Просмотр исходного кода

tagview & sidebar 主题颜色与element ui(全局)同步

RuoYi лет назад: 5
Родитель
Сommit
bb565f87cf

+ 49 - 46
ruoyi-ui/src/layout/components/Sidebar/index.vue

@@ -1,54 +1,57 @@
1 1
 <template>
2
-  <div :class="{'has-logo':showLogo}">
3
-    <logo v-if="showLogo" :collapse="isCollapse" />
4
-    <el-scrollbar wrap-class="scrollbar-wrapper">
5
-      <el-menu
6
-        :default-active="activeMenu"
7
-        :collapse="isCollapse"
8
-        :background-color="variables.menuBg"
9
-        :text-color="variables.menuText"
10
-        :unique-opened="true"
11
-        :active-text-color="variables.menuActiveText"
12
-        :collapse-transition="false"
13
-        mode="vertical"
14
-      >
15
-        <sidebar-item v-for="route in permission_routes" :key="route.path" :item="route" :base-path="route.path" />
16
-      </el-menu>
17
-    </el-scrollbar>
18
-  </div>
2
+    <div :class="{'has-logo':showLogo}">
3
+        <logo v-if="showLogo" :collapse="isCollapse" />
4
+        <el-scrollbar wrap-class="scrollbar-wrapper">
5
+            <el-menu
6
+                :default-active="activeMenu"
7
+                :collapse="isCollapse"
8
+                :background-color="variables.menuBg"
9
+                :text-color="variables.menuText"
10
+                :unique-opened="true"
11
+                :active-text-color="settings.theme"
12
+                :collapse-transition="false"
13
+                mode="vertical"
14
+            >
15
+                <sidebar-item
16
+                    v-for="(route, index) in permission_routes"
17
+                    :key="route.path  + index"
18
+                    :item="route"
19
+                    :base-path="route.path"
20
+                />
21
+            </el-menu>
22
+        </el-scrollbar>
23
+    </div>
19 24
 </template>
20 25
 
21 26
 <script>
22
-import { mapGetters } from 'vuex'
23
-import Logo from './Logo'
24
-import SidebarItem from './SidebarItem'
25
-import variables from '@/assets/styles/variables.scss'
27
+import { mapGetters, mapState } from "vuex";
28
+import Logo from "./Logo";
29
+import SidebarItem from "./SidebarItem";
30
+import variables from "@/assets/styles/variables.scss";
26 31
 
27 32
 export default {
28
-  components: { SidebarItem, Logo },
29
-  computed: {
30
-    ...mapGetters([
31
-      'permission_routes',
32
-      'sidebar'
33
-    ]),
34
-    activeMenu() {
35
-      const route = this.$route
36
-      const { meta, path } = route
37
-      // if set path, the sidebar will highlight the path you set
38
-      if (meta.activeMenu) {
39
-        return meta.activeMenu
40
-      }
41
-      return path
42
-    },
43
-    showLogo() {
44
-      return this.$store.state.settings.sidebarLogo
45
-    },
46
-    variables() {
47
-      return variables
48
-    },
49
-    isCollapse() {
50
-      return !this.sidebar.opened
33
+    components: { SidebarItem, Logo },
34
+    computed: {
35
+        ...mapState(["settings"]),
36
+        ...mapGetters(["permission_routes", "sidebar"]),
37
+        activeMenu() {
38
+            const route = this.$route;
39
+            const { meta, path } = route;
40
+            // if set path, the sidebar will highlight the path you set
41
+            if (meta.activeMenu) {
42
+                return meta.activeMenu;
43
+            }
44
+            return path;
45
+        },
46
+        showLogo() {
47
+            return this.$store.state.settings.sidebarLogo;
48
+        },
49
+        variables() {
50
+            return variables;
51
+        },
52
+        isCollapse() {
53
+            return !this.sidebar.opened;
54
+        }
51 55
     }
52
-  }
53
-}
56
+};
54 57
 </script>

+ 15 - 1
ruoyi-ui/src/layout/components/TagsView/index.vue

@@ -1,6 +1,6 @@
1 1
 <template>
2 2
   <div id="tags-view-container" class="tags-view-container">
3
-    <scroll-pane ref="scrollPane" class="tags-view-wrapper">
3
+    <scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll">
4 4
       <router-link
5 5
         v-for="tag in visitedViews"
6 6
         ref="tag"
@@ -9,6 +9,7 @@
9 9
         :to="{ path: tag.path, query: tag.query, fullPath: tag.fullPath }"
10 10
         tag="span"
11 11
         class="tags-view-item"
12
+        :style="activeStyle(tag)"
12 13
         @click.middle.native="!isAffix(tag)?closeSelectedTag(tag):''"
13 14
         @contextmenu.prevent.native="openMenu(tag,$event)"
14 15
       >
@@ -46,6 +47,9 @@ export default {
46 47
     },
47 48
     routes() {
48 49
       return this.$store.state.permission.routes
50
+    },
51
+    theme() {
52
+      return this.$store.state.settings.theme;
49 53
     }
50 54
   },
51 55
   watch: {
@@ -69,6 +73,13 @@ export default {
69 73
     isActive(route) {
70 74
       return route.path === this.$route.path
71 75
     },
76
+    activeStyle(tag) {
77
+      if (!this.isActive(tag)) return {};
78
+      return {
79
+        "background-color": this.theme,
80
+        "border-color": this.theme
81
+      };
82
+    },
72 83
     isAffix(tag) {
73 84
       return tag.meta && tag.meta.affix
74 85
     },
@@ -189,6 +200,9 @@ export default {
189 200
     },
190 201
     closeMenu() {
191 202
       this.visible = false
203
+    },
204
+    handleScroll() {
205
+      this.closeMenu()
192 206
     }
193 207
   }
194 208
 }