添加一个配置项,当设置为true时从本地读取配置

This commit is contained in:
hiRainn 2020-09-12 13:26:57 +08:00
parent 5a65032772
commit a1f2c1d880
6 changed files with 56 additions and 10 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
src/

View File

@ -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']),

View File

@ -98,13 +98,13 @@
</a-list-item>
</a-list>
</setting-item>
<a-alert
<a-alert v-if="!localSaveSetting"
style="max-width: 240px; margin: -16px 0 8px; word-break: break-all"
type="warning"
:message="$t('alert')"
>
</a-alert>
<a-button id="copyBtn" :data-clipboard-text="copyConfig" @click="copyCode" style="width: 100%" icon="copy" >{{$t('copy')}}</a-button>
<a-button id="copyBtn" :data-clipboard-text="copyConfig" @click="copyCode" style="width: 100%" icon="copy" >{{localSaveSetting?$t('save'):$t('copy')}}</a-button>
</div>
</template>
@ -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()
})
},

View File

@ -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'
}
}
}

View File

@ -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

View File

@ -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)
}
}
}
}
}
}