chore: optimize the function of copy configuration code ; 🌟

This commit is contained in:
iczer
2020-07-10 11:12:13 +08:00
parent e619e44d4f
commit d78f6d61d7
8 changed files with 30 additions and 16 deletions

View File

@@ -0,0 +1,7 @@
import ColorCheckbox from '@/components/checkbox/ColorCheckbox'
import ImgCheckbox from '@/components/checkbox/ImgCheckbox'
export {
ColorCheckbox,
ImgCheckbox
}

View File

@@ -90,23 +90,23 @@
</a-list>
</setting-item>
<a-alert
style="max-width: 224px; margin: -16px 0 8px"
message="拷贝配置后,直接覆盖文件 src/config/config.js 中的全部内容即可"
style="max-width: 240px; margin: -16px 0 8px; word-break: break-all"
type="warning"
:closable="true"
/>
:message="$t('alert')"
>
</a-alert>
<a-button id="copyBtn" :data-clipboard-text="copyConfig" @click="copyCode" style="width: 100%" icon="copy" >{{$t('copy')}}</a-button>
</div>
</template>
<script>
import SettingItem from './SettingItem'
import ColorCheckbox from '../checkbox/ColorCheckbox'
import ImgCheckbox from '../checkbox/ImgCheckbox'
import {ColorCheckbox, ImgCheckbox} from '@/components/checkbox'
import Clipboard from 'clipboard'
import { mapState, mapMutations } from 'vuex'
import {formatConfig} from '@/utils/formatter'
import {setting} from '@/config/default'
import fastEqual from 'fast-deep-equal'
const ColorCheckboxGroup = ColorCheckbox.Group
const ImgCheckboxGroup = ImgCheckbox.Group
@@ -136,8 +136,11 @@ export default {
// 提取配置
let mySetting = this.$store.state.setting
Object.keys(mySetting).forEach(key => {
if (setting[key]) {
config[key] = mySetting[key]
const dftValue = setting[key], myValue = mySetting[key]
// 只提取与默认配置不同的配置项
if (dftValue != undefined && !fastEqual(dftValue, myValue)) {
console.log(myValue)
config[key] = myValue
}
})
this.copyConfig = '// 自定义配置,参考 ./default/setting.js需要自定义的属性在这里配置即可\n'

View File

@@ -31,6 +31,7 @@ module.exports = {
effect: '动画效果',
direction: '动画方向'
},
alert: '拷贝配置后,直接覆盖文件 src/config/config.js 中的全部内容即可。(注意:仅会拷贝与默认配置不同的项)',
copy: '拷贝配置'
},
HK: {
@@ -64,6 +65,7 @@ module.exports = {
effect: '動畫效果',
direction: '動畫方向'
},
alert: '拷貝配置后,直接覆蓋文件 src/config/config.js 中的全部內容即可。(注意:僅會拷貝與默認配置不同的項)',
copy: '拷貝配置'
},
US: {
@@ -97,6 +99,7 @@ module.exports = {
effect: 'Effect',
direction: 'Direction'
},
alert: 'After copying the configuration code, directly cover all contents in the file src/config/config.js. (Note: only items that are different from the default configuration will be copied)',
copy: 'Copy Setting'
}
}