update 后台跳转大屏免登录,优化登录数据缓存
This commit is contained in:
@@ -31,7 +31,6 @@ export const Map = {
|
|||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
AMap = res;
|
AMap = res;
|
||||||
const { zoom, center, mapStyle } = { ...defaultOption, ...option };
|
const { zoom, center, mapStyle } = { ...defaultOption, ...option };
|
||||||
console.log('option', option, center);
|
|
||||||
//基本地图加载
|
//基本地图加载
|
||||||
this.map = new AMap.Map(el, {
|
this.map = new AMap.Map(el, {
|
||||||
resizeEnable: true,
|
resizeEnable: true,
|
||||||
|
|||||||
@@ -86,10 +86,12 @@
|
|||||||
setValue(result, page);
|
setValue(result, page);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
const { result, page } = JSON.parse(getSession(PAGE2_RIGHT3));
|
const { result, page } = getSession(PAGE2_RIGHT3) ? JSON.parse(getSession(PAGE2_RIGHT3)) : {};
|
||||||
|
if (result) {
|
||||||
setValue(result, page);
|
setValue(result, page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setValue(result, page) {
|
function setValue(result, page) {
|
||||||
dataSource.value = result.records;
|
dataSource.value = result.records;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
export interface RoleInfo {
|
||||||
|
roleName: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserInfo {
|
||||||
|
id: string | number;
|
||||||
|
userId: string | number;
|
||||||
|
username: string;
|
||||||
|
realname: string;
|
||||||
|
avatar: string;
|
||||||
|
desc?: string;
|
||||||
|
homePath?: string;
|
||||||
|
tenantid?: string | number;
|
||||||
|
roles: RoleInfo[];
|
||||||
|
orgCode?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LoginInfo {
|
||||||
|
multi_depart?: string | number;
|
||||||
|
userInfo?: object;
|
||||||
|
departs?: [];
|
||||||
|
tenantList?: [];
|
||||||
|
isLogin?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LoginParams {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import { TOKEN_KEY, USER_INFO_KEY } from '/@/enum/cacheEnum.ts';
|
|||||||
import { getBaseLogin, PageEnum } from '/@/enum/pageEnum.ts';
|
import { getBaseLogin, PageEnum } from '/@/enum/pageEnum.ts';
|
||||||
import { getAuthCache, setAuthCache } from '/@/utils/auth.ts';
|
import { getAuthCache, setAuthCache } from '/@/utils/auth.ts';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import { LoginInfo, LoginParams, UserInfo } from '/@/store/modules/storeType.ts';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
export const useUserStore = defineStore({
|
export const useUserStore = defineStore({
|
||||||
@@ -15,32 +16,32 @@ export const useUserStore = defineStore({
|
|||||||
loginInfo: null,
|
loginInfo: null,
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getUserInfo() {
|
getUserInfo(): UserInfo {
|
||||||
return (this.userInfo && Object.keys(this.userInfo).length > 0) || getAuthCache(USER_INFO_KEY) || {};
|
return (this.userInfo && Object.keys(this.userInfo).length > 0) || getAuthCache(USER_INFO_KEY) || {};
|
||||||
},
|
},
|
||||||
getLoginInfo() {
|
getLoginInfo(): LoginInfo {
|
||||||
return this.loginInfo;
|
return this.loginInfo || {};
|
||||||
},
|
},
|
||||||
getToken() {
|
getToken(): string {
|
||||||
return this.token || getAuthCache(TOKEN_KEY);
|
return this.token || getAuthCache(TOKEN_KEY);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setToken(info) {
|
setToken(info: string | undefined) {
|
||||||
this.token = info;
|
this.token = info ? info : '';
|
||||||
setAuthCache(TOKEN_KEY, info);
|
setAuthCache(TOKEN_KEY, info);
|
||||||
},
|
},
|
||||||
setUserInfo(info) {
|
setUserInfo(info: UserInfo | null) {
|
||||||
this.userInfo = info;
|
this.userInfo = info;
|
||||||
setAuthCache(USER_INFO_KEY, info);
|
setAuthCache(USER_INFO_KEY, info);
|
||||||
},
|
},
|
||||||
setLoginInfo(info) {
|
setLoginInfo(info: LoginInfo | null) {
|
||||||
this.loginInfo = info;
|
this.loginInfo = info;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 登录事件
|
* 登录事件
|
||||||
*/
|
*/
|
||||||
async login(params) {
|
async login(params: LoginParams) {
|
||||||
try {
|
try {
|
||||||
const { goHome = true, mode, ...loginParams } = params;
|
const { goHome = true, mode, ...loginParams } = params;
|
||||||
const data = await loginApi(loginParams, mode);
|
const data = await loginApi(loginParams, mode);
|
||||||
|
|||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
import { isJSON } from '/@/utils/is.ts';
|
import { isJSON, isObjectOrArray } from '/@/utils/is.ts';
|
||||||
|
|
||||||
export function getAuthCache(key) {
|
export function getAuthCache(key) {
|
||||||
let v = localStorage.getItem(key);
|
let v = localStorage.getItem(key);
|
||||||
@@ -10,9 +10,9 @@ export function getAuthCache(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setAuthCache(key, value) {
|
export function setAuthCache(key, value) {
|
||||||
if (!isJSON(value)) {
|
if (isObjectOrArray(value)) {
|
||||||
return localStorage.setItem(key, value);
|
|
||||||
} else {
|
|
||||||
return localStorage.setItem(key, JSON.stringify(value));
|
return localStorage.setItem(key, JSON.stringify(value));
|
||||||
|
} else {
|
||||||
|
return localStorage.setItem(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,3 +19,8 @@ export function isJSON(str) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//是否为对象或数组
|
||||||
|
export function isObjectOrArray(obj) {
|
||||||
|
return isObject(obj) || isArray(obj);
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,7 +105,6 @@
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
console.log('route', route);
|
|
||||||
const prefixCls = 'mini-login';
|
const prefixCls = 'mini-login';
|
||||||
const { notification, createMessage } = useMessage();
|
const { notification, createMessage } = useMessage();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|||||||
@@ -10,14 +10,13 @@
|
|||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const { baseLogin, baseHome, msg } = JSON.parse(route.query.data);
|
const { baseLogin, baseHome, msg } = JSON.parse(route.query.data);
|
||||||
setBaseLogin(baseLogin);
|
setBaseLogin(baseLogin);
|
||||||
getUserInfo().then((res) => {
|
|
||||||
const { code, result } = res;
|
|
||||||
if (code == 200) {
|
|
||||||
userStore.setToken(msg);
|
userStore.setToken(msg);
|
||||||
|
getUserInfo().then((res) => {
|
||||||
|
const { code, result } = res || {};
|
||||||
|
if (code == 200) {
|
||||||
userStore.setUserInfo(result.userInfo);
|
userStore.setUserInfo(result.userInfo);
|
||||||
router.push(baseHome);
|
router.push(baseHome);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log('route', route);
|
|
||||||
</script>
|
</script>
|
||||||
<style scoped lang="less"></style>
|
<style scoped lang="less"></style>
|
||||||
|
|||||||
Reference in New Issue
Block a user