@ -1,5 +1,9 @@
< template >
< div class = "side-setting" >
< setting -item >
< a -button @click ="saveSetting" type = "primary" icon = "save" > { { $t ( 'save' ) } } < / a - b u t t o n >
< a -button @click ="resetSetting" type = "dashed" icon = "redo" style = "float: right" > { { $t ( 'reset' ) } } < / a - b u t t o n >
< / s e t t i n g - i t e m >
< setting -item :title ="$t('theme.title')" >
< img -checkbox -group
@ change = "values => setTheme({...theme, mode: values[0]})"
@ -102,12 +106,13 @@
< / a - l i s t >
< / s e t t i n g - i t e m >
< a -alert
v - if = "isDev"
style = "max-width: 240px; margin: -16px 0 8px; word-break: break-all"
type = "warning"
: message = "$t('alert')"
>
< / a - a l e r t >
< a -button id = "copyBtn" :data-clipboard-text ="copyConfig" @click ="copyCode" style = "width: 100%" icon = "copy" > { { $t ( 'copy' ) } } < / a - b u t t o n >
< a -button v -if = " isDev " id = "copyBtn" :data-clipboard-text ="copyConfig" @click ="copyCode" style = "width: 100%" icon = "copy" > { { $t ( 'copy' ) } } < / a - b u t t o n >
< / div >
< / template >
@ -128,7 +133,8 @@ 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~' ,
isDev : process . env . NODE _ENV === 'development'
}
} ,
computed : {
@ -147,26 +153,48 @@ export default {
return this . $el . parentNode
} ,
copyCode ( ) {
let config = this . extractConfig ( )
this . copyConfig = ` // 自定义配置,参考 ./default/setting.config.js,需要自定义的属性在这里配置即可
module . exports = $ { formatConfig ( config ) }
`
let clipboard = new Clipboard ( '#copyBtn' )
clipboard . on ( 'success' , ( ) => {
this . $message . success ( ` 复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效 ` ) . then ( ( ) => {
const localConfig = localStorage . getItem ( process . env . VUE _APP _SETTING _KEY )
if ( localConfig ) {
console . warn ( '检测到本地有历史保存的主题配置,想要要拷贝的配置代码生效,您可能需要先重置配置' )
this . $message . warn ( '检测到本地有历史保存的主题配置,想要要拷贝的配置代码生效,您可能需要先重置配置' , 5 )
}
} )
clipboard . destroy ( )
} )
} ,
saveSetting ( ) {
const closeMessage = this . $message . loading ( '正在保存到本地,请稍后...' , 0 )
const config = this . extractConfig ( )
localStorage . setItem ( process . env . VUE _APP _SETTING _KEY , JSON . stringify ( config ) )
setTimeout ( closeMessage , 800 )
} ,
resetSetting ( ) {
this . $confirm ( {
title : '重置主题会刷新页面,当前页面内容不会保留,确认重置?' ,
onOk ( ) {
localStorage . removeItem ( process . env . VUE _APP _SETTING _KEY )
window . location . reload ( )
}
} )
} ,
/ / 提 取 配 置
extractConfig ( ) {
let config = { }
/ / 提 取 配 置
let mySetting = this . $store . state . setting
Object . keys ( mySetting ) . forEach ( key => {
const dftValue = setting [ key ] , myValue = mySetting [ key ]
/ / 只 提 取 与 默 认 配 置 不 同 的 配 置 项
if ( dftValue != undefined && ! fastEqual ( dftValue , myValue ) ) {
config [ key ] = myValue
}
} )
this . copyConfig = '// 自定义配置,参考 ./default/setting.config.js,需要自定义的属性在这里配置即可\n'
this . copyConfig += 'module.exports = '
this . copyConfig += formatConfig ( config )
let clipboard = new Clipboard ( '#copyBtn' )
const _this = this
clipboard . on ( 'success' , function ( ) {
_this . $message . success ( ` 复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效 ` )
clipboard . destroy ( )
} )
return config
} ,
... mapMutations ( 'setting' , [ 'setTheme' , 'setLayout' , 'setMultiPage' , 'setWeekMode' ,
'setFixedSideBar' , 'setFixedHeader' , 'setAnimate' , 'setHideSetting' , 'setPageWidth' ] )