From 90bcf0a18a68c7e1a294fe063808e3eba13b4058 Mon Sep 17 00:00:00 2001 From: hiRainn Date: Sun, 13 Sep 2020 13:35:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=9C=AC=E5=9C=B0=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=94=B9=E4=B8=BA=E4=BB=8E=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=8C=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=BA=E4=BF=9D=E5=AD=98=E6=9C=AC=E5=9C=B0=EF=BC=8C=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E7=8E=AF=E5=A2=83=E4=B8=BA=E5=A4=8D=E5=88=B6=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 4 ++-- src/components/setting/Setting.vue | 23 ++++++++++++++-------- src/components/setting/i18n.js | 9 ++++++--- src/config/default/setting.config.js | 1 - src/store/modules/setting.js | 29 +++++++++++++++++++--------- 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/App.vue b/src/App.vue index 1631899..9b7e870 100644 --- a/src/App.vue +++ b/src/App.vue @@ -22,7 +22,7 @@ export default { this.setLanguage(this.lang) enquireScreen(isMobile => this.setDevice(isMobile)) //设置为读取本地存储配置 - const loadLocalSetting = this.localSaveSetting + const loadLocalSetting = process.env.NODE_ENV === 'production'?true:false if (loadLocalSetting) { this.$store.dispatch('setting/loadLocalSetting') } @@ -54,7 +54,7 @@ export default { } }, computed: { - ...mapState('setting', ['theme', 'weekMode', 'lang', 'localSaveSetting']) + ...mapState('setting', ['theme', 'weekMode', 'lang']) }, methods: { ...mapMutations('setting', ['setDevice']), diff --git a/src/components/setting/Setting.vue b/src/components/setting/Setting.vue index 1615038..122b2d1 100644 --- a/src/components/setting/Setting.vue +++ b/src/components/setting/Setting.vue @@ -104,7 +104,8 @@ :message="$t('alert')" > - {{localSaveSetting?$t('save'):$t('copy')}} + {{localSaveSetting?$t('save'):$t('copy')}} + {{$t('init')}} @@ -125,14 +126,15 @@ export default { components: {ImgCheckboxGroup, ImgCheckbox, ColorCheckboxGroup, ColorCheckbox, SettingItem}, data() { return { - copyConfig: 'Sorry, you have copied nothing O(∩_∩)O~' + copyConfig: 'Sorry, you have copied nothing O(∩_∩)O~', + localSaveSetting: process.env.NODE_ENV === 'production'?true:false } }, computed: { directions() { return this.animates.find(item => item.name == this.animate.name).directions }, - ...mapState('setting', ['theme', 'layout', 'animate', 'animates', 'palettes', 'multiPage', 'weekMode', 'fixedHeader', 'fixedSideBar', 'hideSetting', 'pageWidth', 'localSaveSetting']) + ...mapState('setting', ['theme', 'layout', 'animate', 'animates', 'palettes', 'multiPage', 'weekMode', 'fixedHeader', 'fixedSideBar', 'hideSetting', 'pageWidth']) }, watch: { 'animate.name': function(val) { @@ -157,11 +159,10 @@ export default { this.copyConfig = '// 自定义配置,参考 ./default/setting.config.js,需要自定义的属性在这里配置即可\n' this.copyConfig += 'module.exports = ' this.copyConfig += formatConfig(config) - - //如果设置保存在本地,则存到浏览器localStroge中 - if(this.localSaveSetting) { - localStorage.setItem('localSetting',JSON.stringify(config)) - } + //如果设置保存在本地,则存到浏览器localStroge中 + if(this.localSaveSetting) { + localStorage.setItem('localSetting',JSON.stringify(config)) + } let clipboard = new Clipboard('#copyBtn') clipboard.on('success', () => { @@ -173,6 +174,12 @@ export default { clipboard.destroy() }) }, + //初始化配置 + initSetting() { + this.$message.loading(`正在初始化配置...`) + localStorage.removeItem('localSetting') + this.$store.dispatch('setting/initSetting') + }, ...mapMutations('setting', ['setTheme', 'setLayout', 'setMultiPage', 'setWeekMode', 'setFixedSideBar', 'setFixedHeader', 'setAnimate', 'setHideSetting', 'setPageWidth']) } diff --git a/src/components/setting/i18n.js b/src/components/setting/i18n.js index c591d26..ec12c75 100644 --- a/src/components/setting/i18n.js +++ b/src/components/setting/i18n.js @@ -35,7 +35,8 @@ module.exports = { }, alert: '拷贝配置后,直接覆盖文件 src/config/config.js 中的全部内容,然后重启即可。(注意:仅会拷贝与默认配置不同的项)', copy: '拷贝配置', - save: '保存配置' + save: '保存配置', + init: '初始配置', }, HK: { theme: { @@ -71,7 +72,8 @@ module.exports = { }, alert: '拷貝配置后,直接覆蓋文件 src/config/config.js 中的全部內容,然後重啟即可。(注意:僅會拷貝與默認配置不同的項)', copy: '拷貝配置', - save: '保存配置' + save: '保存配置', + init: '初始配置', }, US: { theme: { @@ -108,7 +110,8 @@ module.exports = { }, alert: 'After copying the configuration code, directly cover all contents in the file src/config/config.js, then restart the server. (Note: only items that are different from the default configuration will be copied)', copy: 'Copy Setting', - save: 'Save Setting' + save: 'Save Setting', + init: 'Init Setting', } } } diff --git a/src/config/default/setting.config.js b/src/config/default/setting.config.js index 8b44d66..b2ef5a7 100644 --- a/src/config/default/setting.config.js +++ b/src/config/default/setting.config.js @@ -20,7 +20,6 @@ module.exports = { asyncRoutes: false, //异步加载路由,true:开启,false:不开启 showPageTitle: true, //是否显示页面标题(PageLayout 布局中的页面标题),true:显示,false:不显示 filterMenu: true, //根据权限过滤菜单,true:过滤,false:不过滤 - localSaveSetting:true, //是否将右侧设置保存在本地,设置为true的时候,将不显示拷贝设置而将设置保存在localStorage animate: { //动画设置 disabled: false, //禁用动画,true:禁用,false:启用 name: 'bounce', //动画效果,支持的动画效果可参考 ./animate.config.js diff --git a/src/store/modules/setting.js b/src/store/modules/setting.js index 7e4e7b2..19b6ba5 100644 --- a/src/store/modules/setting.js +++ b/src/store/modules/setting.js @@ -91,17 +91,17 @@ export default { }, actions: { loadLocalSetting({commit}) { - const localSetting = localStorage.getItem("localSetting") - if (localSetting !== '' && localSetting != null) { + const localSetting = localStorage.getItem("localSetting") + if (localSetting !== '' && localSetting != null) { let setting = {} try { - setting = JSON.parse(localSetting) + setting = JSON.parse(localSetting) } catch ( e ) { - console.log('json error') - return false + console.log('json error') + return false } for (let key in setting) { - switch (key) { + switch (key) { case 'theme' : commit('setTheme', setting.theme); break; case 'layout': commit('setLayout', setting.layout); break; case 'multiPage': commit('setMultiPage', setting.multiPage); break; @@ -110,10 +110,21 @@ export default { case 'fixedSideBar': commit('setFixedSideBar', setting.fixedSideBar); break; case 'pageWidth': commit('setPageWidth', setting.pageWidth); break; // case 'hideSetting': commit('setHideSetting', setting.hideSetting); break; - case 'animate' : commit('setAnimate', setting.animate) - } + case 'animate' : commit('setAnimate', setting.animate); break; + } } - } + } + }, + //初始化配置 + initSetting({commit}) { + commit('setTheme', config.theme); + commit('setLayout', config.layout); + commit('setMultiPage', config.multiPage); + commit('setWeekMode', config.weekMode); + commit('setFixedHeader', config.fixedHeader); + commit('setFixedSideBar', config.fixedSideBar); + commit('setPageWidth', config.pageWidth); + commit('setAnimate', config.animate) } } }