xyyd-fatfox/src/layout/background/useBackgroundStore.ts

35 lines
923 B
TypeScript
Raw Normal View History

2024-09-09 17:53:07 +08:00
import { defineStore } from 'pinia'
import { reactive, ref, watch } from 'vue'
export default defineStore('background', () => {
const tag = ref(localStorage.getItem('backgroundTag') || '')
const resource = reactive({
type: 'image',
brief: '',
url: ''
})
const getResource = (tag: string) => {
// 默认壁纸
if (!tag) {
return {
type: 'image',
brief:
'https://aihlp.com.cn/admin/wallpaper/508d3994-3727-4839-bfe9-41b97ccf4fba_66a3272c874d41e5b9ec7562fe5822cd (1).jpg?x-oss-process=image/resize,w_400,h_225',
url: 'https://aihlp.com.cn/admin/wallpaper/508d3994-3727-4839-bfe9-41b97ccf4fba_66a3272c874d41e5b9ec7562fe5822cd (1).jpg'
}
}
}
watch(
tag,
(val) => {
localStorage.setItem('backgroundTag', val)
Object.assign(resource, getResource(val))
},
{ immediate: true }
)
return {
tag,
2024-11-15 21:01:19 +08:00
resource
2024-09-09 17:53:07 +08:00
}
})