mirror of
https://gitee.com/dromara/go-view.git
synced 2025-08-17 02:49:47 +08:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ConfigType, PackagesStoreType, PackagesType } from './packagesStore.d'
|
|
import { packagesList } from '@/packages/index'
|
|
import { StorageEnum } from '@/enums/storageEnum'
|
|
import { getLocalStorage, setLocalStorage } from '@/utils'
|
|
|
|
// 组件 packages
|
|
export const usePackagesStore = defineStore({
|
|
id: 'usePackagesStore',
|
|
state: (): PackagesStoreType => ({
|
|
packagesList: Object.freeze(packagesList),
|
|
newPhoto: undefined
|
|
}),
|
|
getters: {
|
|
getPackagesList(): PackagesType {
|
|
return this.packagesList
|
|
}
|
|
},
|
|
actions: {
|
|
addPhotos(newPhoto: ConfigType, index: number) {
|
|
this.newPhoto = newPhoto
|
|
this.packagesList.Photos.splice(index, 0, newPhoto)
|
|
},
|
|
deletePhotos(photoInfo: ConfigType, index: number) {
|
|
this.packagesList.Photos.splice(index, 1)
|
|
const StoreKey = StorageEnum.GO_USER_MEDIA_PHOTOS
|
|
const userPhotosList = getLocalStorage(StoreKey)
|
|
userPhotosList.splice(index - 1, 1)
|
|
setLocalStorage(StoreKey, userPhotosList)
|
|
}
|
|
}
|
|
})
|