| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import { computed } from 'vue'
- import { defineStore } from '../store'
- import { useLoginStore } from './login'
- import { localData } from '../storage'
- /**
- * 系统设置存储对象
- */
- export const useSettingStore = defineStore(() => {
- const loginStore = useLoginStore()
- const settings = localData.getValue('settings')
- const settingIndex = computed(() => settings.findIndex(((e) => e.loginId === loginStore.userId)))
- const userSetting = computed(() => (settings[settingIndex.value] ?? {
- loginId: 0,
- showOrderDialog: true,
- showOrderSuccessDialog: false,
- showOrderFailDialog: false,
- orderFocusType: 1,
- orderPriceType: 1,
- }))
- // 获取设置项值
- const getSettingValue = (key: keyof Omit<Model.LocalSetting, 'loginId'>) => {
- return userSetting.value[key]
- }
- // 保存设置
- const saveSettings = (value: Omit<Model.LocalSetting, 'loginId'>) => {
- const item = {
- loginId: loginStore.userId,
- ...value
- }
- if (settingIndex.value > -1) {
- settings[settingIndex.value] = item
- } else {
- settings.push(item)
- }
- localData.setValue('settings', settings)
- }
- // 恢复默认设置
- const restoreDefaultSettings = () => {
- if (settingIndex.value > -1) {
- settings.splice(settingIndex.value, 1)
- localData.setValue('settings', settings)
- }
- }
- return {
- userSetting,
- getSettingValue,
- saveSettings,
- restoreDefaultSettings
- }
- })
|