Skip to content

Commit e439bff

Browse files
committed
feat: 调整个人配置功能,每次改变自动保存,右上角保存修改为重置。
1 parent 4e735be commit e439bff

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

Diff for: web/src/pinia/modules/app.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ export const useAppStore = defineStore('app', () => {
9999
config.transition_type = e
100100
}
101101

102+
const baseCoinfg = {
103+
darkMode: 'auto',
104+
primaryColor: '#3b82f6',
105+
show_watermark: false,
106+
grey: false,
107+
weakness: false,
108+
side_mode: 'normal',
109+
showTabs: true,
110+
transition_type: 'fade',
111+
layout_side_width: 200,
112+
layout_side_collapsed_width: 60,
113+
layout_side_item_height: 40
114+
}
115+
116+
const resetConfig = () => {
117+
for (let baseCoinfgKey in baseCoinfg) {
118+
config[baseCoinfgKey] = baseCoinfg[baseCoinfgKey]
119+
}
120+
}
121+
102122
// 监听色弱模式和灰色模式
103123
watchEffect(() => {
104124
document.documentElement.classList.toggle('html-weakenss', config.weakness)
@@ -128,6 +148,7 @@ export const useAppStore = defineStore('app', () => {
128148
toggleConfigSideItemHeight,
129149
toggleConfigWatermark,
130150
toggleSideMode,
131-
toggleTransition
151+
toggleTransition,
152+
resetConfig
132153
}
133154
})

Diff for: web/src/view/layout/setting/index.vue

+13-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<template #header>
1010
<div class="flex justify-between items-center">
1111
<span class="text-lg">系统配置</span>
12-
<el-button type="primary" @click="saveConfig">保存配置</el-button>
12+
<el-button type="primary" @click="resetConfig">重置配置</el-button>
1313
</div>
1414
</template>
1515
<div class="flex flex-col">
@@ -144,6 +144,8 @@
144144
import { ElMessage } from 'element-plus'
145145
import { setSelfSetting } from '@/api/user'
146146
import Title from './title.vue'
147+
import { watch } from 'vue';
148+
147149
const appStore = useAppStore()
148150
const { config, device } = storeToRefs(appStore)
149151
defineOptions({
@@ -185,24 +187,24 @@
185187
]
186188
187189
const saveConfig = async () => {
188-
/*const input = document.createElement("textarea");
189-
input.value = JSON.stringify(config.value);
190-
// 添加回车
191-
input.value = input.value.replace(/,/g, ",\n");
192-
document.body.appendChild(input);
193-
input.select();
194-
document.execCommand("copy");
195-
document.body.removeChild(input);
196-
ElMessage.success("复制成功, 请自行保存到本地文件中");*/
197190
const res = await setSelfSetting(config.value)
191+
console.log(config.value)
198192
if (res.code === 0) {
199193
localStorage.setItem('originSetting', JSON.stringify(config.value))
200194
ElMessage.success('保存成功')
201-
drawer.value = false
202195
}
203196
}
204197
205198
const customColor = ref('')
199+
200+
const resetConfig = () => {
201+
appStore.resetConfig()
202+
}
203+
204+
205+
watch(config, async () => {
206+
await saveConfig();
207+
}, { deep: true });
206208
</script>
207209

208210
<style lang="scss" scoped>

0 commit comments

Comments
 (0)