89 lines
2.0 KiB
JavaScript
89 lines
2.0 KiB
JavaScript
import { defineStore } from 'pinia';
|
|
import { ref } from 'vue';
|
|
|
|
|
|
export const useStorageStore = defineStore('storageStore',{
|
|
state:()=>({
|
|
imgObjStr: '{}',
|
|
videoObjStr: '{}',
|
|
audioObjStr: '{}',
|
|
touchBtnZIndex: 12,
|
|
showPreviewDetail: false,
|
|
fileType: 'iamge',
|
|
fileId: '',
|
|
fileSrc: '',
|
|
gettingVoiceId: ''
|
|
}),
|
|
getters:{
|
|
imgObj(state){
|
|
return JSON.parse(state.imgObjStr)
|
|
},
|
|
videoObj(state){
|
|
return JSON.parse(state.videoObjStr)
|
|
},
|
|
audioObj(state){
|
|
return JSON.parse(state.audioObjStr)
|
|
},
|
|
getTouchBtnZIndex(state){
|
|
return state.touchBtnZIndex
|
|
},
|
|
getShowPreviewDetail(state){
|
|
return state.showPreviewDetail
|
|
},
|
|
getFileType(state){
|
|
return state.fileType
|
|
},
|
|
getFileId(state){
|
|
return state.fileId
|
|
},
|
|
getFileSrc(state){
|
|
return state.fileSrc
|
|
},
|
|
getGettingVoiceId(state){
|
|
return state.gettingVoiceId
|
|
},
|
|
},
|
|
actions:{
|
|
setGettingVoiceId(id){
|
|
return this.gettingVoiceId = id
|
|
},
|
|
setShowPreviewDetail({ status = false, fileType = 'image', fileId = '', fileSrc = '' }){
|
|
this.showPreviewDetail = status
|
|
this.fileId = fileId
|
|
this.fileType = fileType
|
|
this.fileSrc = fileSrc
|
|
},
|
|
setTouchBtnZIndex(index = 12){
|
|
this.touchBtnZIndex = index
|
|
},
|
|
setStorage(type, id, url) {
|
|
if(type === 'image'){
|
|
let _obj = JSON.parse(this.imgObjStr)
|
|
_obj[id] = url
|
|
this.imgObjStr = JSON.stringify(_obj)
|
|
}else if(type === 'video'){
|
|
let _obj = JSON.parse(this.videoObjStr)
|
|
_obj[id] = url
|
|
this.videoObjStr = JSON.stringify(_obj)
|
|
}else if(type === 'audio'){
|
|
let _obj = JSON.parse(this.audioObjStr)
|
|
_obj[id] = url
|
|
this.audioObjStr = JSON.stringify(_obj)
|
|
}
|
|
},
|
|
getStorageById(type, id, cb = (()=>{})){
|
|
// 两种方式 ,传递回调函数 或 直接取return值
|
|
let _obj
|
|
if(type === 'image'){
|
|
_obj = JSON.parse(this.imgObjStr)
|
|
}else if(type === 'video'){
|
|
_obj = JSON.parse(this.videoObjStr)
|
|
}else if(type === 'audio'){
|
|
_obj = JSON.parse(this.audioObjStr)
|
|
}
|
|
let _cache = _obj[id]||''
|
|
cb && cb(_cache)
|
|
return _cache
|
|
}
|
|
}
|
|
}) |