4
0
mirror of https://github.com/iczer/vue-antd-admin.git synced 2025-10-13 20:36:59 +08:00

将本地读取配置改为从环境判断,生产环境为保存本地,开发环境为复制配置变量

This commit is contained in:
hiRainn 2020-09-13 13:35:10 +08:00
parent ab8914021b
commit 90bcf0a18a
5 changed files with 43 additions and 23 deletions

View File

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

View File

@ -104,7 +104,8 @@
:message="$t('alert')"
>
</a-alert>
<a-button id="copyBtn" :data-clipboard-text="copyConfig" @click="copyCode" style="width: 100%" icon="copy" >{{localSaveSetting?$t('save'):$t('copy')}}</a-button>
<a-button id="copyBtn" :data-clipboard-text="copyConfig" @click="copyCode" :style="{width: this.localSaveSetting?'50%':'100%'}" icon="copy" >{{localSaveSetting?$t('save'):$t('copy')}}</a-button>
<a-button @click="initSetting" style="width: 50%" icon="disconnect" v-if="localSaveSetting">{{$t('init')}}</a-button>
</div>
</template>
@ -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,7 +159,6 @@ 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))
@ -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'])
}

View File

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

View File

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

View File

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