new feature: recover all settings, optimize code logic

This commit is contained in:
KUN1007 2023-05-30 22:25:42 +08:00
parent 611ebbfdd5
commit 48f1cd73af
5 changed files with 29 additions and 42 deletions

View file

@ -1,17 +1,10 @@
<script setup lang="ts">
// Vue
import {
defineAsyncComponent,
onBeforeMount,
onBeforeUnmount,
onUpdated,
} from 'vue'
import { defineAsyncComponent, onBeforeMount, onBeforeUnmount } from 'vue'
//
import { Icon } from '@iconify/vue'
// css
import 'animate.css'
//
import router from '@/router'
// store
import { useKUNGalgameSettingsStore } from '@/store/modules/settings'
@ -68,16 +61,6 @@ if (isTopicPage) {
let navItemNum = topBarItem.length
const navItemNumString = navItemNum + '00px'
//
const handleClickAvatar = () => {
// isShowInfo.value = !isShowInfo.value
router.push('/kungalgamer')
}
//
const handleSittingsClick = () => {
showKUNGalgamePanel.value = !showKUNGalgamePanel.value
}
//
onBeforeUnmount(() => {
showKUNGalgamePanel.value = false
@ -111,12 +94,13 @@ onBeforeMount(() => {
</div>
</div>
<div class="kungalgamer-info">
<span @click="handleSittingsClick"><Icon icon="uiw:setting-o" /></span>
<img
src="../assets/images/KUN.jpg"
alt="KUN"
@click="handleClickAvatar"
/>
<!-- showKUNGalgamePanel store 里的布尔值,其真假控制设置面板的显示与关闭 -->
<span @click="showKUNGalgamePanel = !showKUNGalgamePanel"
><Icon icon="uiw:setting-o"
/></span>
<router-link to="/kungalgamer">
<img src="../assets/images/KUN.jpg" alt="KUN" />
</router-link>
</div>
</div>
<div class="settings-panel" :style="topicStyle">

View file

@ -29,15 +29,8 @@ const handleChangeLanguage = () => {
}
/* 恢复所有设置为默认 */
const handleRecover = () => {}
/*
* 设置面板显示切换
*/
//
const handleClose = () => {
showKUNGalgamePanel.value = false
const handleRecover = () => {
settingsStore.restoreSettings()
}
</script>
@ -111,7 +104,8 @@ const handleClose = () => {
<!-- 关闭面板 -->
<div class="close">
<Icon @click="handleClose" icon="line-md:close" />
<!-- showKUNGalgamePanel 存在于 settings ,false 为关闭设置面板 -->
<Icon @click="showKUNGalgamePanel = false" icon="line-md:close" />
</div>
</div>
</template>

View file

@ -11,7 +11,7 @@ import { restoreBackground } from '@/hooks/useBackgroundPicture'
// 使 store
const settingsStore = useKUNGalgameSettingsStore()
const { showKUNGalgameBackground, showCustomBackground } =
const { showKUNGalgameBackground, showKUNGalgameCustomBackground } =
storeToRefs(settingsStore)
//
@ -36,7 +36,7 @@ const handelChangeImage = (index: number) => {
const url = ref('')
const handleCustomBackground = () => {
if (url.value) {
showCustomBackground.value = url.value
showKUNGalgameCustomBackground.value = url.value
showKUNGalgameBackground.value = '1007'
url.value = ''
} else {

View file

@ -5,7 +5,7 @@ import { computed } from 'vue'
// 使用设置面板的 store
const settingsStore = useKUNGalgameSettingsStore()
const { showKUNGalgameBackground, showCustomBackground } =
const { showKUNGalgameBackground, showKUNGalgameCustomBackground } =
storeToRefs(settingsStore)
// 恢复空白背景
@ -20,11 +20,9 @@ export const currBackground = computed(() => {
) {
return 'none'
} else if (showKUNGalgameBackground.value === '1007') {
return `url(${showCustomBackground.value})`
return `url(${showKUNGalgameCustomBackground.value})`
} else {
// TODO: 替换为后端接口
return `url(src/assets/images/bg/bg${showKUNGalgameBackground.value}.png)`
}
})
console.log(currBackground.value)

View file

@ -12,17 +12,28 @@ interface KUNGalgameSettings {
// 背景图
showKUNGalgameBackground: string
// 自定义背景图
showCustomBackground: string
showKUNGalgameCustomBackground: string
}
export const useKUNGalgameSettingsStore = defineStore({
id: 'KUNGalgame-settings',
persist: true,
// 默认值
state: (): KUNGalgameSettings => ({
showKUNGalgamePanel: false,
showKUNGalgameLanguage: 'en',
showKUNGalgameMainPageWidth: '61.8',
showKUNGalgameBackground: 'none',
showCustomBackground: '',
showKUNGalgameCustomBackground: '',
}),
actions: {
// 恢复出厂设置()
restoreSettings() {
this.showKUNGalgamePanel = false
this.showKUNGalgameLanguage = 'en'
this.showKUNGalgameMainPageWidth = '61.8'
this.showKUNGalgameBackground = 'none'
this.showKUNGalgameCustomBackground = ''
},
},
})