作者 RuoYi

布局设置支持保存&重置配置

@@ -43,7 +43,7 @@ spring: @@ -43,7 +43,7 @@ spring:
43 allow: 43 allow:
44 url-pattern: /druid/* 44 url-pattern: /druid/*
45 # 控制台管理用户名和密码 45 # 控制台管理用户名和密码
46 - login-username: admin 46 + login-username: ruoyi
47 login-password: 123456 47 login-password: 123456
48 filter: 48 filter:
49 stat: 49 stat:
@@ -30,6 +30,9 @@ @@ -30,6 +30,9 @@
30 <script> 30 <script>
31 import { constantRoutes } from "@/router"; 31 import { constantRoutes } from "@/router";
32 32
  33 +// 不需要激活的路由
  34 +const noactiveList = ["/user/profile", "/dict/type", "/gen/edit", "/job/log"];
  35 +
33 export default { 36 export default {
34 data() { 37 data() {
35 return { 38 return {
@@ -42,10 +45,13 @@ export default { @@ -42,10 +45,13 @@ export default {
42 computed: { 45 computed: {
43 // 顶部显示菜单 46 // 顶部显示菜单
44 topMenus() { 47 topMenus() {
45 - return this.routers.map((menu) => ({  
46 - ...menu,  
47 - children: undefined,  
48 - })); 48 + let topMenus = [];
  49 + this.routers.map((menu) => {
  50 + if (menu.hidden === false) {
  51 + topMenus.push(menu);
  52 + }
  53 + });
  54 + return topMenus;
49 }, 55 },
50 // 所有的路由信息 56 // 所有的路由信息
51 routers() { 57 routers() {
@@ -69,6 +75,12 @@ export default { @@ -69,6 +75,12 @@ export default {
69 activeMenu() { 75 activeMenu() {
70 const path = this.$route.path; 76 const path = this.$route.path;
71 let activePath = this.routers[0].path; 77 let activePath = this.routers[0].path;
  78 + var noactive = noactiveList.some(function (item) {
  79 + return path.indexOf(item) !== -1;
  80 + });
  81 + if (noactive) {
  82 + return;
  83 + }
72 if (path.lastIndexOf("/") > 0) { 84 if (path.lastIndexOf("/") > 0) {
73 const tmpPath = path.substring(1, path.length); 85 const tmpPath = path.substring(1, path.length);
74 activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); 86 activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
@@ -89,7 +101,7 @@ export default { @@ -89,7 +101,7 @@ export default {
89 methods: { 101 methods: {
90 // 根据宽度计算设置显示栏数 102 // 根据宽度计算设置显示栏数
91 setVisibleNumber() { 103 setVisibleNumber() {
92 - const width = document.body.getBoundingClientRect().width - 200; 104 + const width = document.body.getBoundingClientRect().width - 380;
93 const elWidth = this.$el.getBoundingClientRect().width; 105 const elWidth = this.$el.getBoundingClientRect().width;
94 const menuItemNodes = this.$el.children; 106 const menuItemNodes = this.$el.children;
95 const menuWidth = Array.from(menuItemNodes).map( 107 const menuWidth = Array.from(menuItemNodes).map(
@@ -119,7 +131,7 @@ export default { @@ -119,7 +131,7 @@ export default {
119 }); 131 });
120 } 132 }
121 this.$store.commit("SET_SIDEBAR_ROUTERS", routes); 133 this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
122 - }, 134 + }
123 }, 135 },
124 }; 136 };
125 </script> 137 </script>
@@ -62,6 +62,10 @@ @@ -62,6 +62,10 @@
62 <el-switch v-model="sidebarLogo" class="drawer-switch" /> 62 <el-switch v-model="sidebarLogo" class="drawer-switch" />
63 </div> 63 </div>
64 64
  65 + <el-divider/>
  66 +
  67 + <el-button size="small" type="primary" plain icon="el-icon-document-add" @click="saveSetting">保存配置</el-button>
  68 + <el-button size="small" plain icon="el-icon-refresh" @click="resetSetting">重置配置</el-button>
65 </div> 69 </div>
66 </div> 70 </div>
67 </template> 71 </template>
@@ -72,15 +76,14 @@ import ThemePicker from '@/components/ThemePicker' @@ -72,15 +76,14 @@ import ThemePicker from '@/components/ThemePicker'
72 export default { 76 export default {
73 components: { ThemePicker }, 77 components: { ThemePicker },
74 data() { 78 data() {
75 - return {} 79 + return {
  80 + sideTheme: this.$store.state.settings.sideTheme
  81 + };
76 }, 82 },
77 computed: { 83 computed: {
78 theme() { 84 theme() {
79 return this.$store.state.settings.theme 85 return this.$store.state.settings.theme
80 }, 86 },
81 - sideTheme() {  
82 - return this.$store.state.settings.sideTheme  
83 - },  
84 fixedHeader: { 87 fixedHeader: {
85 get() { 88 get() {
86 return this.$store.state.settings.fixedHeader 89 return this.$store.state.settings.fixedHeader
@@ -141,6 +144,38 @@ export default { @@ -141,6 +144,38 @@ export default {
141 key: 'sideTheme', 144 key: 'sideTheme',
142 value: val 145 value: val
143 }) 146 })
  147 + this.sideTheme = val;
  148 + },
  149 + saveSetting() {
  150 + const loading = this.$loading({
  151 + lock: true,
  152 + fullscreen: false,
  153 + text: "正在保存到本地,请稍后...",
  154 + spinner: "el-icon-loading",
  155 + background: "rgba(0, 0, 0, 0.7)"
  156 + });
  157 + localStorage.setItem(
  158 + "layout-setting",
  159 + `{
  160 + "topNav":${this.topNav},
  161 + "tagsView":${this.tagsView},
  162 + "fixedHeader":${this.fixedHeader},
  163 + "sidebarLogo":${this.sidebarLogo},
  164 + "sideTheme":"${this.sideTheme}"
  165 + }`
  166 + );
  167 + setTimeout(loading.close(), 1000)
  168 + },
  169 + resetSetting() {
  170 + this.$loading({
  171 + lock: true,
  172 + fullscreen: false,
  173 + text: "正在清除设置缓存并刷新,请稍后...",
  174 + spinner: "el-icon-loading",
  175 + background: "rgba(0, 0, 0, 0.7)"
  176 + });
  177 + localStorage.removeItem("layout-setting")
  178 + setTimeout("window.location.reload()", 1000)
144 } 179 }
145 } 180 }
146 } 181 }
@@ -14,7 +14,7 @@ module.exports = { @@ -14,7 +14,7 @@ module.exports = {
14 /** 14 /**
15 * 是否显示顶部导航 15 * 是否显示顶部导航
16 */ 16 */
17 - topNav: true, 17 + topNav: false,
18 18
19 /** 19 /**
20 * 是否显示 tagsView 20 * 是否显示 tagsView
@@ -3,16 +3,16 @@ import defaultSettings from '@/settings' @@ -3,16 +3,16 @@ import defaultSettings from '@/settings'
3 3
4 const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo } = defaultSettings 4 const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo } = defaultSettings
5 5
  6 +const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''
6 const state = { 7 const state = {
7 theme: variables.theme, 8 theme: variables.theme,
8 - sideTheme: sideTheme, 9 + sideTheme: storageSetting.sideTheme || sideTheme,
9 showSettings: showSettings, 10 showSettings: showSettings,
10 - topNav: topNav,  
11 - tagsView: tagsView,  
12 - fixedHeader: fixedHeader,  
13 - sidebarLogo: sidebarLogo 11 + topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
  12 + tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView,
  13 + fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
  14 + sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo
14 } 15 }
15 -  
16 const mutations = { 16 const mutations = {
17 CHANGE_SETTING: (state, { key, value }) => { 17 CHANGE_SETTING: (state, { key, value }) => {
18 if (state.hasOwnProperty(key)) { 18 if (state.hasOwnProperty(key)) {