import { defineStore } from 'pinia'
import { ref } from 'vue'
import type {LoginResult} from '@/types/member'
//定义 Store
export const useMemberStore = defineStore(
'member',
() => {
// 会员信息
const profile = ref<LoginResult>()
//保存会员信息,登录时使用
const setProfile = (val: LoginResult) => {
profile.value = val
}
//清理会员信息,退出时使用,赋值undefined
const clearProfile = () => {
profile.value = undefined
}
//记得 return
return {
profile,
setProfile,
clearProfile,
}
},
//TODO:持久化
{
//persist: true,
//注意:微信小程序的本地存储,和H5本地存储不一样,必须写 storage: { setItem(){},
getItem(){} }
persist: {
//调整为兼容多端的API
storage: {
getItem(key) {
return uni.getStorageSync(key) // [!code warning]
},
setItem(key, value) {
uni.setStorageSync(key, value) // [!code warning]
},
},
},
},
)