purchase-let/store/user.js

50 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-04-25 18:02:30 +08:00
// 导入定义仓库的方法
2024-05-07 13:35:30 +08:00
import {
defineStore
} from 'pinia';
2024-04-25 18:02:30 +08:00
// 导入响应式和计算
2024-05-07 13:35:30 +08:00
import {
ref
} from 'vue';
2024-04-25 18:02:30 +08:00
const useUserStore = defineStore("user", () => {
2024-05-06 17:58:41 +08:00
2024-05-07 13:35:30 +08:00
// 定义一个状态用户信息
const userInfo = ref(uni.getStorageSync('userInfo') || {});
// 定义一个设置状态的方法
const setUserInfo = (data) => {
userInfo.value = data;
uni.setStorageSync('userInfo', data)
}
2024-05-06 17:58:41 +08:00
2024-05-07 13:35:30 +08:00
const token = ref(uni.getStorageSync('token') || '');
const setToken = (data) => {
token.value = data;
uni.setStorageSync('token', data)
}
2024-05-06 17:58:41 +08:00
2024-05-07 15:11:40 +08:00
// #ifdef H5
2024-05-09 09:12:22 +08:00
2024-05-16 18:03:25 +08:00
token.value = "356b6f0615184692de99df42b9329749"
2024-05-07 19:02:43 +08:00
// token.value = "95b24dd6d2dda836fe07854b08ba0944"
2024-05-07 15:11:40 +08:00
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,
2024-05-16 18:03:25 +08:00
token: "356b6f0615184692de99df42b9329749"
2024-05-07 15:11:40 +08:00
}
// #endif
2024-05-06 17:58:41 +08:00
2024-05-07 13:35:30 +08:00
return {
userInfo,
setUserInfo,
token,
setToken
}
2024-04-25 18:02:30 +08:00
})
export default useUserStore;