添加一个配置项,当设置为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.setHtmlTitle()
this.setLanguage(this.lang) this.setLanguage(this.lang)
enquireScreen(isMobile => this.setDevice(isMobile)) enquireScreen(isMobile => this.setDevice(isMobile))
//
const loadLocalSetting = this.localSaveSetting
if (loadLocalSetting) {
this.$store.dispatch('setting/loadLocalSetting')
}
}, },
mounted() { mounted() {
this.setWeekModeTheme(this.weekMode) this.setWeekModeTheme(this.weekMode)
@ -49,7 +54,7 @@ export default {
} }
}, },
computed: { computed: {
...mapState('setting', ['theme', 'weekMode', 'lang']) ...mapState('setting', ['theme', 'weekMode', 'lang', 'localSaveSetting'])
}, },
methods: { methods: {
...mapMutations('setting', ['setDevice']), ...mapMutations('setting', ['setDevice']),

View File

@ -98,13 +98,13 @@
</a-list-item> </a-list-item>
</a-list> </a-list>
</setting-item> </setting-item>
<a-alert <a-alert v-if="!localSaveSetting"
style="max-width: 240px; margin: -16px 0 8px; word-break: break-all" style="max-width: 240px; margin: -16px 0 8px; word-break: break-all"
type="warning" type="warning"
:message="$t('alert')" :message="$t('alert')"
> >
</a-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> </div>
</template> </template>
@ -132,7 +132,7 @@ export default {
directions() { directions() {
return this.animates.find(item => item.name == this.animate.name).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: { watch: {
'animate.name': function(val) { 'animate.name': function(val) {
@ -158,10 +158,18 @@ export default {
this.copyConfig += 'module.exports = ' this.copyConfig += 'module.exports = '
this.copyConfig += formatConfig(config) this.copyConfig += formatConfig(config)
//localStroge
if(this.localSaveSetting) {
localStorage.setItem('localSetting',JSON.stringify(config))
}
let clipboard = new Clipboard('#copyBtn') let clipboard = new Clipboard('#copyBtn')
const _this = this clipboard.on('success', () => {
clipboard.on('success', function () { if(this.localSaveSetting) {
_this.$message.success(`复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效`) this.$message.success(`保存配置成功`)
} else {
this.$message.success(`复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效`)
}
clipboard.destroy() clipboard.destroy()
}) })
}, },

View File

@ -34,7 +34,8 @@ module.exports = {
direction: '动画方向' direction: '动画方向'
}, },
alert: '拷贝配置后,直接覆盖文件 src/config/config.js 中的全部内容,然后重启即可。(注意:仅会拷贝与默认配置不同的项)', alert: '拷贝配置后,直接覆盖文件 src/config/config.js 中的全部内容,然后重启即可。(注意:仅会拷贝与默认配置不同的项)',
copy: '拷贝配置' copy: '拷贝配置',
save: '保存配置'
}, },
HK: { HK: {
theme: { theme: {
@ -69,7 +70,8 @@ module.exports = {
direction: '動畫方向' direction: '動畫方向'
}, },
alert: '拷貝配置后,直接覆蓋文件 src/config/config.js 中的全部內容,然後重啟即可。(注意:僅會拷貝與默認配置不同的項)', alert: '拷貝配置后,直接覆蓋文件 src/config/config.js 中的全部內容,然後重啟即可。(注意:僅會拷貝與默認配置不同的項)',
copy: '拷貝配置' copy: '拷貝配置',
save: '保存配置'
}, },
US: { US: {
theme: { theme: {
@ -105,7 +107,8 @@ module.exports = {
direction: 'Direction' 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)', 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:不开启 asyncRoutes: false, //异步加载路由true:开启false:不开启
showPageTitle: true, //是否显示页面标题PageLayout 布局中的页面标题true:显示false:不显示 showPageTitle: true, //是否显示页面标题PageLayout 布局中的页面标题true:显示false:不显示
filterMenu: true, //根据权限过滤菜单true:过滤false:不过滤 filterMenu: true, //根据权限过滤菜单true:过滤false:不过滤
localSaveSetting:true, //是否将右侧设置保存在本地,设置为true的时候,将不显示拷贝设置而将设置保存在localStorage
animate: { //动画设置 animate: { //动画设置
disabled: false, //禁用动画true:禁用false:启用 disabled: false, //禁用动画true:禁用false:启用
name: 'bounce', //动画效果,支持的动画效果可参考 ./animate.config.js name: 'bounce', //动画效果,支持的动画效果可参考 ./animate.config.js

View File

@ -88,5 +88,33 @@ export default {
setActivatedFirst(state, activatedFirst) { setActivatedFirst(state, activatedFirst) {
state.activatedFirst = 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)
} }
} }
}
}
}
}