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