| | |
| | | import { useUserStoreHook } from "@/store/modules/user"; |
| | | import { storageLocal, isString, isIncludeAllChildren } from "@pureadmin/utils"; |
| | | import type { nowRoleType } from "@/store/types"; |
| | | import type { LoginResult, RoleItem } from "@/api/types"; |
| | | |
| | | export interface DataInfo<T> { |
| | | /** token */ |
| | |
| | | * 将`accessToken`、`expires`、`refreshToken`这三条信息放在key值为authorized-token的cookie里(过期自动销毁) |
| | | * 将`avatar`、`username`、`nickname`、`exRoles`、`permissions`、`refreshToken`、`expires`这七条信息放在key值为`user-info`的localStorage里(利用`multipleTabsKey`当浏览器完全关闭后自动销毁) |
| | | */ |
| | | export function setToken(data: DataInfo<Date>) { |
| | | export function setToken(data: LoginResult) { |
| | | let expires = 0; |
| | | const { accessToken, refreshToken } = data; |
| | | const { isRemembered, loginDay } = useUserStoreHook(); |
| | |
| | | storageLocal().setItem(userKey, obj); |
| | | } |
| | | |
| | | export function setRoleListInfo(data: DataInfo<string>) { |
| | | export function setRoleListInfo(data: RoleItem[]) { |
| | | useUserStoreHook().SET_EXROLES_LIST(data); |
| | | storageLocal().setItem("rolesList", data); |
| | | } |
| | |
| | | const obj = list.find(item => { |
| | | return item.code == data.code; |
| | | }); |
| | | data = { ...obj, ...data }; |
| | | data = Object.assign(obj, data); |
| | | } |
| | | useUserStoreHook().SET_ROLES([data.name]); |
| | | useUserStoreHook().SET_NOW_ROLE(data); |