5 changed files with 155 additions and 30 deletions
-
10activitylink/src/api/manage/win.js
-
48activitylink/src/stone/winStone.js
-
15activitylink/src/views/zhongchou/activity/detail/index.vue
-
3activitylink/src/views/zhongchou/activity/index.vue
-
109activitylink/src/views/zhongchou/winning/index.vue
@ -0,0 +1,48 @@ |
|||||
|
import { defineStore } from "pinia"; |
||||
|
import { ref } from 'vue'; |
||||
|
import localforage from 'localforage'; |
||||
|
|
||||
|
// 创建本地存储实例
|
||||
|
const winStorage = localforage.createInstance({ |
||||
|
name: 'winStore', |
||||
|
storeName: 'winData' |
||||
|
}); |
||||
|
|
||||
|
export const useWinStone = defineStore('winStone', () => { |
||||
|
// 持久化参数:searchgradeId
|
||||
|
const searchgradeId = ref(localStorage.getItem('searchgradeId') || ''); |
||||
|
|
||||
|
// 设置 searchgradeId 并持久化
|
||||
|
const setSearchgradeId = (value) => { |
||||
|
searchgradeId.value = value; |
||||
|
localStorage.setItem('searchgradeId', value); |
||||
|
winStorage.setItem('searchgradeId', value).catch((err) => { |
||||
|
console.error('保存 searchgradeId 到 localforage 失败:', err); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
// 初始化恢复数据
|
||||
|
const initialize = async () => { |
||||
|
try { |
||||
|
const storedgradeId = await winStorage.getItem('searchgradeId'); |
||||
|
if (storedgradeId !== null) { |
||||
|
searchgradeId.value = storedgradeId; |
||||
|
} |
||||
|
} catch (error) { |
||||
|
console.warn('从 localforage 恢复失败,尝试从 localStorage 恢复'); |
||||
|
const localStoragegradeId = localStorage.getItem('searchgradeId'); |
||||
|
if (localStoragegradeId !== null) { |
||||
|
searchgradeId.value = localStoragegradeId; |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// 初始化时恢复数据
|
||||
|
initialize(); |
||||
|
|
||||
|
// 暴露出去
|
||||
|
return { |
||||
|
searchgradeId, |
||||
|
setSearchgradeId, |
||||
|
}; |
||||
|
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue