"use strict"; const common_vendor = require("../common/vendor.js"); const useUserStore = common_vendor.defineStore("user", () => { const token = common_vendor.ref(null); const userInfo = common_vendor.ref(null); const roleKeyInfo = common_vendor.ref(null); const baseUrlHt = common_vendor.ref("https://opo.qduh.cn:443"); const isLoggedIn = common_vendor.computed(() => !!token.value); const userName = common_vendor.computed(() => { var _a; return ((_a = userInfo.value) == null ? void 0 : _a.name) || ""; }); const ADMIN_ROLES = ["admin", "medical_admin"]; const USER_ROLES = ["user", "patient"]; const DOCTOR_ROLES = ["doctor", "specialist"]; function setToken(newToken) { token.value = newToken; common_vendor.index.setStorageSync("token", newToken); } function setUserInfo(info) { userInfo.value = info; common_vendor.index.setStorageSync("userInfo", info); } function setroleKey(roleKey) { if (ADMIN_ROLES.includes(roleKey)) { roleKeyInfo.value = 1; } else if (DOCTOR_ROLES.includes(roleKey)) { roleKeyInfo.value = 2; } else if (USER_ROLES.includes(roleKey)) { roleKeyInfo.value = 0; } else { roleKeyInfo.value = 0; } common_vendor.index.setStorageSync("roleKeyInfo", roleKeyInfo.value); } function clearUser() { token.value = null; userInfo.value = null; roleKeyInfo.value = null; common_vendor.index.removeStorageSync("token"); common_vendor.index.removeStorageSync("roleKeyInfo"); common_vendor.index.removeStorageSync("userInfo"); } function initFromStorage() { const localToken = common_vendor.index.getStorageSync("token"); const localUser = common_vendor.index.getStorageSync("userInfo"); const localroleKey = common_vendor.index.getStorageSync("roleKeyInfo"); if (localToken) token.value = localToken; if (localUser) userInfo.value = localUser; if (localroleKey) roleKeyInfo.value = localroleKey; } async function refreshUserInfo() { try { const res = await common_vendor.index.$uapi.get("/getInfo"); if (res && res.user) { setUserInfo(res.user); if (res.roles) setroleKey(res.roles); return true; } return false; } catch (error) { common_vendor.index.__f__("error", "at stores/user.js:73", "刷新用户信息失败", error); return false; } } return { token, userInfo, roleKeyInfo, isLoggedIn, userName, baseUrlHt, setToken, setUserInfo, clearUser, initFromStorage, setroleKey, refreshUserInfo }; }); exports.useUserStore = useUserStore; //# sourceMappingURL=../../.sourcemap/mp-weixin/stores/user.js.map