|
@@ -1,54 +1,54 @@
|
|
|
-import Cookies from 'js-cookie'
|
|
|
+import Cookies from "js-cookie";
|
|
|
|
|
|
-const TokenKey = 'dy_admin_token'
|
|
|
+const TokenKey = "dy_admin_token";
|
|
|
// const CrossTokenKey = 'Admin-Token'
|
|
|
-const CrossTokenKey = 'Admin-Token'
|
|
|
+const CrossTokenKey = "Admin-Token";
|
|
|
|
|
|
function getCookieDomain() {
|
|
|
- let host = location.hostname
|
|
|
- const ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
|
|
|
- if (ip.test(host) === true || host === 'localhost') return host
|
|
|
- const regex = /([^]*).*/
|
|
|
- const match = host.match(regex)
|
|
|
- if (typeof match !== 'undefined' && match !== null) host = match[1]
|
|
|
- if (typeof host !== 'undefined' && host !== null) {
|
|
|
- const strAry = host.split('.')
|
|
|
+ let host = location.hostname;
|
|
|
+ const ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
|
|
|
+ if (ip.test(host) === true || host === "localhost") return host;
|
|
|
+ const regex = /([^]*).*/;
|
|
|
+ const match = host.match(regex);
|
|
|
+ if (typeof match !== "undefined" && match !== null) host = match[1];
|
|
|
+ if (typeof host !== "undefined" && host !== null) {
|
|
|
+ const strAry = host.split(".");
|
|
|
if (strAry.length > 1) {
|
|
|
- host = strAry[strAry.length - 2] + '.' + strAry[strAry.length - 1]
|
|
|
+ host = strAry[strAry.length - 2] + "." + strAry[strAry.length - 1];
|
|
|
}
|
|
|
}
|
|
|
- return '.' + host
|
|
|
+ return "." + host;
|
|
|
}
|
|
|
|
|
|
-export function getToken () {
|
|
|
- return Cookies.get(TokenKey)
|
|
|
+export function getToken() {
|
|
|
+ return Cookies.get(TokenKey, { domani: getCookieDomain() });
|
|
|
}
|
|
|
|
|
|
export function getTenantId() {
|
|
|
- const tenantConfig = sessionStorage.getItem('tenantConfig')
|
|
|
- const tmp = tenantConfig ? JSON.parse(tenantConfig) : null
|
|
|
- return tmp ? tmp.tenantId : 0
|
|
|
+ const tenantConfig = sessionStorage.getItem("tenantConfig");
|
|
|
+ const tmp = tenantConfig ? JSON.parse(tenantConfig) : null;
|
|
|
+ return tmp ? tmp.tenantId : 0;
|
|
|
}
|
|
|
|
|
|
-export function setToken (token) {
|
|
|
- return Cookies.set(TokenKey, token)
|
|
|
+export function setToken(token) {
|
|
|
+ return Cookies.set(TokenKey, token, { domain: getCookieDomain() });
|
|
|
}
|
|
|
|
|
|
-export function removeToken () {
|
|
|
- return Cookies.remove(TokenKey)
|
|
|
+export function removeToken() {
|
|
|
+ return Cookies.remove(TokenKey, { domain: getCookieDomain() });
|
|
|
}
|
|
|
|
|
|
export function removeTenant() {
|
|
|
// 移除跟机构相关信息
|
|
|
- sessionStorage.removeItem('tenantRenewStatus')
|
|
|
- sessionStorage.removeItem('tenantConfig')
|
|
|
- sessionStorage.removeItem('baseTenantId')
|
|
|
+ sessionStorage.removeItem("tenantRenewStatus");
|
|
|
+ sessionStorage.removeItem("tenantConfig");
|
|
|
+ sessionStorage.removeItem("baseTenantId");
|
|
|
}
|
|
|
|
|
|
-export function setCrossToken (token) {
|
|
|
- return Cookies.set(CrossTokenKey, token, { domain: getCookieDomain() })
|
|
|
+export function setCrossToken(token) {
|
|
|
+ return Cookies.set(CrossTokenKey, token, { domain: getCookieDomain() });
|
|
|
}
|
|
|
|
|
|
-export function removeCrossToken () {
|
|
|
- return Cookies.remove(CrossTokenKey, { domain: getCookieDomain() })
|
|
|
-}
|
|
|
+export function removeCrossToken() {
|
|
|
+ return Cookies.remove(CrossTokenKey, { domain: getCookieDomain() });
|
|
|
+}
|