jinlin
2023-12-11 fe2f3011f3f5d3ea760b6520e9e95a2c419e4b78
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<template>
  <div class="aui-theme-tools" :class="{ 'aui-theme-tools--open': isOpen }">
    <!-- <div class="aui-theme-tools__toggle" @click="isOpen = !isOpen">
      <svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-setting"></use></svg>
    </div> -->
    <div class="aui-theme-tools__content">
      <div class="aui-theme-tools__item">
        <h3>主题</h3>
        <div style="margin: 20px 0">
          <el-radio-group v-model="$store.state.theme" size="mini" @change="themehangeHandle">
            <el-radio-button label="light">浅色</el-radio-button>
            <el-radio-button label="high">深色</el-radio-button>
          </el-radio-group>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
  import Cookies from 'js-cookie'
 
  export default {
    data() {
      return {
        isOpen: false,
        themeColor: ''
      }
    },
    created() {
      let that = this
      this.$EventBus.$on('changeTheme', function () {
        that.isOpen = true
      })
    },
    watch: {
      themeColor(val) {
        this.$router.go(0)
      }
    },
    methods: {
      themehangeHandle(val) {
        this.themeColor = val
        Cookies.set('systemTheme', val)
        let body = document.querySelector('body')
        let clazz = body.className
        clazz = clazz.replace(' light', '').replace(' high', '')
        body.className = clazz + ' ' + val
        this.isOpen = false
      }
    }
  }
</script>