Commit 98e1af9d authored by 前端-许佳敏's avatar 前端-许佳敏

fix: 用户信息清除方式

parent 84825218
......@@ -14,7 +14,8 @@ export const REQUEST_HEADER = 'http://'
/**
* 顶域
*/
export const TOP_DOMAIN = process.env.NODE_ENV !== 'development' ? getTopDomainByHost(GlobalConfig.global.siteInfo.siteUrl) : 'lingxidev.com'
// export const TOP_DOMAIN = process.env.NODE_ENV !== 'development' ? getTopDomainByHost(GlobalConfig.global.siteInfo.siteUrl) : 'lingxidev.com'
export const TOP_DOMAIN = getTopDomainByHost(GlobalConfig.global.siteInfo.siteUrl)
/**
* 平台首页域名
......
......@@ -19,6 +19,7 @@ export interface AuthInfo {
}
const AUTH_KEY = 'AUTH'
const AUTH_ROLES_KEY = 'AUTH_ROLES'
export const setAuth = (info: AuthInfo) => {
const auth = {
userId: info.userId,
......@@ -31,8 +32,9 @@ export const setAuth = (info: AuthInfo) => {
memberRoleType: info.memberRoleType,
memberRoleId: info.memberRoleId
}
setCookie(AUTH_KEY, JSON.stringify(auth), { domain: TOP_DOMAIN })
setCookie('AUTH_ROLES', JSON.stringify(info.roles), { domain: TOP_DOMAIN })
console.log(getTopDomainByHost(TOP_DOMAIN, true))
setCookie(AUTH_KEY, JSON.stringify(auth), { domain: getTopDomainByHost(TOP_DOMAIN, true) })
setCookie(AUTH_ROLES_KEY, JSON.stringify(info.roles), { domain: getTopDomainByHost(TOP_DOMAIN, true) })
setLocalAuth(info)
setRouters(info.urls)
}
......@@ -77,8 +79,8 @@ export const removeRouters = () => {
}
export const removeAuth = () => {
console.log(TOP_DOMAIN)
removeCookie(AUTH_KEY, { path: '/', domain: TOP_DOMAIN })
removeCookie(AUTH_KEY, { path: '/', domain: getTopDomainByHost(TOP_DOMAIN, true) })
removeCookie(AUTH_ROLES_KEY, { path: '/', domain: getTopDomainByHost(TOP_DOMAIN, true) })
window.localStorage.removeItem(AUTH_KEY)
removeRouters()
}
......
......@@ -642,8 +642,13 @@ export const getIChannelInfo = () => {
* @param url 链接
* @returns
*/
export const getTopDomainByHost = (url: string): string => {
export const getTopDomainByHost = (url: string, isPort = false): string => {
if (!url) return ''
// 如果后缀带有端口号, 可通过第二个参数把端口去掉
const splitUrl = url.split(':')
if (splitUrl.length > 1 && isPort) {
return `${splitUrl[0].split('.').slice(-2).join('.')}`
}
return url.split('.').slice(-2).join('.')
}
......
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