@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,156 @@
|
|
|
1
|
+
/*! js-cookie v3.0.5 | MIT */
|
|
2
|
+
/* eslint-disable no-var */
|
|
3
|
+
function assign (target) {
|
|
4
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
5
|
+
var source = arguments[i];
|
|
6
|
+
for (var key in source) {
|
|
7
|
+
target[key] = source[key];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return target
|
|
11
|
+
}
|
|
12
|
+
/* eslint-enable no-var */
|
|
13
|
+
|
|
14
|
+
/* eslint-disable no-var */
|
|
15
|
+
var defaultConverter = {
|
|
16
|
+
read: function (value) {
|
|
17
|
+
if (value[0] === '"') {
|
|
18
|
+
value = value.slice(1, -1);
|
|
19
|
+
}
|
|
20
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
|
|
21
|
+
},
|
|
22
|
+
write: function (value) {
|
|
23
|
+
return encodeURIComponent(value).replace(
|
|
24
|
+
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
25
|
+
decodeURIComponent
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/* eslint-enable no-var */
|
|
30
|
+
|
|
31
|
+
/* eslint-disable no-var */
|
|
32
|
+
|
|
33
|
+
function init (converter, defaultAttributes) {
|
|
34
|
+
function set (name, value, attributes) {
|
|
35
|
+
if (typeof document === 'undefined') {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
attributes = assign({}, defaultAttributes, attributes);
|
|
40
|
+
|
|
41
|
+
if (typeof attributes.expires === 'number') {
|
|
42
|
+
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
43
|
+
}
|
|
44
|
+
if (attributes.expires) {
|
|
45
|
+
attributes.expires = attributes.expires.toUTCString();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
name = encodeURIComponent(name)
|
|
49
|
+
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
50
|
+
.replace(/[()]/g, escape);
|
|
51
|
+
|
|
52
|
+
var stringifiedAttributes = '';
|
|
53
|
+
for (var attributeName in attributes) {
|
|
54
|
+
if (!attributes[attributeName]) {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
59
|
+
|
|
60
|
+
if (attributes[attributeName] === true) {
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Considers RFC 6265 section 5.2:
|
|
65
|
+
// ...
|
|
66
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
67
|
+
// character:
|
|
68
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
69
|
+
// not including, the first %x3B (";") character.
|
|
70
|
+
// ...
|
|
71
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return (document.cookie =
|
|
75
|
+
name + '=' + converter.write(value, name) + stringifiedAttributes)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function get (name) {
|
|
79
|
+
if (typeof document === 'undefined' || (arguments.length && !name)) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// To prevent the for loop in the first place assign an empty array
|
|
84
|
+
// in case there are no cookies at all.
|
|
85
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
86
|
+
var jar = {};
|
|
87
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
88
|
+
var parts = cookies[i].split('=');
|
|
89
|
+
var value = parts.slice(1).join('=');
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
var found = decodeURIComponent(parts[0]);
|
|
93
|
+
jar[found] = converter.read(value, found);
|
|
94
|
+
|
|
95
|
+
if (name === found) {
|
|
96
|
+
break
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return name ? jar[name] : jar
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return Object.create(
|
|
105
|
+
{
|
|
106
|
+
set,
|
|
107
|
+
get,
|
|
108
|
+
remove: function (name, attributes) {
|
|
109
|
+
set(
|
|
110
|
+
name,
|
|
111
|
+
'',
|
|
112
|
+
assign({}, attributes, {
|
|
113
|
+
expires: -1
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
},
|
|
117
|
+
withAttributes: function (attributes) {
|
|
118
|
+
return init(this.converter, assign({}, this.attributes, attributes))
|
|
119
|
+
},
|
|
120
|
+
withConverter: function (converter) {
|
|
121
|
+
return init(assign({}, this.converter, converter), this.attributes)
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
attributes: { value: Object.freeze(defaultAttributes) },
|
|
126
|
+
converter: { value: Object.freeze(converter) }
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var api = init(defaultConverter, { path: '/' });
|
|
132
|
+
|
|
133
|
+
const getUrlToken = () => {
|
|
134
|
+
const search = new URL(location.href).searchParams;
|
|
135
|
+
const token = search.get("token") || search.get("accessToken") || search.get("accesstoken") || "";
|
|
136
|
+
if (token) {
|
|
137
|
+
const tokenInfo = JSON.stringify({ access_token: token });
|
|
138
|
+
sessionStorage.setItem("accessToken", token);
|
|
139
|
+
sessionStorage.setItem("tokenInfo", tokenInfo);
|
|
140
|
+
api.set("accessToken", token);
|
|
141
|
+
api.set("accessTokenInfo", tokenInfo);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const getProjectInfoFromQuery = () => {
|
|
145
|
+
const preProject = JSON.parse(sessionStorage.getItem("projectInfo") || "{}");
|
|
146
|
+
const search = new URL(location.href).searchParams;
|
|
147
|
+
const id = search.get("project") || search.get("projectId") || "";
|
|
148
|
+
if (!id)
|
|
149
|
+
return;
|
|
150
|
+
const parentId = search.get("projectParent") || search.get("projectParentId") || preProject?.parentId || "";
|
|
151
|
+
const name = search.get("projectName") || preProject?.name || "";
|
|
152
|
+
sessionStorage.setItem("project", id);
|
|
153
|
+
sessionStorage.setItem("projectInfo", JSON.stringify({ ...preProject, id, name, parentId }));
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export { getProjectInfoFromQuery, getUrlToken };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const arrEqual = (a, b, isSort = true) => {
|
|
2
|
+
if (a.length !== b.length)
|
|
3
|
+
return false;
|
|
4
|
+
if (isSort) {
|
|
5
|
+
return a.sort().toString() === b.sort().toString();
|
|
6
|
+
} else {
|
|
7
|
+
return a.toString() === b.toString();
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const arrUnique = (arr, val) => {
|
|
11
|
+
const res = /* @__PURE__ */ new Map();
|
|
12
|
+
return arr.filter((item) => !res.has(item[val]) && res.set(item[val], 1));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { arrEqual, arrUnique };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const dateFormat = (value, fmt = "yyyy-MM-dd HH:mm:ss") => {
|
|
2
|
+
let date = value ? new Date(value) : /* @__PURE__ */ new Date();
|
|
3
|
+
var o = {
|
|
4
|
+
"M+": date.getMonth() + 1,
|
|
5
|
+
"d+": date.getDate(),
|
|
6
|
+
"H+": date.getHours(),
|
|
7
|
+
"m+": date.getMinutes(),
|
|
8
|
+
"s+": date.getSeconds(),
|
|
9
|
+
"q+": Math.floor((date.getMonth() + 3) / 3),
|
|
10
|
+
S: date.getMilliseconds()
|
|
11
|
+
};
|
|
12
|
+
var year = date.getFullYear().toString();
|
|
13
|
+
year = year.length >= 4 ? year : "0000".substr(0, 4 - year.length) + year;
|
|
14
|
+
if (/(y+)/.test(fmt))
|
|
15
|
+
fmt = fmt.replace(RegExp.$1, (year + "").substr(4 - RegExp.$1.length));
|
|
16
|
+
for (var k in o)
|
|
17
|
+
if (new RegExp("(" + k + ")").test(fmt))
|
|
18
|
+
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
|
|
19
|
+
return fmt;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { dateFormat };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const getUrlParams = (allUrl, name) => {
|
|
2
|
+
let search = window.location.search || "";
|
|
3
|
+
if (allUrl && allUrl !== location.href) {
|
|
4
|
+
const index = allUrl.indexOf("?");
|
|
5
|
+
if (index !== -1) {
|
|
6
|
+
search = allUrl.slice(index);
|
|
7
|
+
} else {
|
|
8
|
+
search = "";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const params = new URLSearchParams(search);
|
|
12
|
+
if (name) {
|
|
13
|
+
return params.get(name);
|
|
14
|
+
} else {
|
|
15
|
+
let allParams = {};
|
|
16
|
+
for (let [key, value] of params.entries()) {
|
|
17
|
+
allParams[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return allParams;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const getFullPath = (url, params = {}) => {
|
|
23
|
+
let result = "";
|
|
24
|
+
let query = "";
|
|
25
|
+
const keys = Object.keys(params);
|
|
26
|
+
if (keys && keys.length) {
|
|
27
|
+
keys.forEach((key, index) => {
|
|
28
|
+
if (index === keys.length - 1) {
|
|
29
|
+
query += `${key}=${params[key]}`;
|
|
30
|
+
} else {
|
|
31
|
+
query += `${key}=${params[key]}&`;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (query) {
|
|
36
|
+
result = location.origin + url + `?${query}`;
|
|
37
|
+
} else {
|
|
38
|
+
result = location.origin + url;
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
const funcUrlDel = (names, url) => {
|
|
43
|
+
const preUrl = url ? url : location.href;
|
|
44
|
+
const params = getUrlParams(preUrl);
|
|
45
|
+
const keys = Object.keys(params) || [];
|
|
46
|
+
if (!keys || !keys.length)
|
|
47
|
+
return preUrl.includes("?") ? preUrl.split("?")[0] : preUrl.split("&")[0];
|
|
48
|
+
let paramsResult = keys.filter((item) => !names.includes(item));
|
|
49
|
+
if (!paramsResult || !paramsResult.length)
|
|
50
|
+
return preUrl.includes("?") ? preUrl.split("?")[0] : preUrl.split("&")[0];
|
|
51
|
+
let query = "";
|
|
52
|
+
paramsResult.forEach((key, index) => {
|
|
53
|
+
if (index === keys.length - 1) {
|
|
54
|
+
query += `${key}=${params[key]}`;
|
|
55
|
+
} else {
|
|
56
|
+
query += `${key}=${params[key]}&`;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return preUrl.includes("?") ? preUrl.split("?")[0] + `?${query}` : preUrl.split("&")[0] + `?${query}`;
|
|
60
|
+
};
|
|
61
|
+
const urlParamsToObject = (url) => {
|
|
62
|
+
const searchParams = new URLSearchParams(url.split("?")[1]);
|
|
63
|
+
const params = {};
|
|
64
|
+
for (const [key, value] of searchParams) {
|
|
65
|
+
if (params.hasOwnProperty(key)) {
|
|
66
|
+
if (Array.isArray(params[key])) {
|
|
67
|
+
params[key].push(value);
|
|
68
|
+
} else {
|
|
69
|
+
params[key] = [params[key], value];
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
params[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return params;
|
|
76
|
+
};
|
|
77
|
+
const objectToUrlparams = (params) => {
|
|
78
|
+
let query = "";
|
|
79
|
+
const keys = Object.keys(params);
|
|
80
|
+
if (keys && keys.length) {
|
|
81
|
+
keys.forEach((key, index) => {
|
|
82
|
+
if (index === keys.length - 1) {
|
|
83
|
+
query += `${key}=${params[key]}`;
|
|
84
|
+
} else {
|
|
85
|
+
query += `${key}=${params[key]}&`;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return query;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export { funcUrlDel, getFullPath, getUrlParams, objectToUrlparams, urlParamsToObject };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
const dateFormat = (value, fmt = "yyyy-MM-dd HH:mm:ss") => {
|
|
2
|
+
let date = value ? new Date(value) : /* @__PURE__ */ new Date();
|
|
3
|
+
var o = {
|
|
4
|
+
"M+": date.getMonth() + 1,
|
|
5
|
+
"d+": date.getDate(),
|
|
6
|
+
"H+": date.getHours(),
|
|
7
|
+
"m+": date.getMinutes(),
|
|
8
|
+
"s+": date.getSeconds(),
|
|
9
|
+
"q+": Math.floor((date.getMonth() + 3) / 3),
|
|
10
|
+
S: date.getMilliseconds()
|
|
11
|
+
};
|
|
12
|
+
var year = date.getFullYear().toString();
|
|
13
|
+
year = year.length >= 4 ? year : "0000".substr(0, 4 - year.length) + year;
|
|
14
|
+
if (/(y+)/.test(fmt))
|
|
15
|
+
fmt = fmt.replace(RegExp.$1, (year + "").substr(4 - RegExp.$1.length));
|
|
16
|
+
for (var k in o)
|
|
17
|
+
if (new RegExp("(" + k + ")").test(fmt))
|
|
18
|
+
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
|
|
19
|
+
return fmt;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getUrlParams = (allUrl, name) => {
|
|
23
|
+
let search = window.location.search || "";
|
|
24
|
+
if (allUrl && allUrl !== location.href) {
|
|
25
|
+
const index = allUrl.indexOf("?");
|
|
26
|
+
if (index !== -1) {
|
|
27
|
+
search = allUrl.slice(index);
|
|
28
|
+
} else {
|
|
29
|
+
search = "";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const params = new URLSearchParams(search);
|
|
33
|
+
if (name) {
|
|
34
|
+
return params.get(name);
|
|
35
|
+
} else {
|
|
36
|
+
let allParams = {};
|
|
37
|
+
for (let [key, value] of params.entries()) {
|
|
38
|
+
allParams[key] = value;
|
|
39
|
+
}
|
|
40
|
+
return allParams;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const getFullPath = (url, params = {}) => {
|
|
44
|
+
let result = "";
|
|
45
|
+
let query = "";
|
|
46
|
+
const keys = Object.keys(params);
|
|
47
|
+
if (keys && keys.length) {
|
|
48
|
+
keys.forEach((key, index) => {
|
|
49
|
+
if (index === keys.length - 1) {
|
|
50
|
+
query += `${key}=${params[key]}`;
|
|
51
|
+
} else {
|
|
52
|
+
query += `${key}=${params[key]}&`;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (query) {
|
|
57
|
+
result = location.origin + url + `?${query}`;
|
|
58
|
+
} else {
|
|
59
|
+
result = location.origin + url;
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
const funcUrlDel = (names, url) => {
|
|
64
|
+
const preUrl = url ? url : location.href;
|
|
65
|
+
const params = getUrlParams(preUrl);
|
|
66
|
+
const keys = Object.keys(params) || [];
|
|
67
|
+
if (!keys || !keys.length)
|
|
68
|
+
return preUrl.includes("?") ? preUrl.split("?")[0] : preUrl.split("&")[0];
|
|
69
|
+
let paramsResult = keys.filter((item) => !names.includes(item));
|
|
70
|
+
if (!paramsResult || !paramsResult.length)
|
|
71
|
+
return preUrl.includes("?") ? preUrl.split("?")[0] : preUrl.split("&")[0];
|
|
72
|
+
let query = "";
|
|
73
|
+
paramsResult.forEach((key, index) => {
|
|
74
|
+
if (index === keys.length - 1) {
|
|
75
|
+
query += `${key}=${params[key]}`;
|
|
76
|
+
} else {
|
|
77
|
+
query += `${key}=${params[key]}&`;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return preUrl.includes("?") ? preUrl.split("?")[0] + `?${query}` : preUrl.split("&")[0] + `?${query}`;
|
|
81
|
+
};
|
|
82
|
+
const urlParamsToObject = (url) => {
|
|
83
|
+
const searchParams = new URLSearchParams(url.split("?")[1]);
|
|
84
|
+
const params = {};
|
|
85
|
+
for (const [key, value] of searchParams) {
|
|
86
|
+
if (params.hasOwnProperty(key)) {
|
|
87
|
+
if (Array.isArray(params[key])) {
|
|
88
|
+
params[key].push(value);
|
|
89
|
+
} else {
|
|
90
|
+
params[key] = [params[key], value];
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
params[key] = value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return params;
|
|
97
|
+
};
|
|
98
|
+
const objectToUrlparams = (params) => {
|
|
99
|
+
let query = "";
|
|
100
|
+
const keys = Object.keys(params);
|
|
101
|
+
if (keys && keys.length) {
|
|
102
|
+
keys.forEach((key, index) => {
|
|
103
|
+
if (index === keys.length - 1) {
|
|
104
|
+
query += `${key}=${params[key]}`;
|
|
105
|
+
} else {
|
|
106
|
+
query += `${key}=${params[key]}&`;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return query;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const findNonEmptyChildrenItems = (arr, children = "children") => {
|
|
114
|
+
let result = [];
|
|
115
|
+
for (let i = 0; i < arr.length; i++) {
|
|
116
|
+
if (arr[i][children] && arr[i][children].length > 0) {
|
|
117
|
+
result.push(arr[i]);
|
|
118
|
+
result = result.concat(findNonEmptyChildrenItems(arr[i][children]));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
const flatTree = (list, child = "children", deleteChild = true) => {
|
|
124
|
+
if (Array.isArray(list) && list.length) {
|
|
125
|
+
return list.reduce((ls, item) => {
|
|
126
|
+
let children = item[child];
|
|
127
|
+
let res = { ...item };
|
|
128
|
+
if (deleteChild) {
|
|
129
|
+
delete res[child];
|
|
130
|
+
}
|
|
131
|
+
if (children && children.length) {
|
|
132
|
+
return ls.concat(res, flatTree(children, child, deleteChild));
|
|
133
|
+
} else {
|
|
134
|
+
return ls.concat(res);
|
|
135
|
+
}
|
|
136
|
+
}, []);
|
|
137
|
+
} else {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const filterTreeArray = (tree, predicate, children = "children") => {
|
|
142
|
+
return tree.filter((item) => {
|
|
143
|
+
return predicate(item);
|
|
144
|
+
}).map((item) => {
|
|
145
|
+
item = Object.assign({}, item);
|
|
146
|
+
if (item[children]) {
|
|
147
|
+
item[children] = filterTreeArray(item[children], predicate);
|
|
148
|
+
}
|
|
149
|
+
return item;
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const treeFind = (tree, func) => {
|
|
153
|
+
for (const data of tree) {
|
|
154
|
+
if (func(data))
|
|
155
|
+
return data;
|
|
156
|
+
if (data?.children && data.children.length) {
|
|
157
|
+
const res = treeFind(data.children, func);
|
|
158
|
+
if (res)
|
|
159
|
+
return res;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const objEqual = (a, b) => {
|
|
166
|
+
if (!a || !b)
|
|
167
|
+
return false;
|
|
168
|
+
if (Object.keys(a).length !== Object.keys(b).length)
|
|
169
|
+
return false;
|
|
170
|
+
for (let key in a) {
|
|
171
|
+
if (b[key] === void 0)
|
|
172
|
+
return false;
|
|
173
|
+
if (typeof b[key] === "function" || typeof a[key] === "function")
|
|
174
|
+
throw new Error("type error");
|
|
175
|
+
if (typeof b[key] != typeof a[key])
|
|
176
|
+
return false;
|
|
177
|
+
if (typeof a[key] === "object")
|
|
178
|
+
return objEqual(a[key], b[key]);
|
|
179
|
+
if (a[key] !== b[key])
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const arrEqual = (a, b, isSort = true) => {
|
|
186
|
+
if (a.length !== b.length)
|
|
187
|
+
return false;
|
|
188
|
+
if (isSort) {
|
|
189
|
+
return a.sort().toString() === b.sort().toString();
|
|
190
|
+
} else {
|
|
191
|
+
return a.toString() === b.toString();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const arrUnique = (arr, val) => {
|
|
195
|
+
const res = /* @__PURE__ */ new Map();
|
|
196
|
+
return arr.filter((item) => !res.has(item[val]) && res.set(item[val], 1));
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const isEmpty = (value) => {
|
|
200
|
+
return !!(value === null || typeof value === "undefined" || value === "");
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const setHtmlMinWH = (layout) => {
|
|
204
|
+
let minWidth = "", minHeight = "";
|
|
205
|
+
if (layout?.minWidth)
|
|
206
|
+
minWidth = layout.minWidth;
|
|
207
|
+
if (layout?.minHeight)
|
|
208
|
+
minHeight = layout.minHeight;
|
|
209
|
+
document.documentElement.style.minWidth = minWidth;
|
|
210
|
+
document.documentElement.style.minHeight = minHeight;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export { arrEqual, arrUnique, dateFormat, filterTreeArray, findNonEmptyChildrenItems, flatTree, funcUrlDel, getFullPath, getUrlParams, isEmpty, objEqual, objectToUrlparams, setHtmlMinWH, treeFind, urlParamsToObject };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const findNonEmptyChildrenItems = (arr, children = "children") => {
|
|
2
|
+
let result = [];
|
|
3
|
+
for (let i = 0; i < arr.length; i++) {
|
|
4
|
+
if (arr[i][children] && arr[i][children].length > 0) {
|
|
5
|
+
result.push(arr[i]);
|
|
6
|
+
result = result.concat(findNonEmptyChildrenItems(arr[i][children]));
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
const flatTree = (list, child = "children", deleteChild = true) => {
|
|
12
|
+
if (Array.isArray(list) && list.length) {
|
|
13
|
+
return list.reduce((ls, item) => {
|
|
14
|
+
let children = item[child];
|
|
15
|
+
let res = { ...item };
|
|
16
|
+
if (deleteChild) {
|
|
17
|
+
delete res[child];
|
|
18
|
+
}
|
|
19
|
+
if (children && children.length) {
|
|
20
|
+
return ls.concat(res, flatTree(children, child, deleteChild));
|
|
21
|
+
} else {
|
|
22
|
+
return ls.concat(res);
|
|
23
|
+
}
|
|
24
|
+
}, []);
|
|
25
|
+
} else {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const filterTreeArray = (tree, predicate, children = "children") => {
|
|
30
|
+
return tree.filter((item) => {
|
|
31
|
+
return predicate(item);
|
|
32
|
+
}).map((item) => {
|
|
33
|
+
item = Object.assign({}, item);
|
|
34
|
+
if (item[children]) {
|
|
35
|
+
item[children] = filterTreeArray(item[children], predicate);
|
|
36
|
+
}
|
|
37
|
+
return item;
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const treeFind = (tree, func) => {
|
|
41
|
+
for (const data of tree) {
|
|
42
|
+
if (func(data))
|
|
43
|
+
return data;
|
|
44
|
+
if (data?.children && data.children.length) {
|
|
45
|
+
const res = treeFind(data.children, func);
|
|
46
|
+
if (res)
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { filterTreeArray, findNonEmptyChildrenItems, flatTree, treeFind };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const objEqual = (a, b) => {
|
|
2
|
+
if (!a || !b)
|
|
3
|
+
return false;
|
|
4
|
+
if (Object.keys(a).length !== Object.keys(b).length)
|
|
5
|
+
return false;
|
|
6
|
+
for (let key in a) {
|
|
7
|
+
if (b[key] === void 0)
|
|
8
|
+
return false;
|
|
9
|
+
if (typeof b[key] === "function" || typeof a[key] === "function")
|
|
10
|
+
throw new Error("type error");
|
|
11
|
+
if (typeof b[key] != typeof a[key])
|
|
12
|
+
return false;
|
|
13
|
+
if (typeof a[key] === "object")
|
|
14
|
+
return objEqual(a[key], b[key]);
|
|
15
|
+
if (a[key] !== b[key])
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { objEqual };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const setHtmlMinWH = (layout) => {
|
|
2
|
+
let minWidth = "", minHeight = "";
|
|
3
|
+
if (layout?.minWidth)
|
|
4
|
+
minWidth = layout.minWidth;
|
|
5
|
+
if (layout?.minHeight)
|
|
6
|
+
minHeight = layout.minHeight;
|
|
7
|
+
document.documentElement.style.minWidth = minWidth;
|
|
8
|
+
document.documentElement.style.minHeight = minHeight;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { setHtmlMinWH };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function throttled(fn, delay = 300) {
|
|
2
|
+
let timer = null;
|
|
3
|
+
let starttime = Date.now();
|
|
4
|
+
return function() {
|
|
5
|
+
let curTime = Date.now();
|
|
6
|
+
let remaining = delay - (curTime - starttime);
|
|
7
|
+
let context = this;
|
|
8
|
+
let args = arguments;
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
if (remaining <= 0) {
|
|
11
|
+
fn.apply(context, args);
|
|
12
|
+
starttime = Date.now();
|
|
13
|
+
} else {
|
|
14
|
+
timer = setTimeout(fn, remaining);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { throttled };
|
package/config/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const getConfig = () => {
|
|
2
|
+
let windowConfig = window?.config || {};
|
|
3
|
+
let config = { ...windowConfig };
|
|
4
|
+
if (!config.rootContainer)
|
|
5
|
+
config.rootContainer = "#app";
|
|
6
|
+
if (!config.baseURL)
|
|
7
|
+
config.baseURL = location.origin;
|
|
8
|
+
if (!config.ossBaseURL)
|
|
9
|
+
config.ossBaseURL = "/oss";
|
|
10
|
+
if (config.ossBaseURL.startsWith("/"))
|
|
11
|
+
config.ossBaseURL = `${config.baseURL}/oss`;
|
|
12
|
+
if (!config.ssoBaseURL)
|
|
13
|
+
config.ssoBaseURL = config.baseURL;
|
|
14
|
+
let { microAppName, publicPath, mainAppName } = config;
|
|
15
|
+
const isPro = import.meta.env.PROD;
|
|
16
|
+
if (microAppName && isPro && !publicPath)
|
|
17
|
+
publicPath = `/${microAppName}/`.replace(/\/\//g, "/");
|
|
18
|
+
if (!publicPath)
|
|
19
|
+
publicPath = "/";
|
|
20
|
+
config.publicPath = publicPath;
|
|
21
|
+
if (!config.autoOssBucket)
|
|
22
|
+
config.autoOssBucket = mainAppName || microAppName;
|
|
23
|
+
return config;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { getConfig };
|