| 1 | import { defineStore } from 'pinia' |
| 2 | import { ref } from 'vue' |
| 3 | |
| 4 | export const useAppStore = defineStore('app', () => { |
| 5 | // 是否是第一次进入账号管理页面 |
| 6 | const isFirstTimeAccountManagement = ref(true) |
| 7 | |
| 8 | // 是否是第一次进入素材管理页面 |
| 9 | const isFirstTimeMaterialManagement = ref(true) |
| 10 | |
| 11 | // 账号管理页面刷新状态 |
| 12 | const isAccountRefreshing = ref(false) |
| 13 | |
| 14 | // 素材列表数据 |
| 15 | const materials = ref([]) |
| 16 | |
| 17 | // 设置账号管理页面已访问 |
| 18 | const setAccountManagementVisited = () => { |
| 19 | isFirstTimeAccountManagement.value = false |
| 20 | } |
| 21 | |
| 22 | // 设置素材管理页面已访问 |
| 23 | const setMaterialManagementVisited = () => { |
| 24 | isFirstTimeMaterialManagement.value = false |
| 25 | } |
| 26 | |
| 27 | // 重置所有访问状态(用于重新登录或刷新应用时) |
| 28 | const resetVisitStatus = () => { |
| 29 | isFirstTimeAccountManagement.value = true |
| 30 | isFirstTimeMaterialManagement.value = true |
| 31 | } |
| 32 | |
| 33 | // 更新素材列表 |
| 34 | const setMaterials = (materialList) => { |
| 35 | materials.value = materialList |
| 36 | } |
| 37 | |
| 38 | // 添加新素材 |
| 39 | const addMaterial = (material) => { |
| 40 | materials.value.push(material) |
| 41 | } |
| 42 | |
| 43 | // 删除素材 |
| 44 | const removeMaterial = (materialId) => { |
| 45 | const index = materials.value.findIndex(m => m.id === materialId) |
| 46 | if (index > -1) { |
| 47 | materials.value.splice(index, 1) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // 设置账号管理页面刷新状态 |
| 52 | const setAccountRefreshing = (status) => { |
| 53 | isAccountRefreshing.value = status |
| 54 | } |
| 55 | |
| 56 | return { |
| 57 | isFirstTimeAccountManagement, |
| 58 | isFirstTimeMaterialManagement, |
| 59 | isAccountRefreshing, |
| 60 | materials, |
| 61 | setAccountManagementVisited, |
| 62 | setMaterialManagementVisited, |
| 63 | resetVisitStatus, |
| 64 | setMaterials, |
| 65 | addMaterial, |
| 66 | removeMaterial, |
| 67 | setAccountRefreshing |
| 68 | } |
| 69 | }) |