48 lines
1000 B
JavaScript
48 lines
1000 B
JavaScript
// 导入定义仓库的方法
|
|
import {
|
|
defineStore
|
|
} from 'pinia';
|
|
// 导入响应式和计算
|
|
import {
|
|
ref
|
|
} from 'vue';
|
|
|
|
const useUserStore = defineStore("user", () => {
|
|
|
|
// 定义一个状态用户信息
|
|
const userInfo = ref(uni.getStorageSync('userInfo') || {});
|
|
// 定义一个设置状态的方法
|
|
const setUserInfo = (data) => {
|
|
userInfo.value = data;
|
|
uni.setStorageSync('userInfo', data)
|
|
}
|
|
|
|
const token = ref(uni.getStorageSync('token') || '');
|
|
const setToken = (data) => {
|
|
token.value = data;
|
|
uni.setStorageSync('token', data)
|
|
}
|
|
|
|
// #ifdef H5
|
|
token.value = "31f74a72e2d05673ec14d2a6408718ef"
|
|
userInfo.value = {
|
|
avatar: "https://lihaiim.oss-cn-chengdu.aliyuncs.com/image/admin/default_avatar.png",
|
|
id: 9,
|
|
is_disable: 0,
|
|
is_new_user: 1,
|
|
mobile: "19330904744",
|
|
nickname: "用户1714964250",
|
|
supplier: null,
|
|
token: "31f74a72e2d05673ec14d2a6408718ef"
|
|
}
|
|
// #endif
|
|
|
|
return {
|
|
userInfo,
|
|
setUserInfo,
|
|
token,
|
|
setToken
|
|
}
|
|
})
|
|
|
|
export default useUserStore; |