Commit fa1af3ad authored by XieZhiXiong's avatar XieZhiXiong

fix: 修复重现登录、切换角色之后最近访问数据还是上个账号/角色的问题

parent aafd4f4d
......@@ -5,6 +5,7 @@ import { getAuth, getCookieAuth, setAuth, setRouters } from '@/utils/auth';
import { postMemberLoginSwitchrole } from '@/services/MemberV2Api';
import { useIntl } from 'umi'
import defaultHomePath from '@/utils/defaultHomePath';
import { clearRecentVisit } from '@/utils/recentVisit';
interface MemberRole {
memberRoleId: number;
......@@ -49,6 +50,7 @@ const Roles: React.FC = () => {
}
setAuth(res.data);
setRouters(res.data.auth);
clearRecentVisit();
setTimeout(() => {
window.location.replace(defaultHomePath());
}, 800);
......
......@@ -3,11 +3,12 @@ import styles from './index.less';
import menu_zh from '@/locales/zh-CN/menu';
import { Tooltip } from 'antd';
import { Link, useIntl } from 'umi';
import { getRecentVisit } from '@/utils/recentVisit';
interface Iprops { }
const RecentVisit: React.FC<Iprops> = () => {
const intl = useIntl();
const recentVisit = localStorage.getItem('recentVisit') && JSON.parse(localStorage.getItem('recentVisit')) || {};
const recentVisit = getRecentVisit();
return (
<div className={styles.recentVisit}>
<div className={styles.header}>
......
......@@ -15,6 +15,10 @@
width: 33.33%;
&-content {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: @padding-sm - 2;
border-radius: 4px;
font-size: @font-size-sm;
......
/**
* @Description 消息提醒
* @Description 最近访问
*/
import React from 'react';
import { history } from 'umi';
import { getRecentVisit } from '@/utils/recentVisit';
import MellowCard from '@/components/MellowCard';
import styles from './index.less';
const RecentlyVisited: React.FC = () => {
const recentVisit = localStorage.getItem('recentVisit') && JSON.parse(localStorage.getItem('recentVisit')) || {};
const recentVisit = getRecentVisit();
const handleJump = (url: string) => {
history.push(url);
......
......@@ -12,6 +12,7 @@ import { isEmpty } from '@antv/util';
import { postMemberLoginSwitchrole } from '@/services/MemberV2Api';
import { getTransactionProductInquiryList, getTransactionQuotationtInquiryExternalStateEnum } from '@/services/TransactionV2Api';
import { AuthUrl } from '@/components/AuthButton/AuthUrl';
import { clearRecentVisit } from '@/utils/recentVisit';
interface MemberRole {
memberRoleId: number;
......@@ -41,6 +42,7 @@ const InquirySearch = () => {
}
setAuth(res.data);
setRouters(res.data.auth);
clearRecentVisit();
setTimeout(() => {
window.location.replace(`/memberCenter/tranactionAbility/productInquiry/waitAddInquiry/two?id=${id}`);
}, 800);
......
......@@ -13,6 +13,7 @@ import { setUserCookie } from '@/utils/siteCookie';
import { omit } from '@/utils';
import defaultHomePath from '@/utils/defaultHomePath';
import styles from './index.less'
import { clearRecentVisit } from '@/utils/recentVisit';
const intl = getIntl();
const LoginWrap: React.FC = () => {
......@@ -32,6 +33,7 @@ const LoginWrap: React.FC = () => {
setRouters(data.auth)
// 设置同域名cookie缓存
setAuth(data)
clearRecentVisit()
// 此处需使用href跳转, 否则无法触发app.ts中的路由初始化校验
if (redirect) {
window.location.replace(decodeURIComponent(Base64.decode(redirect)))
......
......@@ -5,6 +5,7 @@ import { setAuth, setRouters } from '@/utils/auth';
import QRCode from 'qrcode';
import { postMemberLoginAuthUrl, postMemberLoginInfo } from '@/services/MemberV2Api';
import defaultHomePath from '@/utils/defaultHomePath';
import { clearRecentVisit } from '@/utils/recentVisit';
const intl = getIntl();
const ScanLoginWrap: React.FC = () => {
......@@ -68,6 +69,7 @@ const ScanLoginWrap: React.FC = () => {
message.success(intl.formatMessage({ id: 'user.dengluchenggong' }))
setAuth(data)
setRouters(data.auth)
clearRecentVisit()
// 此处需使用href跳转, 否则无法触发app.ts中的路由初始化校验
if (redirect) {
window.location.replace(decodeURIComponent(atob(redirect)))
......
......@@ -4,6 +4,8 @@
* 双向链表 用JSON.stringify 会报错,应该是因为有一个环
*/
import { setRecentVisit, getRecentVisit } from './recentVisit';
const LRUCache = function (capacity: number) {
this.cache = new Map();
......@@ -12,7 +14,7 @@ const LRUCache = function (capacity: number) {
};
LRUCache.prototype.init = function() {
const recentVisit = localStorage.getItem('recentVisit') && JSON.parse(localStorage.getItem('recentVisit')) || {};
const recentVisit = getRecentVisit();
Object.keys(recentVisit).map((item) => {
this.cache.set(item, recentVisit[item]);
})
......@@ -33,7 +35,7 @@ LRUCache.prototype.put = function (key: string, value: string) {
for(var [k, v] of this.cache) {
data[k] = v
}
localStorage.setItem("recentVisit", JSON.stringify(data))
setRecentVisit(data);
};
......
type RecentVisitType = { [key: string]: string }
const recentVisitKey = 'recentVisit';
/**
* 设置最近访问本地存储数据
* @param data
*/
export const setRecentVisit = (data: RecentVisitType) => {
localStorage.setItem(recentVisitKey, JSON.stringify(data));
};
/**
* 获取最近访问本地存储数据
* @param data
*/
export const getRecentVisit = (): RecentVisitType => {
const stora = localStorage.getItem(recentVisitKey);
const recentVisit: RecentVisitType = stora ? JSON.parse(stora) : {};
return recentVisit;
};
/**
* 清除最近访问本地存储数据
* @param data
*/
export const clearRecentVisit = () => {
localStorage.removeItem(recentVisitKey);
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment