@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,12 @@
|
|
|
1
|
+
const setProcessEngineToken = (data) => {
|
|
2
|
+
sessionStorage.setItem("hotentToken", data.accessToken || "");
|
|
3
|
+
sessionStorage.setItem("currentUser", JSON.stringify({ token: data.accessToken || "" }));
|
|
4
|
+
if (data.info && JSON.stringify(data.info) !== "{}") {
|
|
5
|
+
sessionStorage.setItem("hotentUserInfo", JSON.stringify({ id: data.info?.sub ?? "", name: data.info?.name ?? "", flag: data.info?.flag, tenantId: data.info?.tenant ?? "" }));
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
const setProcessEngineProject = (projectId) => {
|
|
9
|
+
sessionStorage.setItem("project", projectId);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { setProcessEngineProject, setProcessEngineToken };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const PREFIX = "oss";
|
|
2
|
+
const handle1 = (url) => {
|
|
3
|
+
if (url.indexOf(`/${PREFIX}/`) === 0)
|
|
4
|
+
return url;
|
|
5
|
+
return null;
|
|
6
|
+
};
|
|
7
|
+
const handle2 = (url) => {
|
|
8
|
+
if (url.indexOf("/") === 0)
|
|
9
|
+
return `/${PREFIX}${url}`;
|
|
10
|
+
return null;
|
|
11
|
+
};
|
|
12
|
+
const handle3 = (url) => {
|
|
13
|
+
if (url.indexOf(`${PREFIX}/`) === 0)
|
|
14
|
+
return `/${url}`;
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
const handle4 = (url) => {
|
|
18
|
+
return `/${PREFIX}/${url}`;
|
|
19
|
+
};
|
|
20
|
+
const createHandlerChain = (...handlers) => {
|
|
21
|
+
return (url) => handlers.reduce((result, handler) => result !== null ? result : handler(url), null);
|
|
22
|
+
};
|
|
23
|
+
const handlerChain = createHandlerChain(handle1, handle2, handle3, handle4);
|
|
24
|
+
const pureImageSrc = (url) => {
|
|
25
|
+
if (!url)
|
|
26
|
+
return "";
|
|
27
|
+
return handlerChain(url);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { pureImageSrc };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getProjectInfo } from '@das-fed/utils/common-info';
|
|
3
|
+
import { getConfig } from '@das-fed/utils/config';
|
|
4
|
+
|
|
5
|
+
const apis = {
|
|
6
|
+
personalInfo: "/api/personal-center/personal-server/v1/info"
|
|
7
|
+
};
|
|
8
|
+
const setPersonalInfo = async (token) => {
|
|
9
|
+
const res = await axios.create().get(apis.personalInfo, {
|
|
10
|
+
baseURL: getConfig().baseURL,
|
|
11
|
+
params: {
|
|
12
|
+
project: getProjectInfo()?.id || "",
|
|
13
|
+
timestamp: (/* @__PURE__ */ new Date()).getTime()
|
|
14
|
+
},
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: `Bearer ${token}`
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (res?.data) {
|
|
20
|
+
sessionStorage.setItem("userInfo", JSON.stringify(res.data));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { setPersonalInfo };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ref, onMounted } from 'vue';
|
|
2
|
+
|
|
3
|
+
const SizeWatcher = (cb, dom) => {
|
|
4
|
+
const watchDom = dom || document.documentElement;
|
|
5
|
+
const objResizeObserver = new ResizeObserver((entries) => {
|
|
6
|
+
const entry = entries[0];
|
|
7
|
+
cb(entry.contentRect);
|
|
8
|
+
});
|
|
9
|
+
if (dom !== null)
|
|
10
|
+
objResizeObserver.observe(watchDom);
|
|
11
|
+
return objResizeObserver;
|
|
12
|
+
};
|
|
13
|
+
const useSizeWatcher = () => {
|
|
14
|
+
const el = ref(null);
|
|
15
|
+
const rect = ref({ bottom: 0, height: 0, left: 0, right: 0, top: 0, width: 0, x: 0, y: 0, toJSON: () => {
|
|
16
|
+
} });
|
|
17
|
+
onMounted(() => {
|
|
18
|
+
SizeWatcher((val) => {
|
|
19
|
+
rect.value = val;
|
|
20
|
+
}, el.value);
|
|
21
|
+
if (!el.value)
|
|
22
|
+
return;
|
|
23
|
+
});
|
|
24
|
+
return { el, rect };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { SizeWatcher, useSizeWatcher };
|
package/style/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vue/shared v3.4.21
|
|
3
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
|
|
7
|
+
!!(process.env.NODE_ENV !== "production") ? Object.freeze({}) : {};
|
|
8
|
+
!!(process.env.NODE_ENV !== "production") ? Object.freeze([]) : [];
|
|
9
|
+
const cacheStringFunction = (fn) => {
|
|
10
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
11
|
+
return (str) => {
|
|
12
|
+
const hit = cache[str];
|
|
13
|
+
return hit || (cache[str] = fn(str));
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const camelizeRE = /-(\w)/g;
|
|
17
|
+
const camelize = cacheStringFunction((str) => {
|
|
18
|
+
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const classNameToArray = (cls = "") => cls.split(" ").filter((item) => !!item.trim());
|
|
22
|
+
const hasClass = (el, cls) => {
|
|
23
|
+
if (!el || !cls)
|
|
24
|
+
return false;
|
|
25
|
+
if (cls.includes(" "))
|
|
26
|
+
throw new Error("className should not contain space.");
|
|
27
|
+
return el.classList.contains(cls);
|
|
28
|
+
};
|
|
29
|
+
const addClass = (el, cls) => {
|
|
30
|
+
if (!el || !cls.trim())
|
|
31
|
+
return;
|
|
32
|
+
el.classList.add(...classNameToArray(cls));
|
|
33
|
+
};
|
|
34
|
+
const removeClass = (el, cls) => {
|
|
35
|
+
if (!el || !cls.trim())
|
|
36
|
+
return;
|
|
37
|
+
el.classList.remove(...classNameToArray(cls));
|
|
38
|
+
};
|
|
39
|
+
const getStyle = (element, styleName) => {
|
|
40
|
+
if (!element || !styleName)
|
|
41
|
+
return "";
|
|
42
|
+
let key = camelize(styleName);
|
|
43
|
+
if (key === "float")
|
|
44
|
+
key = "cssFloat";
|
|
45
|
+
try {
|
|
46
|
+
const style = element.style[key];
|
|
47
|
+
if (style)
|
|
48
|
+
return style;
|
|
49
|
+
const computed = window?.getComputedStyle(element, "");
|
|
50
|
+
return computed ? computed[key] : "";
|
|
51
|
+
} catch {
|
|
52
|
+
return element.style[key];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const getCSS = (styleObj = {}) => {
|
|
56
|
+
return Object.keys(styleObj).map((key) => `${key}:${styleObj[key] !== "" ? styleObj[key] : '""'}`).join(";");
|
|
57
|
+
};
|
|
58
|
+
const createStyle = (id, data) => {
|
|
59
|
+
if (document.getElementById(id))
|
|
60
|
+
return;
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const styleSheet = document.createElement("style");
|
|
63
|
+
styleSheet.rel = "text/css";
|
|
64
|
+
styleSheet.id = id;
|
|
65
|
+
for (const item of data) {
|
|
66
|
+
styleSheet.appendChild(document.createTextNode(`${item.className}{${getCSS(item.style)}}`));
|
|
67
|
+
}
|
|
68
|
+
const head = document.getElementsByTagName("head")[0];
|
|
69
|
+
head.appendChild(styleSheet);
|
|
70
|
+
styleSheet.onload = () => resolve("load success");
|
|
71
|
+
styleSheet.onerror = () => reject("load error");
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const updateStyle = (id, data) => {
|
|
75
|
+
const styleSheet = document.getElementById(id);
|
|
76
|
+
if (styleSheet) {
|
|
77
|
+
styleSheet.innerHTML = "";
|
|
78
|
+
for (const item of data) {
|
|
79
|
+
styleSheet.appendChild(document.createTextNode(`${item.className}{${getCSS(item.style)}}`));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const px2number = (str) => Number(str.toString().replace("px", ""));
|
|
85
|
+
const operation = (type, a, b) => {
|
|
86
|
+
a = px2number(a);
|
|
87
|
+
b = px2number(b);
|
|
88
|
+
let res;
|
|
89
|
+
if (type === "add")
|
|
90
|
+
res = a + b;
|
|
91
|
+
if (type === "subtract")
|
|
92
|
+
res = a - b;
|
|
93
|
+
if (type === "multiply")
|
|
94
|
+
res = a * b;
|
|
95
|
+
if (type === "divide")
|
|
96
|
+
res = a / b;
|
|
97
|
+
a = null;
|
|
98
|
+
b = null;
|
|
99
|
+
return res;
|
|
100
|
+
};
|
|
101
|
+
const curringMath = (a) => {
|
|
102
|
+
return {
|
|
103
|
+
add: (b) => curringMath(operation("add", a, b)),
|
|
104
|
+
subtract: (b) => curringMath(operation("subtract", a, b)),
|
|
105
|
+
multiply: (b) => curringMath(operation("multiply", a, b)),
|
|
106
|
+
divide: (b) => curringMath(operation("divide", a, b)),
|
|
107
|
+
res: () => {
|
|
108
|
+
const res = a + "px";
|
|
109
|
+
a = null;
|
|
110
|
+
return res;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export { addClass, createStyle, curringMath, getCSS, getStyle, hasClass, removeClass, updateStyle };
|
package/style/math.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const px2number = (str) => Number(str.toString().replace("px", ""));
|
|
2
|
+
const operation = (type, a, b) => {
|
|
3
|
+
a = px2number(a);
|
|
4
|
+
b = px2number(b);
|
|
5
|
+
let res;
|
|
6
|
+
if (type === "add")
|
|
7
|
+
res = a + b;
|
|
8
|
+
if (type === "subtract")
|
|
9
|
+
res = a - b;
|
|
10
|
+
if (type === "multiply")
|
|
11
|
+
res = a * b;
|
|
12
|
+
if (type === "divide")
|
|
13
|
+
res = a / b;
|
|
14
|
+
a = null;
|
|
15
|
+
b = null;
|
|
16
|
+
return res;
|
|
17
|
+
};
|
|
18
|
+
const curringMath = (a) => {
|
|
19
|
+
return {
|
|
20
|
+
add: (b) => curringMath(operation("add", a, b)),
|
|
21
|
+
subtract: (b) => curringMath(operation("subtract", a, b)),
|
|
22
|
+
multiply: (b) => curringMath(operation("multiply", a, b)),
|
|
23
|
+
divide: (b) => curringMath(operation("divide", a, b)),
|
|
24
|
+
res: () => {
|
|
25
|
+
const res = a + "px";
|
|
26
|
+
a = null;
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { curringMath };
|
package/style/style.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vue/shared v3.4.21
|
|
3
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
|
|
7
|
+
!!(process.env.NODE_ENV !== "production") ? Object.freeze({}) : {};
|
|
8
|
+
!!(process.env.NODE_ENV !== "production") ? Object.freeze([]) : [];
|
|
9
|
+
const cacheStringFunction = (fn) => {
|
|
10
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
11
|
+
return (str) => {
|
|
12
|
+
const hit = cache[str];
|
|
13
|
+
return hit || (cache[str] = fn(str));
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const camelizeRE = /-(\w)/g;
|
|
17
|
+
const camelize = cacheStringFunction((str) => {
|
|
18
|
+
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const classNameToArray = (cls = "") => cls.split(" ").filter((item) => !!item.trim());
|
|
22
|
+
const hasClass = (el, cls) => {
|
|
23
|
+
if (!el || !cls)
|
|
24
|
+
return false;
|
|
25
|
+
if (cls.includes(" "))
|
|
26
|
+
throw new Error("className should not contain space.");
|
|
27
|
+
return el.classList.contains(cls);
|
|
28
|
+
};
|
|
29
|
+
const addClass = (el, cls) => {
|
|
30
|
+
if (!el || !cls.trim())
|
|
31
|
+
return;
|
|
32
|
+
el.classList.add(...classNameToArray(cls));
|
|
33
|
+
};
|
|
34
|
+
const removeClass = (el, cls) => {
|
|
35
|
+
if (!el || !cls.trim())
|
|
36
|
+
return;
|
|
37
|
+
el.classList.remove(...classNameToArray(cls));
|
|
38
|
+
};
|
|
39
|
+
const getStyle = (element, styleName) => {
|
|
40
|
+
if (!element || !styleName)
|
|
41
|
+
return "";
|
|
42
|
+
let key = camelize(styleName);
|
|
43
|
+
if (key === "float")
|
|
44
|
+
key = "cssFloat";
|
|
45
|
+
try {
|
|
46
|
+
const style = element.style[key];
|
|
47
|
+
if (style)
|
|
48
|
+
return style;
|
|
49
|
+
const computed = window?.getComputedStyle(element, "");
|
|
50
|
+
return computed ? computed[key] : "";
|
|
51
|
+
} catch {
|
|
52
|
+
return element.style[key];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const getCSS = (styleObj = {}) => {
|
|
56
|
+
return Object.keys(styleObj).map((key) => `${key}:${styleObj[key] !== "" ? styleObj[key] : '""'}`).join(";");
|
|
57
|
+
};
|
|
58
|
+
const createStyle = (id, data) => {
|
|
59
|
+
if (document.getElementById(id))
|
|
60
|
+
return;
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const styleSheet = document.createElement("style");
|
|
63
|
+
styleSheet.rel = "text/css";
|
|
64
|
+
styleSheet.id = id;
|
|
65
|
+
for (const item of data) {
|
|
66
|
+
styleSheet.appendChild(document.createTextNode(`${item.className}{${getCSS(item.style)}}`));
|
|
67
|
+
}
|
|
68
|
+
const head = document.getElementsByTagName("head")[0];
|
|
69
|
+
head.appendChild(styleSheet);
|
|
70
|
+
styleSheet.onload = () => resolve("load success");
|
|
71
|
+
styleSheet.onerror = () => reject("load error");
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const updateStyle = (id, data) => {
|
|
75
|
+
const styleSheet = document.getElementById(id);
|
|
76
|
+
if (styleSheet) {
|
|
77
|
+
styleSheet.innerHTML = "";
|
|
78
|
+
for (const item of data) {
|
|
79
|
+
styleSheet.appendChild(document.createTextNode(`${item.className}{${getCSS(item.style)}}`));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { addClass, classNameToArray, createStyle, getCSS, getStyle, hasClass, removeClass, updateStyle };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { tokenStorage } from '@das-fed/utils/api-services/src/sso';
|
|
2
|
+
import { setProcessEngineToken } from '@das-fed/utils/process-engine-info';
|
|
3
|
+
import { setPersonalInfo } from '@das-fed/utils/set-personal-info';
|
|
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 KEY = "accessToken", INFOKEY = "accessTokenInfo";
|
|
138
|
+
const getAccessToken = () => {
|
|
139
|
+
const cookieToken = api.get(KEY) ?? "";
|
|
140
|
+
let sessionToken = "";
|
|
141
|
+
if (tokenStorage().getData()?.info && JSON.stringify(tokenStorage().getData()?.info) !== "{}") {
|
|
142
|
+
sessionToken = tokenStorage().getData()?.info?.access_token ?? tokenStorage().getData()?.info?.accessToken ?? "";
|
|
143
|
+
}
|
|
144
|
+
if (cookieToken && !sessionToken) {
|
|
145
|
+
const cookieTokenInfo = getAccessTokenInfo();
|
|
146
|
+
if (cookieTokenInfo && JSON.stringify(cookieTokenInfo) !== "{}") {
|
|
147
|
+
const { access_token, refresh_token, expires_in } = cookieTokenInfo;
|
|
148
|
+
const tokenData = {
|
|
149
|
+
accessToken: access_token,
|
|
150
|
+
accessTokenExpiredAt: +/* @__PURE__ */ new Date() + expires_in * 1e3,
|
|
151
|
+
refreshToken: refresh_token,
|
|
152
|
+
info: cookieTokenInfo
|
|
153
|
+
};
|
|
154
|
+
tokenStorage().save(tokenData);
|
|
155
|
+
setPersonalInfo(access_token);
|
|
156
|
+
setProcessEngineToken(tokenData);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return api.get(KEY) ?? tokenStorage().getData()?.accessToken ?? "";
|
|
160
|
+
};
|
|
161
|
+
const getAccessTokenInfo = () => {
|
|
162
|
+
if (api.get(INFOKEY)) {
|
|
163
|
+
return JSON.parse(api.get(INFOKEY));
|
|
164
|
+
} else {
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const setAccessToken = (token, info) => {
|
|
169
|
+
api.set(KEY, token);
|
|
170
|
+
if (info)
|
|
171
|
+
api.set(INFOKEY, JSON.stringify(info));
|
|
172
|
+
};
|
|
173
|
+
const removeAccessToken = () => {
|
|
174
|
+
api.remove(KEY);
|
|
175
|
+
if (api.get(INFOKEY))
|
|
176
|
+
api.remove(INFOKEY);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export { getAccessToken, getAccessTokenInfo, removeAccessToken, setAccessToken };
|
package/vue/index.js
ADDED