@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,114 @@
|
|
|
1
|
+
import { getUrlParams, flatTree } from '@das-fed/utils/common-tools';
|
|
2
|
+
import { getTabInfo, getSubApps, getPageAuth } from '@das-fed/utils/common-info';
|
|
3
|
+
|
|
4
|
+
const getEl = async (el, options) => {
|
|
5
|
+
let res = el;
|
|
6
|
+
if (options?.target) {
|
|
7
|
+
if (typeof options.target === "string")
|
|
8
|
+
res = options.target;
|
|
9
|
+
if (typeof options.target === "function")
|
|
10
|
+
res = await options.target(el);
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const hasBtnAuth = (btnList, code) => {
|
|
16
|
+
if (!btnList || !code)
|
|
17
|
+
return false;
|
|
18
|
+
if (typeof code === "string") {
|
|
19
|
+
const currentItem = btnList.find((item) => item.code === code);
|
|
20
|
+
return !!currentItem;
|
|
21
|
+
} else {
|
|
22
|
+
let flag = false;
|
|
23
|
+
for (let value of code) {
|
|
24
|
+
const currentItem = btnList.find((item) => item.code === value);
|
|
25
|
+
if (currentItem) {
|
|
26
|
+
flag = true;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return flag;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const hasPermission = (options) => {
|
|
34
|
+
const code = options?.code ?? "";
|
|
35
|
+
const path = options?.path ?? location.pathname;
|
|
36
|
+
const applicationCode = options?.applicationCode ?? "";
|
|
37
|
+
let menuCode = "";
|
|
38
|
+
if (window.__IN_MICRO_APP__) {
|
|
39
|
+
menuCode = options?.menuCode ? options.menuCode : getUrlParams(location.href, "menu");
|
|
40
|
+
} else {
|
|
41
|
+
menuCode = options?.menuCode ? options.menuCode : getTabInfo().currentTab?.code;
|
|
42
|
+
}
|
|
43
|
+
if (!menuCode) {
|
|
44
|
+
const currentMenus = getSubApps().currentSubApp?.menus ?? [];
|
|
45
|
+
if (currentMenus && currentMenus.length) {
|
|
46
|
+
const flatMenus = flatTree(currentMenus).filter((item) => item?.routeUrl);
|
|
47
|
+
if (flatMenus && flatMenus.length) {
|
|
48
|
+
const currentMenu = flatMenus.find((item) => {
|
|
49
|
+
if (item?.applicationPath) {
|
|
50
|
+
return path?.includes("/" + item.applicationPath + item.routeUrl);
|
|
51
|
+
} else {
|
|
52
|
+
return path?.includes(item.routeUrl);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (currentMenu)
|
|
56
|
+
menuCode = currentMenu?.code ?? "";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let flag = false;
|
|
61
|
+
if (code) {
|
|
62
|
+
const btnList = getPageAuth(menuCode, applicationCode) ?? [];
|
|
63
|
+
flag = hasBtnAuth(btnList, code);
|
|
64
|
+
} else {
|
|
65
|
+
flag = !!getPageAuth(menuCode, applicationCode);
|
|
66
|
+
}
|
|
67
|
+
return flag;
|
|
68
|
+
};
|
|
69
|
+
const removeEl = (el, type) => {
|
|
70
|
+
if (type === "hide") {
|
|
71
|
+
el.classList.add("is-hide");
|
|
72
|
+
} else {
|
|
73
|
+
el.setAttribute("disabled", "");
|
|
74
|
+
el.classList.add("is-disabled");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const addEl = (el, type) => {
|
|
78
|
+
if (type === "hide") {
|
|
79
|
+
el.classList.remove("is-hide");
|
|
80
|
+
} else {
|
|
81
|
+
el.removeAttribute("disabled");
|
|
82
|
+
el.classList.remove("is-disabled");
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const vAuth = (el, binding) => {
|
|
86
|
+
let options = (el ? binding.value : binding) || {};
|
|
87
|
+
if (typeof options === "string")
|
|
88
|
+
options = { code: options };
|
|
89
|
+
const type = options?.type ?? "hide";
|
|
90
|
+
const isPermission = hasPermission(options);
|
|
91
|
+
if (el) {
|
|
92
|
+
if (!binding.oldValue) {
|
|
93
|
+
if (!isPermission)
|
|
94
|
+
getEl(el, options).then((element) => {
|
|
95
|
+
removeEl(element, type);
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
const oldHasPermission = hasPermission(binding.oldValue);
|
|
99
|
+
const newHasPermission = isPermission;
|
|
100
|
+
if (oldHasPermission === newHasPermission)
|
|
101
|
+
return;
|
|
102
|
+
getEl(el, options).then((element) => {
|
|
103
|
+
if (newHasPermission) {
|
|
104
|
+
addEl(element, type);
|
|
105
|
+
} else {
|
|
106
|
+
removeEl(element, type);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return isPermission;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { vAuth };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const getEl = async (el, options) => {
|
|
2
|
+
let res = el;
|
|
3
|
+
if (options?.target) {
|
|
4
|
+
if (typeof options.target === "string")
|
|
5
|
+
res = options.target;
|
|
6
|
+
if (typeof options.target === "function")
|
|
7
|
+
res = await options.target(el);
|
|
8
|
+
}
|
|
9
|
+
return res;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const vClickOutside = {
|
|
13
|
+
mounted: async (el, binding) => {
|
|
14
|
+
const options = binding.value;
|
|
15
|
+
const targetEl = await getEl(el, options);
|
|
16
|
+
function eventHandler(e) {
|
|
17
|
+
let flag = true;
|
|
18
|
+
if (Array.isArray(targetEl)) {
|
|
19
|
+
for (let dom of targetEl) {
|
|
20
|
+
dom.__click_outside__ = eventHandler;
|
|
21
|
+
if (dom.contains(e.target))
|
|
22
|
+
flag = false;
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
if (targetEl.contains(e.target)) {
|
|
26
|
+
flag = false;
|
|
27
|
+
}
|
|
28
|
+
targetEl.__click_outside__ = eventHandler;
|
|
29
|
+
}
|
|
30
|
+
if (flag) {
|
|
31
|
+
if (options?.fn && typeof options?.fn === "function") {
|
|
32
|
+
options?.fn(e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
document.addEventListener("click", eventHandler);
|
|
37
|
+
},
|
|
38
|
+
beforeUnmount: async (el, binding) => {
|
|
39
|
+
const options = binding.value;
|
|
40
|
+
const targetEl = await getEl(el, options);
|
|
41
|
+
if (Array.isArray(targetEl)) {
|
|
42
|
+
for (let dom of targetEl) {
|
|
43
|
+
document.removeEventListener("click", dom.__click_outside__);
|
|
44
|
+
delete dom.__click_outside__;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
document.removeEventListener("click", targetEl.__click_outside__);
|
|
48
|
+
delete targetEl.__click_outside__;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { vClickOutside };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const getEl = async (el, options) => {
|
|
2
|
+
let res = el;
|
|
3
|
+
if (options?.target) {
|
|
4
|
+
if (typeof options.target === "string")
|
|
5
|
+
res = options.target;
|
|
6
|
+
if (typeof options.target === "function")
|
|
7
|
+
res = await options.target(el);
|
|
8
|
+
}
|
|
9
|
+
return res;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const vHoverInside = {
|
|
13
|
+
mounted: async (el, binding) => {
|
|
14
|
+
const options = binding.value;
|
|
15
|
+
const targetEl = await getEl(el, options);
|
|
16
|
+
function eventHandler(flag, e) {
|
|
17
|
+
targetEl._inside_event = eventHandler;
|
|
18
|
+
if (typeof options === "function") {
|
|
19
|
+
options(flag, e);
|
|
20
|
+
} else if (options?.fn && typeof options?.fn === "function") {
|
|
21
|
+
options?.fn(flag, e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
targetEl.addEventListener("mouseenter", (e) => {
|
|
25
|
+
eventHandler(true, e);
|
|
26
|
+
});
|
|
27
|
+
targetEl.addEventListener("mouseleave", (e) => {
|
|
28
|
+
eventHandler(false, e);
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
beforeUnmount: async (el, binding) => {
|
|
32
|
+
const options = binding.value;
|
|
33
|
+
const targetEl = await getEl(el, options);
|
|
34
|
+
targetEl.addEventListener("mouseenter", targetEl._inside_event);
|
|
35
|
+
targetEl.addEventListener("mouseleave", targetEl._inside_event);
|
|
36
|
+
delete targetEl._inside_event;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { vHoverInside };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { getUrlParams, flatTree } from '@das-fed/utils/common-tools';
|
|
2
|
+
import { getTabInfo, getSubApps, getPageAuth } from '@das-fed/utils/common-info';
|
|
3
|
+
|
|
4
|
+
const getEl = async (el, options) => {
|
|
5
|
+
let res = el;
|
|
6
|
+
if (options?.target) {
|
|
7
|
+
if (typeof options.target === "string")
|
|
8
|
+
res = options.target;
|
|
9
|
+
if (typeof options.target === "function")
|
|
10
|
+
res = await options.target(el);
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const hasBtnAuth = (btnList, code) => {
|
|
16
|
+
if (!btnList || !code)
|
|
17
|
+
return false;
|
|
18
|
+
if (typeof code === "string") {
|
|
19
|
+
const currentItem = btnList.find((item) => item.code === code);
|
|
20
|
+
return !!currentItem;
|
|
21
|
+
} else {
|
|
22
|
+
let flag = false;
|
|
23
|
+
for (let value of code) {
|
|
24
|
+
const currentItem = btnList.find((item) => item.code === value);
|
|
25
|
+
if (currentItem) {
|
|
26
|
+
flag = true;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return flag;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const hasPermission = (options) => {
|
|
34
|
+
const code = options?.code ?? "";
|
|
35
|
+
const path = options?.path ?? location.pathname;
|
|
36
|
+
const applicationCode = options?.applicationCode ?? "";
|
|
37
|
+
let menuCode = "";
|
|
38
|
+
if (window.__IN_MICRO_APP__) {
|
|
39
|
+
menuCode = options?.menuCode ? options.menuCode : getUrlParams(location.href, "menu");
|
|
40
|
+
} else {
|
|
41
|
+
menuCode = options?.menuCode ? options.menuCode : getTabInfo().currentTab?.code;
|
|
42
|
+
}
|
|
43
|
+
if (!menuCode) {
|
|
44
|
+
const currentMenus = getSubApps().currentSubApp?.menus ?? [];
|
|
45
|
+
if (currentMenus && currentMenus.length) {
|
|
46
|
+
const flatMenus = flatTree(currentMenus).filter((item) => item?.routeUrl);
|
|
47
|
+
if (flatMenus && flatMenus.length) {
|
|
48
|
+
const currentMenu = flatMenus.find((item) => {
|
|
49
|
+
if (item?.applicationPath) {
|
|
50
|
+
return path?.includes("/" + item.applicationPath + item.routeUrl);
|
|
51
|
+
} else {
|
|
52
|
+
return path?.includes(item.routeUrl);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (currentMenu)
|
|
56
|
+
menuCode = currentMenu?.code ?? "";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let flag = false;
|
|
61
|
+
if (code) {
|
|
62
|
+
const btnList = getPageAuth(menuCode, applicationCode) ?? [];
|
|
63
|
+
flag = hasBtnAuth(btnList, code);
|
|
64
|
+
} else {
|
|
65
|
+
flag = !!getPageAuth(menuCode, applicationCode);
|
|
66
|
+
}
|
|
67
|
+
return flag;
|
|
68
|
+
};
|
|
69
|
+
const removeEl = (el, type) => {
|
|
70
|
+
if (type === "hide") {
|
|
71
|
+
el.classList.add("is-hide");
|
|
72
|
+
} else {
|
|
73
|
+
el.setAttribute("disabled", "");
|
|
74
|
+
el.classList.add("is-disabled");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const addEl = (el, type) => {
|
|
78
|
+
if (type === "hide") {
|
|
79
|
+
el.classList.remove("is-hide");
|
|
80
|
+
} else {
|
|
81
|
+
el.removeAttribute("disabled");
|
|
82
|
+
el.classList.remove("is-disabled");
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const vAuth = (el, binding) => {
|
|
86
|
+
let options = (el ? binding.value : binding) || {};
|
|
87
|
+
if (typeof options === "string")
|
|
88
|
+
options = { code: options };
|
|
89
|
+
const type = options?.type ?? "hide";
|
|
90
|
+
const isPermission = hasPermission(options);
|
|
91
|
+
if (el) {
|
|
92
|
+
if (!binding.oldValue) {
|
|
93
|
+
if (!isPermission)
|
|
94
|
+
getEl(el, options).then((element) => {
|
|
95
|
+
removeEl(element, type);
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
const oldHasPermission = hasPermission(binding.oldValue);
|
|
99
|
+
const newHasPermission = isPermission;
|
|
100
|
+
if (oldHasPermission === newHasPermission)
|
|
101
|
+
return;
|
|
102
|
+
getEl(el, options).then((element) => {
|
|
103
|
+
if (newHasPermission) {
|
|
104
|
+
addEl(element, type);
|
|
105
|
+
} else {
|
|
106
|
+
removeEl(element, type);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return isPermission;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const vClickOutside = {
|
|
115
|
+
mounted: async (el, binding) => {
|
|
116
|
+
const options = binding.value;
|
|
117
|
+
const targetEl = await getEl(el, options);
|
|
118
|
+
function eventHandler(e) {
|
|
119
|
+
let flag = true;
|
|
120
|
+
if (Array.isArray(targetEl)) {
|
|
121
|
+
for (let dom of targetEl) {
|
|
122
|
+
dom.__click_outside__ = eventHandler;
|
|
123
|
+
if (dom.contains(e.target))
|
|
124
|
+
flag = false;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (targetEl.contains(e.target)) {
|
|
128
|
+
flag = false;
|
|
129
|
+
}
|
|
130
|
+
targetEl.__click_outside__ = eventHandler;
|
|
131
|
+
}
|
|
132
|
+
if (flag) {
|
|
133
|
+
if (options?.fn && typeof options?.fn === "function") {
|
|
134
|
+
options?.fn(e);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
document.addEventListener("click", eventHandler);
|
|
139
|
+
},
|
|
140
|
+
beforeUnmount: async (el, binding) => {
|
|
141
|
+
const options = binding.value;
|
|
142
|
+
const targetEl = await getEl(el, options);
|
|
143
|
+
if (Array.isArray(targetEl)) {
|
|
144
|
+
for (let dom of targetEl) {
|
|
145
|
+
document.removeEventListener("click", dom.__click_outside__);
|
|
146
|
+
delete dom.__click_outside__;
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
document.removeEventListener("click", targetEl.__click_outside__);
|
|
150
|
+
delete targetEl.__click_outside__;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const vHoverInside = {
|
|
156
|
+
mounted: async (el, binding) => {
|
|
157
|
+
const options = binding.value;
|
|
158
|
+
const targetEl = await getEl(el, options);
|
|
159
|
+
function eventHandler(flag, e) {
|
|
160
|
+
targetEl._inside_event = eventHandler;
|
|
161
|
+
if (typeof options === "function") {
|
|
162
|
+
options(flag, e);
|
|
163
|
+
} else if (options?.fn && typeof options?.fn === "function") {
|
|
164
|
+
options?.fn(flag, e);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
targetEl.addEventListener("mouseenter", (e) => {
|
|
168
|
+
eventHandler(true, e);
|
|
169
|
+
});
|
|
170
|
+
targetEl.addEventListener("mouseleave", (e) => {
|
|
171
|
+
eventHandler(false, e);
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
beforeUnmount: async (el, binding) => {
|
|
175
|
+
const options = binding.value;
|
|
176
|
+
const targetEl = await getEl(el, options);
|
|
177
|
+
targetEl.addEventListener("mouseenter", targetEl._inside_event);
|
|
178
|
+
targetEl.addEventListener("mouseleave", targetEl._inside_event);
|
|
179
|
+
delete targetEl._inside_event;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export { vAuth, vClickOutside, vHoverInside };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const getEl = async (el, options) => {
|
|
2
|
+
let res = el;
|
|
3
|
+
if (options?.target) {
|
|
4
|
+
if (typeof options.target === "string")
|
|
5
|
+
res = options.target;
|
|
6
|
+
if (typeof options.target === "function")
|
|
7
|
+
res = await options.target(el);
|
|
8
|
+
}
|
|
9
|
+
return res;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { getEl };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const domCheckIn = (dom) => {
|
|
2
|
+
const event = window.event;
|
|
3
|
+
let x = Number(event.clientX);
|
|
4
|
+
let y = Number(event.clientY);
|
|
5
|
+
let div_x = Number(dom.getBoundingClientRect().left);
|
|
6
|
+
let div_x_width = Number(dom.getBoundingClientRect().left + dom.clientWidth);
|
|
7
|
+
let div_y = Number(dom.getBoundingClientRect().top);
|
|
8
|
+
let div_y_height = Number(dom.getBoundingClientRect().top + dom.clientHeight);
|
|
9
|
+
if (x > div_x && x < div_x_width && y > div_y && y < div_y_height) {
|
|
10
|
+
return true;
|
|
11
|
+
} else {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { domCheckIn };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const DomWatcher = (cb, dom, config = { attributes: true, childList: true, subtree: true }) => {
|
|
2
|
+
const watchDom = dom || document.body;
|
|
3
|
+
const domObserver = new MutationObserver((mutationsList) => {
|
|
4
|
+
cb(mutationsList);
|
|
5
|
+
});
|
|
6
|
+
domObserver.observe(watchDom, config);
|
|
7
|
+
return domObserver;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { DomWatcher };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ref, getCurrentInstance, inject, computed, unref } from 'vue';
|
|
2
|
+
|
|
3
|
+
const isNumber = (val) => typeof val === "number";
|
|
4
|
+
|
|
5
|
+
const zIndex = ref(0);
|
|
6
|
+
const defaultInitialZIndex = 2e3;
|
|
7
|
+
const zIndexContextKey = Symbol("zIndexContextKey");
|
|
8
|
+
const useZIndex$1 = (zIndexOverrides) => {
|
|
9
|
+
const zIndexInjection = zIndexOverrides || (getCurrentInstance() ? inject(zIndexContextKey, void 0) : void 0);
|
|
10
|
+
const initialZIndex = computed(() => {
|
|
11
|
+
const zIndexFromInjection = unref(zIndexInjection);
|
|
12
|
+
return isNumber(zIndexFromInjection) ? zIndexFromInjection : defaultInitialZIndex;
|
|
13
|
+
});
|
|
14
|
+
const currentZIndex = computed(() => initialZIndex.value + zIndex.value);
|
|
15
|
+
const nextZIndex = () => {
|
|
16
|
+
zIndex.value++;
|
|
17
|
+
return currentZIndex.value;
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
initialZIndex,
|
|
21
|
+
currentZIndex,
|
|
22
|
+
nextZIndex
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const elementZindex = useZIndex$1();
|
|
27
|
+
const useZIndex = () => {
|
|
28
|
+
const initialZIndex = computed(() => elementZindex.initialZIndex.value);
|
|
29
|
+
const currentZIndex = computed(() => elementZindex.currentZIndex.value);
|
|
30
|
+
const nextZIndex = () => {
|
|
31
|
+
const currentZIndex2 = elementZindex.nextZIndex();
|
|
32
|
+
return currentZIndex2;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
initialZIndex,
|
|
36
|
+
currentZIndex,
|
|
37
|
+
nextZIndex
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { useZIndex };
|
package/index.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { getUrlParams, flatTree } from '@das-fed/utils/common-tools';
|
|
2
|
+
import { getTabInfo, getSubApps, getPageAuth } from '@das-fed/utils/common-info';
|
|
3
|
+
|
|
4
|
+
const getConfig = () => {
|
|
5
|
+
let windowConfig = window?.config || {};
|
|
6
|
+
let config = { ...windowConfig };
|
|
7
|
+
if (!config.rootContainer)
|
|
8
|
+
config.rootContainer = "#app";
|
|
9
|
+
if (!config.baseURL)
|
|
10
|
+
config.baseURL = location.origin;
|
|
11
|
+
if (!config.ossBaseURL)
|
|
12
|
+
config.ossBaseURL = "/oss";
|
|
13
|
+
if (config.ossBaseURL.startsWith("/"))
|
|
14
|
+
config.ossBaseURL = `${config.baseURL}/oss`;
|
|
15
|
+
if (!config.ssoBaseURL)
|
|
16
|
+
config.ssoBaseURL = config.baseURL;
|
|
17
|
+
let { microAppName, publicPath, mainAppName } = config;
|
|
18
|
+
const isPro = import.meta.env.PROD;
|
|
19
|
+
if (microAppName && isPro && !publicPath)
|
|
20
|
+
publicPath = `/${microAppName}/`.replace(/\/\//g, "/");
|
|
21
|
+
if (!publicPath)
|
|
22
|
+
publicPath = "/";
|
|
23
|
+
config.publicPath = publicPath;
|
|
24
|
+
if (!config.autoOssBucket)
|
|
25
|
+
config.autoOssBucket = mainAppName || microAppName;
|
|
26
|
+
return config;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getEl = async (el, options) => {
|
|
30
|
+
let res = el;
|
|
31
|
+
if (options?.target) {
|
|
32
|
+
if (typeof options.target === "string")
|
|
33
|
+
res = options.target;
|
|
34
|
+
if (typeof options.target === "function")
|
|
35
|
+
res = await options.target(el);
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const hasBtnAuth = (btnList, code) => {
|
|
41
|
+
if (!btnList || !code)
|
|
42
|
+
return false;
|
|
43
|
+
if (typeof code === "string") {
|
|
44
|
+
const currentItem = btnList.find((item) => item.code === code);
|
|
45
|
+
return !!currentItem;
|
|
46
|
+
} else {
|
|
47
|
+
let flag = false;
|
|
48
|
+
for (let value of code) {
|
|
49
|
+
const currentItem = btnList.find((item) => item.code === value);
|
|
50
|
+
if (currentItem) {
|
|
51
|
+
flag = true;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return flag;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const hasPermission = (options) => {
|
|
59
|
+
const code = options?.code ?? "";
|
|
60
|
+
const path = options?.path ?? location.pathname;
|
|
61
|
+
const applicationCode = options?.applicationCode ?? "";
|
|
62
|
+
let menuCode = "";
|
|
63
|
+
if (window.__IN_MICRO_APP__) {
|
|
64
|
+
menuCode = options?.menuCode ? options.menuCode : getUrlParams(location.href, "menu");
|
|
65
|
+
} else {
|
|
66
|
+
menuCode = options?.menuCode ? options.menuCode : getTabInfo().currentTab?.code;
|
|
67
|
+
}
|
|
68
|
+
if (!menuCode) {
|
|
69
|
+
const currentMenus = getSubApps().currentSubApp?.menus ?? [];
|
|
70
|
+
if (currentMenus && currentMenus.length) {
|
|
71
|
+
const flatMenus = flatTree(currentMenus).filter((item) => item?.routeUrl);
|
|
72
|
+
if (flatMenus && flatMenus.length) {
|
|
73
|
+
const currentMenu = flatMenus.find((item) => {
|
|
74
|
+
if (item?.applicationPath) {
|
|
75
|
+
return path?.includes("/" + item.applicationPath + item.routeUrl);
|
|
76
|
+
} else {
|
|
77
|
+
return path?.includes(item.routeUrl);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (currentMenu)
|
|
81
|
+
menuCode = currentMenu?.code ?? "";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
let flag = false;
|
|
86
|
+
if (code) {
|
|
87
|
+
const btnList = getPageAuth(menuCode, applicationCode) ?? [];
|
|
88
|
+
flag = hasBtnAuth(btnList, code);
|
|
89
|
+
} else {
|
|
90
|
+
flag = !!getPageAuth(menuCode, applicationCode);
|
|
91
|
+
}
|
|
92
|
+
return flag;
|
|
93
|
+
};
|
|
94
|
+
const removeEl = (el, type) => {
|
|
95
|
+
if (type === "hide") {
|
|
96
|
+
el.classList.add("is-hide");
|
|
97
|
+
} else {
|
|
98
|
+
el.setAttribute("disabled", "");
|
|
99
|
+
el.classList.add("is-disabled");
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const addEl = (el, type) => {
|
|
103
|
+
if (type === "hide") {
|
|
104
|
+
el.classList.remove("is-hide");
|
|
105
|
+
} else {
|
|
106
|
+
el.removeAttribute("disabled");
|
|
107
|
+
el.classList.remove("is-disabled");
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const vAuth = (el, binding) => {
|
|
111
|
+
let options = (el ? binding.value : binding) || {};
|
|
112
|
+
if (typeof options === "string")
|
|
113
|
+
options = { code: options };
|
|
114
|
+
const type = options?.type ?? "hide";
|
|
115
|
+
const isPermission = hasPermission(options);
|
|
116
|
+
if (el) {
|
|
117
|
+
if (!binding.oldValue) {
|
|
118
|
+
if (!isPermission)
|
|
119
|
+
getEl(el, options).then((element) => {
|
|
120
|
+
removeEl(element, type);
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
const oldHasPermission = hasPermission(binding.oldValue);
|
|
124
|
+
const newHasPermission = isPermission;
|
|
125
|
+
if (oldHasPermission === newHasPermission)
|
|
126
|
+
return;
|
|
127
|
+
getEl(el, options).then((element) => {
|
|
128
|
+
if (newHasPermission) {
|
|
129
|
+
addEl(element, type);
|
|
130
|
+
} else {
|
|
131
|
+
removeEl(element, type);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return isPermission;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const vClickOutside = {
|
|
140
|
+
mounted: async (el, binding) => {
|
|
141
|
+
const options = binding.value;
|
|
142
|
+
const targetEl = await getEl(el, options);
|
|
143
|
+
function eventHandler(e) {
|
|
144
|
+
let flag = true;
|
|
145
|
+
if (Array.isArray(targetEl)) {
|
|
146
|
+
for (let dom of targetEl) {
|
|
147
|
+
dom.__click_outside__ = eventHandler;
|
|
148
|
+
if (dom.contains(e.target))
|
|
149
|
+
flag = false;
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
if (targetEl.contains(e.target)) {
|
|
153
|
+
flag = false;
|
|
154
|
+
}
|
|
155
|
+
targetEl.__click_outside__ = eventHandler;
|
|
156
|
+
}
|
|
157
|
+
if (flag) {
|
|
158
|
+
if (options?.fn && typeof options?.fn === "function") {
|
|
159
|
+
options?.fn(e);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
document.addEventListener("click", eventHandler);
|
|
164
|
+
},
|
|
165
|
+
beforeUnmount: async (el, binding) => {
|
|
166
|
+
const options = binding.value;
|
|
167
|
+
const targetEl = await getEl(el, options);
|
|
168
|
+
if (Array.isArray(targetEl)) {
|
|
169
|
+
for (let dom of targetEl) {
|
|
170
|
+
document.removeEventListener("click", dom.__click_outside__);
|
|
171
|
+
delete dom.__click_outside__;
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
document.removeEventListener("click", targetEl.__click_outside__);
|
|
175
|
+
delete targetEl.__click_outside__;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const vHoverInside = {
|
|
181
|
+
mounted: async (el, binding) => {
|
|
182
|
+
const options = binding.value;
|
|
183
|
+
const targetEl = await getEl(el, options);
|
|
184
|
+
function eventHandler(flag, e) {
|
|
185
|
+
targetEl._inside_event = eventHandler;
|
|
186
|
+
if (typeof options === "function") {
|
|
187
|
+
options(flag, e);
|
|
188
|
+
} else if (options?.fn && typeof options?.fn === "function") {
|
|
189
|
+
options?.fn(flag, e);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
targetEl.addEventListener("mouseenter", (e) => {
|
|
193
|
+
eventHandler(true, e);
|
|
194
|
+
});
|
|
195
|
+
targetEl.addEventListener("mouseleave", (e) => {
|
|
196
|
+
eventHandler(false, e);
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
beforeUnmount: async (el, binding) => {
|
|
200
|
+
const options = binding.value;
|
|
201
|
+
const targetEl = await getEl(el, options);
|
|
202
|
+
targetEl.addEventListener("mouseenter", targetEl._inside_event);
|
|
203
|
+
targetEl.addEventListener("mouseleave", targetEl._inside_event);
|
|
204
|
+
delete targetEl._inside_event;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const withInstall = (comp) => {
|
|
209
|
+
comp.install = function(app) {
|
|
210
|
+
app.component(comp.name, comp);
|
|
211
|
+
};
|
|
212
|
+
return comp;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export { getConfig, vAuth, vClickOutside, vHoverInside, withInstall };
|