@das-fed/utils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-services/index.js +19846 -0
- package/api-services/modules/app-manage.js +6 -0
- package/api-services/modules/authentication.js +6 -0
- package/api-services/modules/bems.js +11 -0
- package/api-services/modules/contract.js +6 -0
- package/api-services/modules/duty-manage.js +15 -0
- package/api-services/modules/enterpriseright.js +6 -0
- package/api-services/modules/file.js +409 -0
- package/api-services/modules/gateway-edge.js +6 -0
- package/api-services/modules/index.js +494 -0
- package/api-services/modules/iot.js +19 -0
- package/api-services/modules/justauth.js +7 -0
- package/api-services/modules/knowledge.js +6 -0
- package/api-services/modules/link.js +6 -0
- package/api-services/modules/permission.js +6 -0
- package/api-services/modules/platformManage.js +14 -0
- package/api-services/modules/portal.js +6 -0
- package/api-services/modules/space-manage.js +6 -0
- package/api-services/modules/super-admin.js +9 -0
- package/api-services/modules/supplier.js +8 -0
- package/api-services/modules/supplychain-manage.js +6 -0
- package/api-services/modules/systemConfiguration.js +6 -0
- package/api-services/modules/tool.js +6 -0
- package/api-services/src/create-service.js +19846 -0
- package/api-services/src/sso.js +200 -0
- package/api-services/src/util.js +23 -0
- package/atob/index.js +12 -0
- package/common-info/getIframeUrl.js +13 -0
- package/common-info/index.js +311 -0
- package/common-info/setInfoFromUrl.js +156 -0
- package/common-tools/arr-tools.js +15 -0
- package/common-tools/date-format.js +22 -0
- package/common-tools/get-url-params.js +92 -0
- package/common-tools/handle-data.js +5 -0
- package/common-tools/index.js +213 -0
- package/common-tools/nest-tree-format.js +53 -0
- package/common-tools/obj-tools.js +21 -0
- package/common-tools/setHtmlMinWH.js +11 -0
- package/common-tools/throttled.js +19 -0
- package/config/index.js +26 -0
- package/curring-http/index.js +17310 -0
- package/directive/auth.js +114 -0
- package/directive/clickOutside.js +53 -0
- package/directive/hoverInside.js +40 -0
- package/directive/index.js +183 -0
- package/directive/utils.js +12 -0
- package/dom-check-in/index.js +16 -0
- package/dom-watcher/index.js +10 -0
- package/hooks/popup-manager/use-zindex.js +41 -0
- package/index.js +215 -0
- package/load-js/index.js +23 -0
- package/oss/index.js +16 -0
- package/package.json +44 -0
- package/pinyin-first-character/index.js +12223 -0
- package/process-engine-info/index.js +12 -0
- package/pure-image-src/index.js +30 -0
- package/set-personal-info/index.js +24 -0
- package/size-watcher/index.js +27 -0
- package/style/index.js +115 -0
- package/style/math.js +32 -0
- package/style/style.js +84 -0
- package/token-tools/index.js +179 -0
- package/vue/hooks/use-model-value.js +11 -0
- package/vue/index.js +11 -0
- package/webSocket-service/index.js +170 -0
- package/with-install/index.js +8 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { ref, watch } from 'vue';
|
|
3
|
+
import { encryption } from '@das-fed/utils/atob';
|
|
4
|
+
import { getConfig } from '@das-fed/utils/config';
|
|
5
|
+
import { getUrlParams, funcUrlDel } from '@das-fed/utils/common-tools';
|
|
6
|
+
import { setAccessToken, getAccessToken, removeAccessToken } from '@das-fed/utils/token-tools';
|
|
7
|
+
import { setProcessEngineToken } from '@das-fed/utils/process-engine-info';
|
|
8
|
+
import { setPersonalInfo } from '@das-fed/utils/set-personal-info';
|
|
9
|
+
|
|
10
|
+
const getQuery = (name) => new URL(location.href).searchParams.get(name);
|
|
11
|
+
const apis = {
|
|
12
|
+
oauth: "/api/justauth/oauth-server/v1/visitor/oauth/authorize",
|
|
13
|
+
// 重定向到登录页
|
|
14
|
+
token: "/api/justauth/oauth-server/v1/visitor/oauth/token"
|
|
15
|
+
// 通过code获取token
|
|
16
|
+
};
|
|
17
|
+
const refreshing = ref(false);
|
|
18
|
+
const { baseURL, mainAppName, microAppName } = getConfig();
|
|
19
|
+
const real_uri = mainAppName || window.__IN_MICRO_APP__ ? `${location.origin}/` : location.origin + location.pathname;
|
|
20
|
+
const getTokenParams = {
|
|
21
|
+
response_type: "code",
|
|
22
|
+
scope: "sever",
|
|
23
|
+
client_id: "sys",
|
|
24
|
+
client_secret: encryption("das123"),
|
|
25
|
+
state: +/* @__PURE__ */ new Date()
|
|
26
|
+
};
|
|
27
|
+
const getTokenFromCode = async (code, data, redirectUri, keepLogin) => {
|
|
28
|
+
const kingdee_token = getUrlParams(location.href, "kingdee_token") || "";
|
|
29
|
+
let tokenRes = {};
|
|
30
|
+
const tokenParams = {
|
|
31
|
+
grant_type: "authorization_code",
|
|
32
|
+
code,
|
|
33
|
+
client_id: data.client_id,
|
|
34
|
+
client_secret: data.client_secret,
|
|
35
|
+
redirect_uri: redirectUri || real_uri
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
if (keepLogin) {
|
|
39
|
+
tokenParams.keep_login = true;
|
|
40
|
+
tokenParams.redirect_uri = `${tokenParams.redirect_uri}?keep_login=true`;
|
|
41
|
+
}
|
|
42
|
+
if (kingdee_token) {
|
|
43
|
+
sessionStorage.setItem("kingdee_token", kingdee_token);
|
|
44
|
+
tokenParams.redirect_uri = `${tokenParams.redirect_uri}?kingdee_token=${kingdee_token}`;
|
|
45
|
+
}
|
|
46
|
+
tokenRes = await axios.create().post(
|
|
47
|
+
apis.token,
|
|
48
|
+
{},
|
|
49
|
+
{
|
|
50
|
+
baseURL,
|
|
51
|
+
params: tokenParams,
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
const { access_token, refresh_token, expires_in } = tokenRes.data;
|
|
58
|
+
const tokenData = {
|
|
59
|
+
accessToken: access_token,
|
|
60
|
+
accessTokenExpiredAt: +/* @__PURE__ */ new Date() + expires_in * 1e3,
|
|
61
|
+
refreshToken: refresh_token,
|
|
62
|
+
info: tokenRes.data
|
|
63
|
+
};
|
|
64
|
+
setAccessToken(access_token, tokenRes.data);
|
|
65
|
+
tokenStorage().save(tokenData);
|
|
66
|
+
setPersonalInfo(access_token);
|
|
67
|
+
let filterParams = ["code", "state", "keep_login", "kingdee_token"];
|
|
68
|
+
window.history.replaceState(null, "", funcUrlDel(filterParams));
|
|
69
|
+
return access_token;
|
|
70
|
+
} catch {
|
|
71
|
+
return login({ ...getTokenParams, redirect_uri: redirectUri || real_uri });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const getToken = async (config) => {
|
|
75
|
+
if (config.public)
|
|
76
|
+
return;
|
|
77
|
+
if (refreshing.value) {
|
|
78
|
+
return await new Promise(async (res) => {
|
|
79
|
+
watch(
|
|
80
|
+
() => refreshing.value,
|
|
81
|
+
(value) => {
|
|
82
|
+
if (!value) {
|
|
83
|
+
const token = getAccessToken();
|
|
84
|
+
res(token);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const accessToken = getAccessToken();
|
|
91
|
+
const { accessTokenExpiredAt, redirectUri } = tokenStorage().getData();
|
|
92
|
+
const oauthCode = getQuery("code") || "";
|
|
93
|
+
const keepLogin = !!getQuery("keep_login");
|
|
94
|
+
refreshing.value = true;
|
|
95
|
+
const whiteList = JSON.parse(sessionStorage.getItem("noLogin-page")) || [];
|
|
96
|
+
if ((!accessToken || accessTokenExpiredAt === 0) && microAppName !== "oauth" && !whiteList.includes(location.pathname)) {
|
|
97
|
+
const needLogin = !oauthCode;
|
|
98
|
+
if (needLogin) {
|
|
99
|
+
return login({ ...getTokenParams, redirect_uri: real_uri });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const tokenExpired = accessTokenExpiredAt > 0 && +/* @__PURE__ */ new Date() + 60 * 1e3 > accessTokenExpiredAt;
|
|
103
|
+
if (tokenExpired)
|
|
104
|
+
return refreshToken(getTokenParams);
|
|
105
|
+
if (accessToken)
|
|
106
|
+
return accessToken;
|
|
107
|
+
if (!oauthCode) {
|
|
108
|
+
refreshing.value = false;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const accessToken2 = await getTokenFromCode(oauthCode, getTokenParams, redirectUri, keepLogin);
|
|
113
|
+
refreshing.value = false;
|
|
114
|
+
return accessToken2;
|
|
115
|
+
} catch {
|
|
116
|
+
refreshing.value = false;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const login = (params) => {
|
|
120
|
+
const { baseURL: baseURL2, ssoLocale } = getConfig();
|
|
121
|
+
params.logout = "true";
|
|
122
|
+
if (ssoLocale)
|
|
123
|
+
params.locale = "locale";
|
|
124
|
+
const query = Object.keys(params).filter((key) => key !== "client_secret").map((key) => `${key}=${params[key]}`).join("&");
|
|
125
|
+
const ssoUrl = `${baseURL2}${apis.oauth}?${query}`;
|
|
126
|
+
removeAccessToken();
|
|
127
|
+
sessionStorage.clear();
|
|
128
|
+
tokenStorage().save({ redirectUri: params.redirect_uri });
|
|
129
|
+
window.__isAutoCloseApp = false;
|
|
130
|
+
location.replace(ssoUrl);
|
|
131
|
+
};
|
|
132
|
+
const refreshToken = async (params) => {
|
|
133
|
+
const { baseURL: baseURL2 } = getConfig();
|
|
134
|
+
const { refreshToken: refreshToken2, redirectUri } = tokenStorage().getData();
|
|
135
|
+
params.redirect_uri = redirectUri;
|
|
136
|
+
try {
|
|
137
|
+
const tokenRes = await axios.create().post(apis.token, {
|
|
138
|
+
baseURL: baseURL2,
|
|
139
|
+
params: {
|
|
140
|
+
refresh_token: refreshToken2,
|
|
141
|
+
grant_type: "refresh_token",
|
|
142
|
+
client_id: params.client_id,
|
|
143
|
+
client_secret: params.client_secret,
|
|
144
|
+
redirect_uri: redirectUri
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const { access_token, refresh_token, expires_in } = tokenRes.data;
|
|
148
|
+
const tokenData = {
|
|
149
|
+
accessToken: access_token,
|
|
150
|
+
accessTokenExpiredAt: +/* @__PURE__ */ new Date() + expires_in * 1e3,
|
|
151
|
+
refreshToken: refresh_token,
|
|
152
|
+
info: tokenRes.data
|
|
153
|
+
};
|
|
154
|
+
setAccessToken(access_token, tokenRes.data);
|
|
155
|
+
tokenStorage().save(tokenData);
|
|
156
|
+
setPersonalInfo(access_token);
|
|
157
|
+
return access_token;
|
|
158
|
+
} catch {
|
|
159
|
+
return login(params);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const tokenStorage = () => {
|
|
163
|
+
const accessTokenKey = "accessToken";
|
|
164
|
+
const accessTokenExpiredAtKey = "accessTokenExpiredAt";
|
|
165
|
+
const refreshTokenKey = "refreshToken";
|
|
166
|
+
const tokenInfoKey = "tokenInfo";
|
|
167
|
+
const redirectUriKey = "redirectUri";
|
|
168
|
+
return {
|
|
169
|
+
getData: () => {
|
|
170
|
+
return {
|
|
171
|
+
accessToken: sessionStorage.getItem(accessTokenKey) || "",
|
|
172
|
+
accessTokenExpiredAt: Number(sessionStorage.getItem(accessTokenExpiredAtKey) || "0"),
|
|
173
|
+
refreshToken: sessionStorage.getItem(refreshTokenKey) || "",
|
|
174
|
+
info: JSON.parse(
|
|
175
|
+
sessionStorage.getItem(tokenInfoKey) === "undefined" ? "{}" : sessionStorage.getItem(tokenInfoKey) || "{}"
|
|
176
|
+
),
|
|
177
|
+
redirectUri: sessionStorage.getItem(redirectUriKey) || ""
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
save: (data) => {
|
|
181
|
+
const accessTokenExpiredAt = data.accessTokenExpiredAt || 0;
|
|
182
|
+
sessionStorage.setItem(accessTokenKey, data.accessToken || "");
|
|
183
|
+
sessionStorage.setItem(accessTokenExpiredAtKey, accessTokenExpiredAt.toString());
|
|
184
|
+
sessionStorage.setItem(refreshTokenKey, data.refreshToken || "");
|
|
185
|
+
sessionStorage.setItem(tokenInfoKey, JSON.stringify(data.info || {}));
|
|
186
|
+
if (data.redirectUri)
|
|
187
|
+
sessionStorage.setItem(redirectUriKey, data.redirectUri || "");
|
|
188
|
+
setProcessEngineToken(data);
|
|
189
|
+
},
|
|
190
|
+
remove: () => {
|
|
191
|
+
sessionStorage.removeItem(accessTokenKey);
|
|
192
|
+
sessionStorage.removeItem(accessTokenExpiredAtKey);
|
|
193
|
+
sessionStorage.removeItem(refreshTokenKey);
|
|
194
|
+
sessionStorage.removeItem(tokenInfoKey);
|
|
195
|
+
sessionStorage.removeItem(redirectUriKey);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export { getQuery, getToken, getTokenFromCode, getTokenParams, login, real_uri, tokenStorage };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getConfig } from '@das-fed/utils/config';
|
|
3
|
+
|
|
4
|
+
const apis = {
|
|
5
|
+
certificateInstalled: "/api/license/admin/v1/visitor/certificate/installed"
|
|
6
|
+
};
|
|
7
|
+
const getCertificateInstalled = () => {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
axios.get(apis.certificateInstalled, {
|
|
10
|
+
baseURL: getConfig().baseURL,
|
|
11
|
+
params: {
|
|
12
|
+
timestamp: (/* @__PURE__ */ new Date()).getTime()
|
|
13
|
+
}
|
|
14
|
+
}).then((res) => {
|
|
15
|
+
const returnData = res?.data ?? res;
|
|
16
|
+
resolve([null, returnData]);
|
|
17
|
+
}).catch((err) => {
|
|
18
|
+
resolve([err, null]);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { getCertificateInstalled };
|
package/atob/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const encryption = (str) => {
|
|
2
|
+
var encStr = encodeURIComponent(str);
|
|
3
|
+
encStr = btoa(encStr);
|
|
4
|
+
return encStr;
|
|
5
|
+
};
|
|
6
|
+
const decrypt = (str) => {
|
|
7
|
+
var decStr = atob(str);
|
|
8
|
+
decStr = decodeURIComponent(decStr);
|
|
9
|
+
return decStr;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { decrypt, encryption };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getFullPath } from '@das-fed/utils/common-tools';
|
|
2
|
+
|
|
3
|
+
const getIframeUrl = (page, query) => {
|
|
4
|
+
if (!page)
|
|
5
|
+
return;
|
|
6
|
+
let innerQuery = {};
|
|
7
|
+
const applicationPath = "enterpriseadmin/iocvisual";
|
|
8
|
+
if (page === "preview" || page === "preview3d")
|
|
9
|
+
innerQuery = { showLayout: false };
|
|
10
|
+
return getFullPath("/" + applicationPath + "/" + page, { ...innerQuery, ...query });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { getIframeUrl };
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { tokenStorage } from '@das-fed/utils/api-services/src/sso';
|
|
2
|
+
import { getConfig } from '@das-fed/utils/config';
|
|
3
|
+
import { getUrlParams } from '@das-fed/utils/common-tools';
|
|
4
|
+
|
|
5
|
+
/*! js-cookie v3.0.5 | MIT */
|
|
6
|
+
/* eslint-disable no-var */
|
|
7
|
+
function assign (target) {
|
|
8
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
9
|
+
var source = arguments[i];
|
|
10
|
+
for (var key in source) {
|
|
11
|
+
target[key] = source[key];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return target
|
|
15
|
+
}
|
|
16
|
+
/* eslint-enable no-var */
|
|
17
|
+
|
|
18
|
+
/* eslint-disable no-var */
|
|
19
|
+
var defaultConverter = {
|
|
20
|
+
read: function (value) {
|
|
21
|
+
if (value[0] === '"') {
|
|
22
|
+
value = value.slice(1, -1);
|
|
23
|
+
}
|
|
24
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
|
|
25
|
+
},
|
|
26
|
+
write: function (value) {
|
|
27
|
+
return encodeURIComponent(value).replace(
|
|
28
|
+
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
29
|
+
decodeURIComponent
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/* eslint-enable no-var */
|
|
34
|
+
|
|
35
|
+
/* eslint-disable no-var */
|
|
36
|
+
|
|
37
|
+
function init (converter, defaultAttributes) {
|
|
38
|
+
function set (name, value, attributes) {
|
|
39
|
+
if (typeof document === 'undefined') {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
attributes = assign({}, defaultAttributes, attributes);
|
|
44
|
+
|
|
45
|
+
if (typeof attributes.expires === 'number') {
|
|
46
|
+
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
47
|
+
}
|
|
48
|
+
if (attributes.expires) {
|
|
49
|
+
attributes.expires = attributes.expires.toUTCString();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
name = encodeURIComponent(name)
|
|
53
|
+
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
54
|
+
.replace(/[()]/g, escape);
|
|
55
|
+
|
|
56
|
+
var stringifiedAttributes = '';
|
|
57
|
+
for (var attributeName in attributes) {
|
|
58
|
+
if (!attributes[attributeName]) {
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
63
|
+
|
|
64
|
+
if (attributes[attributeName] === true) {
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Considers RFC 6265 section 5.2:
|
|
69
|
+
// ...
|
|
70
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
71
|
+
// character:
|
|
72
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
73
|
+
// not including, the first %x3B (";") character.
|
|
74
|
+
// ...
|
|
75
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (document.cookie =
|
|
79
|
+
name + '=' + converter.write(value, name) + stringifiedAttributes)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function get (name) {
|
|
83
|
+
if (typeof document === 'undefined' || (arguments.length && !name)) {
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// To prevent the for loop in the first place assign an empty array
|
|
88
|
+
// in case there are no cookies at all.
|
|
89
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
90
|
+
var jar = {};
|
|
91
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
92
|
+
var parts = cookies[i].split('=');
|
|
93
|
+
var value = parts.slice(1).join('=');
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
var found = decodeURIComponent(parts[0]);
|
|
97
|
+
jar[found] = converter.read(value, found);
|
|
98
|
+
|
|
99
|
+
if (name === found) {
|
|
100
|
+
break
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return name ? jar[name] : jar
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return Object.create(
|
|
109
|
+
{
|
|
110
|
+
set,
|
|
111
|
+
get,
|
|
112
|
+
remove: function (name, attributes) {
|
|
113
|
+
set(
|
|
114
|
+
name,
|
|
115
|
+
'',
|
|
116
|
+
assign({}, attributes, {
|
|
117
|
+
expires: -1
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
},
|
|
121
|
+
withAttributes: function (attributes) {
|
|
122
|
+
return init(this.converter, assign({}, this.attributes, attributes))
|
|
123
|
+
},
|
|
124
|
+
withConverter: function (converter) {
|
|
125
|
+
return init(assign({}, this.converter, converter), this.attributes)
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
attributes: { value: Object.freeze(defaultAttributes) },
|
|
130
|
+
converter: { value: Object.freeze(converter) }
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var api = init(defaultConverter, { path: '/' });
|
|
136
|
+
|
|
137
|
+
const getUrlToken = () => {
|
|
138
|
+
const search = new URL(location.href).searchParams;
|
|
139
|
+
const token = search.get("token") || search.get("accessToken") || search.get("accesstoken") || "";
|
|
140
|
+
if (token) {
|
|
141
|
+
const tokenInfo = JSON.stringify({ access_token: token });
|
|
142
|
+
sessionStorage.setItem("accessToken", token);
|
|
143
|
+
sessionStorage.setItem("tokenInfo", tokenInfo);
|
|
144
|
+
api.set("accessToken", token);
|
|
145
|
+
api.set("accessTokenInfo", tokenInfo);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const getProjectInfoFromQuery = () => {
|
|
149
|
+
const preProject = JSON.parse(sessionStorage.getItem("projectInfo") || "{}");
|
|
150
|
+
const search = new URL(location.href).searchParams;
|
|
151
|
+
const id = search.get("project") || search.get("projectId") || "";
|
|
152
|
+
if (!id)
|
|
153
|
+
return;
|
|
154
|
+
const parentId = search.get("projectParent") || search.get("projectParentId") || preProject?.parentId || "";
|
|
155
|
+
const name = search.get("projectName") || preProject?.name || "";
|
|
156
|
+
sessionStorage.setItem("project", id);
|
|
157
|
+
sessionStorage.setItem("projectInfo", JSON.stringify({ ...preProject, id, name, parentId }));
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const isDev = import.meta.env.DEV;
|
|
161
|
+
const getToken = () => {
|
|
162
|
+
return api.get("accessToken") ?? "";
|
|
163
|
+
};
|
|
164
|
+
const getUserInfo = () => {
|
|
165
|
+
const config = getConfig();
|
|
166
|
+
const infoStrict = config?.infoStrict ?? true;
|
|
167
|
+
let info = tokenStorage().getData().info;
|
|
168
|
+
if (infoStrict) {
|
|
169
|
+
if (isDev && config.userInfo)
|
|
170
|
+
info = config.userInfo;
|
|
171
|
+
} else {
|
|
172
|
+
if (config.userInfo)
|
|
173
|
+
info = config.userInfo;
|
|
174
|
+
}
|
|
175
|
+
const userInfo = {
|
|
176
|
+
id: info.sub ?? "",
|
|
177
|
+
name: info.name ?? "",
|
|
178
|
+
flag: info.flag,
|
|
179
|
+
tenantId: info?.tenant ?? info?.tenantId ?? ""
|
|
180
|
+
};
|
|
181
|
+
return userInfo;
|
|
182
|
+
};
|
|
183
|
+
const getPersonalInfo = () => {
|
|
184
|
+
const config = getConfig();
|
|
185
|
+
const infoStrict = config?.infoStrict ?? true;
|
|
186
|
+
let info = JSON.parse(sessionStorage.getItem("userInfo") || "{}");
|
|
187
|
+
if (infoStrict) {
|
|
188
|
+
if (isDev && config.personalInfo)
|
|
189
|
+
info = config.personalInfo;
|
|
190
|
+
} else {
|
|
191
|
+
if (config.personalInfo)
|
|
192
|
+
info = config.personalInfo;
|
|
193
|
+
}
|
|
194
|
+
const personalInfo = {
|
|
195
|
+
id: info.id ?? "",
|
|
196
|
+
name: info.name ?? "",
|
|
197
|
+
phone: info.phone ?? "",
|
|
198
|
+
userName: info.userName ?? "",
|
|
199
|
+
email: info.email ?? "",
|
|
200
|
+
headPicture: info.headPicture ?? ""
|
|
201
|
+
};
|
|
202
|
+
return personalInfo;
|
|
203
|
+
};
|
|
204
|
+
const getTenantInfo = () => {
|
|
205
|
+
let info = JSON.parse(sessionStorage.getItem("tenantInfo") || "{}");
|
|
206
|
+
const tenantInfo = {
|
|
207
|
+
userId: info.id ?? "",
|
|
208
|
+
userName: info.userName ?? "",
|
|
209
|
+
name: info.name ?? "",
|
|
210
|
+
areaCode: info.areaCode ?? "",
|
|
211
|
+
phone: info.phone ?? "",
|
|
212
|
+
flag: info.flag ?? null,
|
|
213
|
+
tenant: info.tenant ?? {}
|
|
214
|
+
};
|
|
215
|
+
return tenantInfo;
|
|
216
|
+
};
|
|
217
|
+
const getProjectInfo = () => {
|
|
218
|
+
const config = getConfig();
|
|
219
|
+
const infoStrict = config?.infoStrict ?? true;
|
|
220
|
+
let info = JSON.parse(sessionStorage.getItem("projectInfo") || "{}");
|
|
221
|
+
if (infoStrict) {
|
|
222
|
+
if (isDev && config.projectInfo)
|
|
223
|
+
info = config.projectInfo;
|
|
224
|
+
} else {
|
|
225
|
+
if (config.projectInfo)
|
|
226
|
+
info = config.projectInfo;
|
|
227
|
+
}
|
|
228
|
+
const projectInfo = {
|
|
229
|
+
id: info?.id ?? "",
|
|
230
|
+
parentId: info?.parentId ?? "",
|
|
231
|
+
name: info?.name ?? "",
|
|
232
|
+
tenantId: info?.tenant ?? ""
|
|
233
|
+
};
|
|
234
|
+
return projectInfo;
|
|
235
|
+
};
|
|
236
|
+
const getPageAuth = (menuCode, applicationCode) => {
|
|
237
|
+
const KEY = "permission-btn";
|
|
238
|
+
const config = getConfig();
|
|
239
|
+
const subApps = getSubApps();
|
|
240
|
+
const urlApp = getUrlParams(location.href, "app") || "";
|
|
241
|
+
const realApplicationCode = applicationCode ? applicationCode : urlApp ? urlApp : window.__IN_MICRO_APP__ ? subApps.currentSubAppCode : config.title;
|
|
242
|
+
if (!realApplicationCode)
|
|
243
|
+
return void 0;
|
|
244
|
+
const urlMenu = getUrlParams(location.href, "menu") || "";
|
|
245
|
+
const realMenuCode = menuCode ? menuCode : urlMenu ? urlMenu : window.__IN_MICRO_APP__ ? subApps.currentSubApp.currentMenuCode : JSON.parse(sessionStorage.getItem(`${config.title}-tabs`) || "{}").currentTab.code;
|
|
246
|
+
const btnInfo = JSON.parse(sessionStorage.getItem(KEY) || "{}");
|
|
247
|
+
if (!btnInfo || JSON.stringify(btnInfo) === "{}")
|
|
248
|
+
return void 0;
|
|
249
|
+
const btnList = btnInfo[realApplicationCode][realMenuCode];
|
|
250
|
+
if (btnList && btnList.length)
|
|
251
|
+
return btnList;
|
|
252
|
+
if (!btnInfo[realApplicationCode]["origin-auth"])
|
|
253
|
+
return [];
|
|
254
|
+
return btnInfo[realApplicationCode]["origin-auth"][realMenuCode] ?? [];
|
|
255
|
+
};
|
|
256
|
+
const getPageAuthBtn = (menuCode, applicationCode) => {
|
|
257
|
+
const result = getPageAuth(menuCode, applicationCode);
|
|
258
|
+
return result ?? [];
|
|
259
|
+
};
|
|
260
|
+
const getSubApps = () => {
|
|
261
|
+
if (!window.__IN_MICRO_APP__)
|
|
262
|
+
return {};
|
|
263
|
+
const info = JSON.parse(sessionStorage.getItem("subApps") || "{}");
|
|
264
|
+
const flatSubAppList = info.appcategorys?.map((item) => item.apps).flat() ?? [];
|
|
265
|
+
const subApps = {
|
|
266
|
+
appcategorys: info.appcategorys ?? [],
|
|
267
|
+
currentSubApp: info.currentSubApp ?? {},
|
|
268
|
+
currentSubAppCode: info.currentSubAppCode ?? "",
|
|
269
|
+
flatSubAppList,
|
|
270
|
+
subAppList: info.subAppList ?? []
|
|
271
|
+
};
|
|
272
|
+
return subApps;
|
|
273
|
+
};
|
|
274
|
+
const getMenus = (appCode) => {
|
|
275
|
+
const info = JSON.parse(sessionStorage.getItem("menus") || "{}");
|
|
276
|
+
if (appCode) {
|
|
277
|
+
return info[appCode] ?? [];
|
|
278
|
+
} else {
|
|
279
|
+
return info;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const getTabInfo = () => {
|
|
283
|
+
const config = getConfig();
|
|
284
|
+
let result = {};
|
|
285
|
+
if (window.__IN_MICRO_APP__) {
|
|
286
|
+
const info = JSON.parse(sessionStorage.getItem("tabs") || "{}");
|
|
287
|
+
result = {
|
|
288
|
+
activeKey: info.activeKey ?? "",
|
|
289
|
+
currentTab: info.currentTab ?? {},
|
|
290
|
+
tabMap: info.tabMap ?? {}
|
|
291
|
+
};
|
|
292
|
+
} else {
|
|
293
|
+
const info = JSON.parse(sessionStorage.getItem(`${config.title}-tabs`) || "{}");
|
|
294
|
+
result = {
|
|
295
|
+
activeKey: info.activeKey ?? "",
|
|
296
|
+
currentTab: info.currentTab ?? {},
|
|
297
|
+
tabList: info.tabList ?? []
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return result;
|
|
301
|
+
};
|
|
302
|
+
const getMinioAddress = () => {
|
|
303
|
+
const config = getConfig();
|
|
304
|
+
const minioAddress = sessionStorage.getItem("minioAddress");
|
|
305
|
+
return minioAddress ? minioAddress : config.baseURL ? config.baseURL : location.origin;
|
|
306
|
+
};
|
|
307
|
+
if (!getToken())
|
|
308
|
+
getUrlToken();
|
|
309
|
+
getProjectInfoFromQuery();
|
|
310
|
+
|
|
311
|
+
export { getMenus, getMinioAddress, getPageAuth, getPageAuthBtn, getPersonalInfo, getProjectInfo, getSubApps, getTabInfo, getTenantInfo, getToken, getUserInfo };
|