From a1f2c1d880c5f5ddb323653511efe750dcc983b8 Mon Sep 17 00:00:00 2001 From: hiRainn Date: Sat, 12 Sep 2020 13:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=EF=BC=8C=E5=BD=93=E8=AE=BE=E7=BD=AE=E4=B8=BA?= =?UTF-8?q?true=E6=97=B6=E4=BB=8E=E6=9C=AC=E5=9C=B0=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 1 + src/App.vue | 7 ++++++- src/components/setting/Setting.vue | 20 ++++++++++++++------ src/components/setting/i18n.js | 9 ++++++--- src/config/default/setting.config.js | 1 + src/store/modules/setting.js | 28 ++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..aa8e45f --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +src/ \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 737f3e8..1631899 100644 --- a/src/App.vue +++ b/src/App.vue @@ -21,6 +21,11 @@ export default { this.setHtmlTitle() this.setLanguage(this.lang) enquireScreen(isMobile => this.setDevice(isMobile)) + //设置为读取本地存储配置 + const loadLocalSetting = this.localSaveSetting + if (loadLocalSetting) { + this.$store.dispatch('setting/loadLocalSetting') + } }, mounted() { this.setWeekModeTheme(this.weekMode) @@ -49,7 +54,7 @@ export default { } }, computed: { - ...mapState('setting', ['theme', 'weekMode', 'lang']) + ...mapState('setting', ['theme', 'weekMode', 'lang', 'localSaveSetting']) }, methods: { ...mapMutations('setting', ['setDevice']), diff --git a/src/components/setting/Setting.vue b/src/components/setting/Setting.vue index 76cb4d1..1615038 100644 --- a/src/components/setting/Setting.vue +++ b/src/components/setting/Setting.vue @@ -98,13 +98,13 @@ - - {{$t('copy')}} + {{localSaveSetting?$t('save'):$t('copy')}} @@ -132,7 +132,7 @@ export default { 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']) + ...mapState('setting', ['theme', 'layout', 'animate', 'animates', 'palettes', 'multiPage', 'weekMode', 'fixedHeader', 'fixedSideBar', 'hideSetting', 'pageWidth', 'localSaveSetting']) }, watch: { 'animate.name': function(val) { @@ -157,11 +157,19 @@ 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)) + } let clipboard = new Clipboard('#copyBtn') - const _this = this - clipboard.on('success', function () { - _this.$message.success(`复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效`) + clipboard.on('success', () => { + if(this.localSaveSetting) { + this.$message.success(`保存配置成功`) + } else { + this.$message.success(`复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效`) + } clipboard.destroy() }) }, diff --git a/src/components/setting/i18n.js b/src/components/setting/i18n.js index 85fb98d..c591d26 100644 --- a/src/components/setting/i18n.js +++ b/src/components/setting/i18n.js @@ -34,7 +34,8 @@ module.exports = { direction: '动画方向' }, alert: '拷贝配置后,直接覆盖文件 src/config/config.js 中的全部内容,然后重启即可。(注意:仅会拷贝与默认配置不同的项)', - copy: '拷贝配置' + copy: '拷贝配置', + save: '保存配置' }, HK: { theme: { @@ -69,7 +70,8 @@ module.exports = { direction: '動畫方向' }, alert: '拷貝配置后,直接覆蓋文件 src/config/config.js 中的全部內容,然後重啟即可。(注意:僅會拷貝與默認配置不同的項)', - copy: '拷貝配置' + copy: '拷貝配置', + save: '保存配置' }, US: { theme: { @@ -105,7 +107,8 @@ module.exports = { direction: 'Direction' }, 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' + copy: 'Copy Setting', + save: 'Save Setting' } } } diff --git a/src/config/default/setting.config.js b/src/config/default/setting.config.js index b2ef5a7..8b44d66 100644 --- a/src/config/default/setting.config.js +++ b/src/config/default/setting.config.js @@ -20,6 +20,7 @@ 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 3e15a67..7e4e7b2 100644 --- a/src/store/modules/setting.js +++ b/src/store/modules/setting.js @@ -88,5 +88,33 @@ export default { setActivatedFirst(state, activatedFirst) { state.activatedFirst = activatedFirst } + }, + actions: { + loadLocalSetting({commit}) { + const localSetting = localStorage.getItem("localSetting") + if (localSetting !== '' && localSetting != null) { + let setting = {} + try { + setting = JSON.parse(localSetting) + } catch ( e ) { + console.log('json error') + return false + } + for (let key in setting) { + switch (key) { + case 'theme' : commit('setTheme', setting.theme); break; + case 'layout': commit('setLayout', setting.layout); break; + case 'multiPage': commit('setMultiPage', setting.multiPage); break; + case 'weekMode': commit('setWeekMode', setting.weekMode); break; + case 'fixedHeader': commit('setFixedHeader', setting.fixedHeader); break; + 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) + } + } + } + } } } +