v3.5.0 布局设置支持保存&重置配置

This commit is contained in:
YunaiV 2022-02-15 20:39:21 +08:00
parent a7feb9279f
commit cff4391f2d
4 changed files with 64 additions and 17 deletions

View File

@ -30,6 +30,9 @@
<script> <script>
import { constantRoutes } from "@/router"; import { constantRoutes } from "@/router";
//
const noactiveList = ["/user/profile", "/dict/type", "/gen/edit", "/job/log"];
export default { export default {
data() { data() {
return { return {
@ -42,10 +45,13 @@ export default {
computed: { computed: {
// //
topMenus() { topMenus() {
return this.routers.map((menu) => ({ let topMenus = [];
...menu, this.routers.map((menu) => {
children: undefined, if (menu.hidden === false) {
})); topMenus.push(menu);
}
});
return topMenus;
}, },
// //
routers() { routers() {
@ -69,6 +75,12 @@ export default {
activeMenu() { activeMenu() {
const path = this.$route.path; const path = this.$route.path;
let activePath = this.routers[0].path; let activePath = this.routers[0].path;
var noactive = noactiveList.some(function (item) {
return path.indexOf(item) !== -1;
});
if (noactive) {
return;
}
if (path.lastIndexOf("/") > 0) { if (path.lastIndexOf("/") > 0) {
const tmpPath = path.substring(1, path.length); const tmpPath = path.substring(1, path.length);
activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
@ -89,7 +101,7 @@ export default {
methods: { methods: {
// //
setVisibleNumber() { setVisibleNumber() {
const width = document.body.getBoundingClientRect().width - 200; const width = document.body.getBoundingClientRect().width - 380;
const elWidth = this.$el.getBoundingClientRect().width; const elWidth = this.$el.getBoundingClientRect().width;
const menuItemNodes = this.$el.children; const menuItemNodes = this.$el.children;
const menuWidth = Array.from(menuItemNodes).map( const menuWidth = Array.from(menuItemNodes).map(
@ -119,7 +131,7 @@ export default {
}); });
} }
this.$store.commit("SET_SIDEBAR_ROUTERS", routes); this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
}, }
}, },
}; };
</script> </script>

View File

@ -62,6 +62,10 @@
<el-switch v-model="sidebarLogo" class="drawer-switch" /> <el-switch v-model="sidebarLogo" class="drawer-switch" />
</div> </div>
<el-divider/>
<el-button size="small" type="primary" plain icon="el-icon-document-add" @click="saveSetting">保存配置</el-button>
<el-button size="small" plain icon="el-icon-refresh" @click="resetSetting">重置配置</el-button>
</div> </div>
</div> </div>
</template> </template>
@ -72,15 +76,14 @@ import ThemePicker from '@/components/ThemePicker'
export default { export default {
components: { ThemePicker }, components: { ThemePicker },
data() { data() {
return {} return {
sideTheme: this.$store.state.settings.sideTheme
};
}, },
computed: { computed: {
theme() { theme() {
return this.$store.state.settings.theme return this.$store.state.settings.theme
}, },
sideTheme() {
return this.$store.state.settings.sideTheme
},
fixedHeader: { fixedHeader: {
get() { get() {
return this.$store.state.settings.fixedHeader return this.$store.state.settings.fixedHeader
@ -141,6 +144,38 @@ export default {
key: 'sideTheme', key: 'sideTheme',
value: val value: val
}) })
this.sideTheme = val;
},
saveSetting() {
const loading = this.$loading({
lock: true,
fullscreen: false,
text: "正在保存到本地,请稍后...",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)"
});
localStorage.setItem(
"layout-setting",
`{
"topNav":${this.topNav},
"tagsView":${this.tagsView},
"fixedHeader":${this.fixedHeader},
"sidebarLogo":${this.sidebarLogo},
"sideTheme":"${this.sideTheme}"
}`
);
setTimeout(loading.close(), 1000)
},
resetSetting() {
this.$loading({
lock: true,
fullscreen: false,
text: "正在清除设置缓存并刷新,请稍后...",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)"
});
localStorage.removeItem("layout-setting")
setTimeout("window.location.reload()", 1000)
} }
} }
} }

View File

@ -14,7 +14,7 @@ module.exports = {
/** /**
* 是否显示顶部导航 * 是否显示顶部导航
*/ */
topNav: true, topNav: false,
/** /**
* 是否显示 tagsView * 是否显示 tagsView

View File

@ -3,16 +3,16 @@ import defaultSettings from '@/settings'
const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo } = defaultSettings const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo } = defaultSettings
const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''
const state = { const state = {
theme: variables.theme, theme: variables.theme,
sideTheme: sideTheme, sideTheme: storageSetting.sideTheme || sideTheme,
showSettings: showSettings, showSettings: showSettings,
topNav: topNav, topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
tagsView: tagsView, tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView,
fixedHeader: fixedHeader, fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
sidebarLogo: sidebarLogo sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo
} }
const mutations = { const mutations = {
CHANGE_SETTING: (state, { key, value }) => { CHANGE_SETTING: (state, { key, value }) => {
if (state.hasOwnProperty(key)) { if (state.hasOwnProperty(key)) {