kn-cli 1.0.131 → 1.0.134
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/build/shellUtil.sh +2 -2
- package/build/start.sh +3 -2
- package/build/vite.config.js +1 -1
- package/package.json +2 -1
- package/src/create.js +2 -0
- package/templates/template_admin_antd5/.vscode/settings.json +28 -0
- package/templates/template_admin_antd5/build.sh +8 -0
- package/templates/template_admin_antd5/cli.config.js +35 -0
- package/templates/template_admin_antd5/dev.sh +33 -0
- package/templates/template_admin_antd5/frontend_build.sh +48 -0
- package/templates/template_admin_antd5/init/prepare-commit-msg +5 -0
- package/templates/template_admin_antd5/init.sh +24 -0
- package/templates/template_admin_antd5/jsconfig.json +17 -0
- package/templates/template_admin_antd5/package.json +27 -0
- package/templates/template_admin_antd5/public/404.html +26 -0
- package/templates/template_admin_antd5/public/favicon.png +0 -0
- package/templates/template_admin_antd5/public/index.html +48 -0
- package/templates/template_admin_antd5/public/src/_antd.less +37 -0
- package/templates/template_admin_antd5/public/src/_mixin.module.less +79 -0
- package/templates/template_admin_antd5/public/src/_reset.module.less +134 -0
- package/templates/template_admin_antd5/public/src/_variable.module.less +85 -0
- package/templates/template_admin_antd5/public/src/assets/iconfont/iconfont.eot +0 -0
- package/templates/template_admin_antd5/public/src/assets/iconfont/iconfont.module.less +109 -0
- package/templates/template_admin_antd5/public/src/assets/iconfont/iconfont.svg +75 -0
- package/templates/template_admin_antd5/public/src/assets/iconfont/iconfont.ttf +0 -0
- package/templates/template_admin_antd5/public/src/assets/iconfont/iconfont.woff +0 -0
- package/templates/template_admin_antd5/public/src/assets/iconfont/iconfont.woff2 +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/arrow.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/avatar.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/icon-notice.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/icon-user.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/loadFail.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/loading.svg +40 -0
- package/templates/template_admin_antd5/public/src/assets/images/login/bg.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/login/logo.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/login/slogan.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-dep-active.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-dep.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-log-active.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-log.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-loginlog-active.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-loginlog.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-role-active.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-role.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-user-active.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/icon-user.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/nav-toggle.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/nav/slogan.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/noData.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/noSelect.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/permission/403.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/permission/404.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/permission/503.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/play.png +0 -0
- package/templates/template_admin_antd5/public/src/components/_table/column.jsx +47 -0
- package/templates/template_admin_antd5/public/src/components/_table/column.module.less +12 -0
- package/templates/template_admin_antd5/public/src/components/_table/index.jsx +71 -0
- package/templates/template_admin_antd5/public/src/components/_table/index.module.less +15 -0
- package/templates/template_admin_antd5/public/src/components/antd/antProvider.jsx +21 -0
- package/templates/template_admin_antd5/public/src/components/antd/index.jsx +146 -0
- package/templates/template_admin_antd5/public/src/components/antd/select/index.jsx +296 -0
- package/templates/template_admin_antd5/public/src/components/antd/select/index.module.less +21 -0
- package/templates/template_admin_antd5/public/src/components/antd/theme.js +173 -0
- package/templates/template_admin_antd5/public/src/components/antd/tooltip/detail/index.jsx +70 -0
- package/templates/template_admin_antd5/public/src/components/antd/tooltip/detail/index.module.less +12 -0
- package/templates/template_admin_antd5/public/src/components/antd/tooltip/index.jsx +69 -0
- package/templates/template_admin_antd5/public/src/components/antd/tooltip/index.module.less +28 -0
- package/templates/template_admin_antd5/public/src/components/auth/index.jsx +123 -0
- package/templates/template_admin_antd5/public/src/components/auth/index.module.less +7 -0
- package/templates/template_admin_antd5/public/src/components/auth/navCheck.jsx +27 -0
- package/templates/template_admin_antd5/public/src/components/badge/index.jsx +47 -0
- package/templates/template_admin_antd5/public/src/components/badge/index.module.less +44 -0
- package/templates/template_admin_antd5/public/src/components/button/index.jsx +17 -0
- package/templates/template_admin_antd5/public/src/components/debug/index.jsx +28 -0
- package/templates/template_admin_antd5/public/src/components/debug/index.module.less +10 -0
- package/templates/template_admin_antd5/public/src/components/empty/index.jsx +28 -0
- package/templates/template_admin_antd5/public/src/components/empty/index.module.less +20 -0
- package/templates/template_admin_antd5/public/src/components/error/index.jsx +39 -0
- package/templates/template_admin_antd5/public/src/components/icon/index.jsx +128 -0
- package/templates/template_admin_antd5/public/src/components/icon/playVideo/index.jsx +21 -0
- package/templates/template_admin_antd5/public/src/components/icon/playVideo/index.module.less +16 -0
- package/templates/template_admin_antd5/public/src/components/iconFont/index.jsx +20 -0
- package/templates/template_admin_antd5/public/src/components/iconFont/index.module.less +5 -0
- package/templates/template_admin_antd5/public/src/components/image/index.jsx +73 -0
- package/templates/template_admin_antd5/public/src/components/image/index.module.less +117 -0
- package/templates/template_admin_antd5/public/src/components/image/preview.jsx +85 -0
- package/templates/template_admin_antd5/public/src/components/layout/basic/index.jsx +49 -0
- package/templates/template_admin_antd5/public/src/components/layout/basic/index.module.less +76 -0
- package/templates/template_admin_antd5/public/src/components/layout/index.jsx +39 -0
- package/templates/template_admin_antd5/public/src/components/layout/index.module.less +63 -0
- package/templates/template_admin_antd5/public/src/components/layout/provider/index.jsx +32 -0
- package/templates/template_admin_antd5/public/src/components/leftMenu/index.jsx +106 -0
- package/templates/template_admin_antd5/public/src/components/leftMenu/index.module.less +42 -0
- package/templates/template_admin_antd5/public/src/components/link/index.jsx +39 -0
- package/templates/template_admin_antd5/public/src/components/link/index.module.less +11 -0
- package/templates/template_admin_antd5/public/src/components/menuIcon/index.jsx +33 -0
- package/templates/template_admin_antd5/public/src/components/menuIcon/index.module.less +49 -0
- package/templates/template_admin_antd5/public/src/components/page/pageLoading/index.jsx +51 -0
- package/templates/template_admin_antd5/public/src/components/page/pageLoading/index.module.less +29 -0
- package/templates/template_admin_antd5/public/src/components/popup/index.jsx +60 -0
- package/templates/template_admin_antd5/public/src/components/popup/index.module.less +18 -0
- package/templates/template_admin_antd5/public/src/components/react/index.jsx +13 -0
- package/templates/template_admin_antd5/public/src/components/resizeBox/index.jsx +144 -0
- package/templates/template_admin_antd5/public/src/components/resizeBox/index.module.css +90 -0
- package/templates/template_admin_antd5/public/src/components/select/defaultServicesSelect/index.jsx +182 -0
- package/templates/template_admin_antd5/public/src/components/select/dictSelect/index.jsx +84 -0
- package/templates/template_admin_antd5/public/src/components/select/index.jsx +7 -0
- package/templates/template_admin_antd5/public/src/components/select/useSelectList.jsx +217 -0
- package/templates/template_admin_antd5/public/src/components/table/aliTable/index.jsx +250 -0
- package/templates/template_admin_antd5/public/src/components/table/aliTable/index.module.less +105 -0
- package/templates/template_admin_antd5/public/src/components/table/column.jsx +128 -0
- package/templates/template_admin_antd5/public/src/components/table/column.module.less +50 -0
- package/templates/template_admin_antd5/public/src/components/table/imageTable/index.jsx +302 -0
- package/templates/template_admin_antd5/public/src/components/table/imageTable/index.module.less +196 -0
- package/templates/template_admin_antd5/public/src/components/table/imageTable/radio.jsx +15 -0
- package/templates/template_admin_antd5/public/src/components/table/imageTable/radio.module.less +18 -0
- package/templates/template_admin_antd5/public/src/components/table/index.jsx +475 -0
- package/templates/template_admin_antd5/public/src/components/table/index.module.less +133 -0
- package/templates/template_admin_antd5/public/src/components/text/index.jsx +98 -0
- package/templates/template_admin_antd5/public/src/components/text/index.module.less +13 -0
- package/templates/template_admin_antd5/public/src/components/toast/index.jsx +79 -0
- package/templates/template_admin_antd5/public/src/components/toast/index.module.less +43 -0
- package/templates/template_admin_antd5/public/src/components/topMenu/index.jsx +102 -0
- package/templates/template_admin_antd5/public/src/components/topMenu/index.module.less +89 -0
- package/templates/template_admin_antd5/public/src/components/topMenu/topBar/index.jsx +81 -0
- package/templates/template_admin_antd5/public/src/components/topMenu/topBar/index.module.less +97 -0
- package/templates/template_admin_antd5/public/src/components/video/index.jsx +96 -0
- package/templates/template_admin_antd5/public/src/components/video/index.module.less +132 -0
- package/templates/template_admin_antd5/public/src/components/video/preview.jsx +38 -0
- package/templates/template_admin_antd5/public/src/config.js +31 -0
- package/templates/template_admin_antd5/public/src/declarations.d.ts +1 -0
- package/templates/template_admin_antd5/public/src/dictionary/dictionary.js +289 -0
- package/templates/template_admin_antd5/public/src/dictionary/index.jsx +64 -0
- package/templates/template_admin_antd5/public/src/enum.js +41 -0
- package/templates/template_admin_antd5/public/src/hooks/index.jsx +29 -0
- package/templates/template_admin_antd5/public/src/hooks/useDebounceFn.jsx +33 -0
- package/templates/template_admin_antd5/public/src/hooks/useDelay.jsx +34 -0
- package/templates/template_admin_antd5/public/src/hooks/useEsc.jsx +98 -0
- package/templates/template_admin_antd5/public/src/hooks/useImageLoader.jsx +26 -0
- package/templates/template_admin_antd5/public/src/hooks/useInToView.jsx +58 -0
- package/templates/template_admin_antd5/public/src/hooks/useLoading.jsx +46 -0
- package/templates/template_admin_antd5/public/src/hooks/usePreload.jsx +67 -0
- package/templates/template_admin_antd5/public/src/hooks/useRouteMenu.jsx +263 -0
- package/templates/template_admin_antd5/public/src/hooks/useScrollTop.jsx +44 -0
- package/templates/template_admin_antd5/public/src/hooks/useSearch.jsx +163 -0
- package/templates/template_admin_antd5/public/src/hooks/useTableRowSelect.jsx +310 -0
- package/templates/template_admin_antd5/public/src/hooks/useThrottole.jsx +68 -0
- package/templates/template_admin_antd5/public/src/hooks/useTimer.jsx +42 -0
- package/templates/template_admin_antd5/public/src/hooks/useUpdate.jsx +16 -0
- package/templates/template_admin_antd5/public/src/hooks/useWatchServices.jsx +124 -0
- package/templates/template_admin_antd5/public/src/index.jsx +89 -0
- package/templates/template_admin_antd5/public/src/menuConfig/auth.jsx +92 -0
- package/templates/template_admin_antd5/public/src/menuConfig/dashboard.jsx +25 -0
- package/templates/template_admin_antd5/public/src/menuConfig/dna.jsx +76 -0
- package/templates/template_admin_antd5/public/src/menuConfig/index.jsx +17 -0
- package/templates/template_admin_antd5/public/src/mock/auth.js +33 -0
- package/templates/template_admin_antd5/public/src/mock/demo.js +122 -0
- package/templates/template_admin_antd5/public/src/mock/index.js +65 -0
- package/templates/template_admin_antd5/public/src/mock/utils.js +33 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/index.jsx +142 -0
- package/templates/template_admin_antd5/public/src/pages/auth/user/create/index.jsx +47 -0
- package/templates/template_admin_antd5/public/src/pages/auth/user/create/index.module.less +6 -0
- package/templates/template_admin_antd5/public/src/pages/auth/user/dialog/index.jsx +96 -0
- package/templates/template_admin_antd5/public/src/pages/auth/user/index.jsx +214 -0
- package/templates/template_admin_antd5/public/src/pages/components/layout/index.jsx +75 -0
- package/templates/template_admin_antd5/public/src/pages/components/layout/index.module.less +78 -0
- package/templates/template_admin_antd5/public/src/pages/components/layout/titleBar/index.jsx +28 -0
- package/templates/template_admin_antd5/public/src/pages/components/layout/titleBar/index.module.less +44 -0
- package/templates/template_admin_antd5/public/src/pages/components/select/user.jsx +18 -0
- package/templates/template_admin_antd5/public/src/pages/demo/page1.jsx +21 -0
- package/templates/template_admin_antd5/public/src/pages/demo/page2.jsx +21 -0
- package/templates/template_admin_antd5/public/src/pages/demo/page3.jsx +21 -0
- package/templates/template_admin_antd5/public/src/pages/error/403.jsx +15 -0
- package/templates/template_admin_antd5/public/src/pages/error/404.jsx +15 -0
- package/templates/template_admin_antd5/public/src/pages/error/503.jsx +15 -0
- package/templates/template_admin_antd5/public/src/pages/error/permission.jsx +40 -0
- package/templates/template_admin_antd5/public/src/pages/error/permission.module.less +16 -0
- package/templates/template_admin_antd5/public/src/pages/home.jsx +90 -0
- package/templates/template_admin_antd5/public/src/pages/home.module.less +6 -0
- package/templates/template_admin_antd5/public/src/pages/login/index.jsx +113 -0
- package/templates/template_admin_antd5/public/src/pages/login/index.module.less +153 -0
- package/templates/template_admin_antd5/public/src/pages/pageTemplate.jsx +28 -0
- package/templates/template_admin_antd5/public/src/provider/app.jsx +201 -0
- package/templates/template_admin_antd5/public/src/provider/loading.jsx +47 -0
- package/templates/template_admin_antd5/public/src/provider/menu.jsx +161 -0
- package/templates/template_admin_antd5/public/src/provider/menu.module.less +35 -0
- package/templates/template_admin_antd5/public/src/route.jsx +127 -0
- package/templates/template_admin_antd5/public/src/services/demo.js +85 -0
- package/templates/template_admin_antd5/public/src/services/excel.js +43 -0
- package/templates/template_admin_antd5/public/src/services/http/index.js +155 -0
- package/templates/template_admin_antd5/public/src/services/index.js +126 -0
- package/templates/template_admin_antd5/public/src/services/interceptor/index.js +67 -0
- package/templates/template_admin_antd5/public/src/services/login.js +37 -0
- package/templates/template_admin_antd5/public/src/services/socket/index.jsx +99 -0
- package/templates/template_admin_antd5/public/src/services/token/index.js +41 -0
- package/templates/template_admin_antd5/public/src/type.js +67 -0
- package/templates/template_admin_antd5/public/src/utils/event.js +58 -0
- package/templates/template_admin_antd5/public/src/utils/format.js +135 -0
- package/templates/template_admin_antd5/public/src/utils/index.js +727 -0
- package/templates/template_admin_antd5/public/src/utils/menu.js +33 -0
- package/templates/template_admin_antd5/public/src/utils/rule.js +277 -0
- package/templates/template_admin_antd5/public/src/utils/storage.js +30 -0
- package/templates/template_admin_antd5/public/static/about.html +1 -0
- package/templates/template_admin_antd5/public/static/kssoLogin.html +22 -0
- package/templates/template_admin_antd5/readme.md +84 -0
- package/templates/template_admin_antd5/renamejstojsx.js +45 -0
- package/templates/template_admin_antd5/renameless.js +53 -0
- package/templates/template_admin_antd5/report.sh +25 -0
- package/templates/template_admin_antd5/shellUtil.sh +110 -0
- package/templates/template_admin_antd5/versionPublish.sh +16 -0
- package/templates/template_admin_antd5/webpack.api.js +105 -0
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import moment from 'moment';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 打开一个第三方链接
|
|
9
|
+
* @param {string} link - 链接地址
|
|
10
|
+
* @param {string} [target='_blank'] - 打开方式,_blank:新窗口打开
|
|
11
|
+
*/
|
|
12
|
+
export const openLink = (link, target = '_blank',isDownload=false) => {
|
|
13
|
+
// link = 'http://xy-cdn-source-site-test.poi234.com/source/dc/1092/1/ascqcs50041_1.apk';
|
|
14
|
+
// jumpUrl(link,{newWindow:target=='_blank'});
|
|
15
|
+
// return;
|
|
16
|
+
let domLink = document.createElement('a');
|
|
17
|
+
if(isDownload){
|
|
18
|
+
domLink.setAttribute('download','1');
|
|
19
|
+
}
|
|
20
|
+
domLink.href = link;
|
|
21
|
+
domLink.setAttribute('target', target);
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
domLink.style.opacity = 0;
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
domLink.style.zIndex = -999;
|
|
26
|
+
document.body.appendChild(domLink);
|
|
27
|
+
domLink.click();
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
document.body.removeChild(domLink);
|
|
30
|
+
}, 20000);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 生成HTML内容的临时链接
|
|
35
|
+
* @param {string} html - HTML内容
|
|
36
|
+
* @returns {string} 临时URL
|
|
37
|
+
*/
|
|
38
|
+
export const createHtmlTempUrl = (html) => {
|
|
39
|
+
const blob = new Blob([html], { type: 'text/html;charset=utf-8' });
|
|
40
|
+
return URL.createObjectURL(blob);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 打开HTML窗口 - 多种兼容方案
|
|
46
|
+
* @param {string} html - HTML内容
|
|
47
|
+
* @param {number} width - 窗口宽度
|
|
48
|
+
* @param {number} height - 窗口高度
|
|
49
|
+
* @returns {Promise<Window|null>} 打开的窗口对象
|
|
50
|
+
*/
|
|
51
|
+
export const openHtmlWindow= async (html,width=800,height=600)=>{
|
|
52
|
+
// 方案1:临时链接方式(兼容性最好,推荐)
|
|
53
|
+
try {
|
|
54
|
+
const tempUrl = createHtmlTempUrl(html);
|
|
55
|
+
const newWindow = window.open(tempUrl, "_blank", `width=${width},height=${height}`);
|
|
56
|
+
|
|
57
|
+
if (newWindow) {
|
|
58
|
+
// 延迟清理临时URL
|
|
59
|
+
setTimeout(() => URL.revokeObjectURL(tempUrl), 10000);
|
|
60
|
+
return newWindow;
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.warn('临时链接方式失败:', error);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 方案2:Picture-in-Picture(现代浏览器)
|
|
67
|
+
if ("documentPictureInPicture" in window) {
|
|
68
|
+
try {
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
const pipWindow = await window.documentPictureInPicture.requestWindow({
|
|
71
|
+
width, height
|
|
72
|
+
});
|
|
73
|
+
pipWindow.document.write(html);
|
|
74
|
+
pipWindow.document.close();
|
|
75
|
+
return pipWindow;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.warn('Picture-in-Picture失败:', error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 方案3:传统 document.write 方式
|
|
82
|
+
try {
|
|
83
|
+
const newWindow = window.open("", "dynamicWindow", `width=${width},height=${height}`);
|
|
84
|
+
if (!newWindow) return null;
|
|
85
|
+
newWindow.document.write(html);
|
|
86
|
+
newWindow.document.close();
|
|
87
|
+
return newWindow;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.warn('传统方式失败:', error);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 所有方案都失败
|
|
93
|
+
console.error('所有窗口打开方式都失败');
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 判断当前是否为移动端
|
|
100
|
+
* @returns {boolean}
|
|
101
|
+
*/
|
|
102
|
+
export const isMobile = () => {
|
|
103
|
+
return navigator.userAgent.match(
|
|
104
|
+
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
|
|
105
|
+
)?true:false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 跳转URL-兼容飞书
|
|
111
|
+
* @param {string} url - 链接地址
|
|
112
|
+
* @param {object} [options] - 参数
|
|
113
|
+
* @param {boolean} [options.replace] - 是否要覆盖当前URL记录
|
|
114
|
+
* @param {boolean} [options.newWindow] - 是否新窗口中打开
|
|
115
|
+
* @param {boolean} [options.reload] - 是否重载当前页面
|
|
116
|
+
*
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
export const jumpUrl=(url,options={})=>{
|
|
120
|
+
const {replace=false,newWindow=false,reload=false}= options;
|
|
121
|
+
if(!reload){
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
if(window.knFeishu){
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
window.knFeishu.ToHref(url,replace,newWindow);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if(replace){
|
|
131
|
+
location.replace(url);
|
|
132
|
+
if(reload){
|
|
133
|
+
setTimeout(()=>{
|
|
134
|
+
location.reload();
|
|
135
|
+
},500)
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if(reload){
|
|
142
|
+
location.reload();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if(newWindow){
|
|
147
|
+
window.open(url);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
location.href=url;
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
// 关闭页面
|
|
158
|
+
export const closeWindow = () => {
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
if (window.knFeishu && window.knFeishu.closeWindow) {
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
window.knFeishu.closeWindow();
|
|
163
|
+
} else {
|
|
164
|
+
if (window.close) {
|
|
165
|
+
window.close();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
export const px2rem=(px)=>{
|
|
172
|
+
px=+px/100+'rem';
|
|
173
|
+
return px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 获取字符串字节数(中文字符字节数由编码方式角色,utf-8是3个字节)
|
|
178
|
+
*/
|
|
179
|
+
export const getStrByteLen=(str)=>{
|
|
180
|
+
if(!str){
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
const len=encodeURIComponent(str).replace(/%../g,"a").length;
|
|
184
|
+
return len;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 下载文件
|
|
189
|
+
* @param {string} url - 文件地址
|
|
190
|
+
* @param {string} [filename] - 文件名
|
|
191
|
+
*/
|
|
192
|
+
export const downloadFile = (url,filename)=> {
|
|
193
|
+
// 使用fetch API获取资源
|
|
194
|
+
fetch(url)
|
|
195
|
+
.then(response => {
|
|
196
|
+
return response.blob();
|
|
197
|
+
}) // 将响应转换为Blob对象
|
|
198
|
+
.then(blob => {
|
|
199
|
+
// 创建一个指向该Blob的URL
|
|
200
|
+
const blobUrl=window.URL.createObjectURL(blob);
|
|
201
|
+
// 创建一个<a>标签用于下载
|
|
202
|
+
const link=document.createElement('a');
|
|
203
|
+
link.href=blobUrl;
|
|
204
|
+
link.download=filename||''; // 设置下载文件名,如果没有览器将使用URL的最后一部分作为文件名
|
|
205
|
+
link.style.display='none';
|
|
206
|
+
// 触发下载
|
|
207
|
+
document.body.appendChild(link);
|
|
208
|
+
link.click();
|
|
209
|
+
|
|
210
|
+
// 清理并移除<a>标签
|
|
211
|
+
document.body.removeChild(link);
|
|
212
|
+
window.URL.revokeObjectURL(blobUrl);
|
|
213
|
+
})
|
|
214
|
+
.catch(error => {
|
|
215
|
+
console.error('下载资源失败:',error);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
const CONSOLE_CONFIG={
|
|
223
|
+
'useRouteMenu':false,
|
|
224
|
+
'ProviderTimelines':true,
|
|
225
|
+
'Websocket':true,
|
|
226
|
+
'EventBus':false,
|
|
227
|
+
'MessageWall':true,
|
|
228
|
+
'ProviderApp':true,
|
|
229
|
+
'RouteConfig':false
|
|
230
|
+
}
|
|
231
|
+
export const CONSOLE_LOG=(moduleName, txt, ...other)=>{
|
|
232
|
+
if(!CONSOLE_CONFIG[moduleName]){return;}
|
|
233
|
+
console.log(`[${moduleName}]${txt}`, ...other)
|
|
234
|
+
}
|
|
235
|
+
CONSOLE_LOG.MODULE = CONSOLE_CONFIG;
|
|
236
|
+
|
|
237
|
+
CONSOLE_LOG.warn = (moduleName, txt, ...other)=>{
|
|
238
|
+
if(!CONSOLE_CONFIG[moduleName]){return;}
|
|
239
|
+
console.warn(`[${moduleName}]${txt}`, ...other)
|
|
240
|
+
}
|
|
241
|
+
CONSOLE_LOG.error = (moduleName, txt, ...other)=>{
|
|
242
|
+
if(!CONSOLE_CONFIG[moduleName]){return;}
|
|
243
|
+
console.error(`[${moduleName}]${txt}`, ...other)
|
|
244
|
+
}
|
|
245
|
+
CONSOLE_LOG.info = (moduleName, txt, ...other)=>{
|
|
246
|
+
if(!CONSOLE_CONFIG[moduleName]){return;}
|
|
247
|
+
console.info(`[${moduleName}]${txt}`, ...other)
|
|
248
|
+
}
|
|
249
|
+
CONSOLE_LOG.log = (moduleName, txt, ...other)=>{
|
|
250
|
+
if(!CONSOLE_CONFIG[moduleName]){return;}
|
|
251
|
+
console.log(`[${moduleName}]${txt}`, ...other)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export const WriteLog=(text)=>{
|
|
255
|
+
let log = localStorage.getItem('nebulaLog');
|
|
256
|
+
let logs=[];
|
|
257
|
+
text = `[${moment().format('MM-DD HH:mm:ss')}]:${text}`;
|
|
258
|
+
if(log){
|
|
259
|
+
logs = log.split('\n');
|
|
260
|
+
}else{
|
|
261
|
+
log = text;
|
|
262
|
+
}
|
|
263
|
+
logs.splice(0,0,text);
|
|
264
|
+
localStorage.setItem('nebulaLog',logs.join('\n'));
|
|
265
|
+
}
|
|
266
|
+
export const Storage={
|
|
267
|
+
/**
|
|
268
|
+
* @param {string} name
|
|
269
|
+
* @returns {object|null}
|
|
270
|
+
*/
|
|
271
|
+
get:(name)=>{
|
|
272
|
+
let req = localStorage.getItem(name);
|
|
273
|
+
try{
|
|
274
|
+
if(req){
|
|
275
|
+
req = JSON.parse(req);
|
|
276
|
+
return req;
|
|
277
|
+
}
|
|
278
|
+
}catch(ex){
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
/**
|
|
283
|
+
* @param {string} name
|
|
284
|
+
* @param {object} item
|
|
285
|
+
*/
|
|
286
|
+
set:(name,item)=>{
|
|
287
|
+
let value='';
|
|
288
|
+
if(item){
|
|
289
|
+
value = JSON.stringify(item);
|
|
290
|
+
}
|
|
291
|
+
localStorage.setItem(name,value);
|
|
292
|
+
},
|
|
293
|
+
clear:(name)=>{
|
|
294
|
+
localStorage.removeItem(name);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
export const StorageName={
|
|
298
|
+
UserListFilterMenu:'userListFilterMenu',
|
|
299
|
+
AccountConfig:'AccountConfig'
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* 给返回Promise的函数增加节流功能
|
|
306
|
+
* @param {(any)=>Promise} fn
|
|
307
|
+
* @param {number} ms - 防抖时间
|
|
308
|
+
* @returns {Function}
|
|
309
|
+
*/
|
|
310
|
+
export function throttlePromise(fn, ms) {
|
|
311
|
+
const pendingPromises = new Map();
|
|
312
|
+
return function(params) {
|
|
313
|
+
const key = JSON.stringify(params);
|
|
314
|
+
|
|
315
|
+
if (pendingPromises.has(key)) {
|
|
316
|
+
return pendingPromises.get(key);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const promise = new Promise((resolve, reject) => {
|
|
320
|
+
setTimeout(() => {
|
|
321
|
+
pendingPromises.delete(key);
|
|
322
|
+
fn(params).then(resolve).catch(reject);
|
|
323
|
+
}, ms);
|
|
324
|
+
});
|
|
325
|
+
pendingPromises.set(key, promise);
|
|
326
|
+
return promise;
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
export const delayLoader=(loader,ms=5000)=>{
|
|
332
|
+
return new Promise(resolve=>{
|
|
333
|
+
loader.then(req=>{
|
|
334
|
+
setTimeout(()=>{
|
|
335
|
+
resolve(req);
|
|
336
|
+
},ms)
|
|
337
|
+
})
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export const delay=(ms=1000)=>{
|
|
342
|
+
return new Promise(resolve=>{
|
|
343
|
+
setTimeout(()=>{
|
|
344
|
+
resolve();
|
|
345
|
+
},ms)
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 判断是否有值
|
|
351
|
+
* [undefined,null,Number.NaN]=false
|
|
352
|
+
* ['','1',1,0,'0',-1,'-1',true,false,' ',{}]=true
|
|
353
|
+
* @param {any} item
|
|
354
|
+
* @returns {boolean}
|
|
355
|
+
*/
|
|
356
|
+
export const hasValue=(item)=>{
|
|
357
|
+
if(item===undefined||item===null||Number.isNaN(item)){
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 判断是否有数值
|
|
365
|
+
* ['',true,false,undefined,null,Number.NaN,' ','a',{}]=false
|
|
366
|
+
* ['1',1,0,'0',-1,'-1']=true
|
|
367
|
+
* @param {any} item
|
|
368
|
+
* @returns {boolean}
|
|
369
|
+
*/
|
|
370
|
+
export const hasNumberValue=(item)=>{
|
|
371
|
+
return hasValue(item) && !Number.isNaN(parseFloat(item));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export const FormStyle={
|
|
375
|
+
labelWrap:true,
|
|
376
|
+
labelCol:{ span: 2 },
|
|
377
|
+
wrapperCol:{ span: 8 },
|
|
378
|
+
colon:false,
|
|
379
|
+
/**
|
|
380
|
+
* @type {'left'|'right'}
|
|
381
|
+
*/
|
|
382
|
+
labelAlign:'left'
|
|
383
|
+
}
|
|
384
|
+
export const FormStyleLarge={
|
|
385
|
+
labelWrap:true,
|
|
386
|
+
labelCol:{ span: 3 },
|
|
387
|
+
wrapperCol:{ span: 8 },
|
|
388
|
+
colon:false,
|
|
389
|
+
/**
|
|
390
|
+
* @type {'left'|'right'}
|
|
391
|
+
*/
|
|
392
|
+
labelAlign:'left'
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
export const FormStyleDialog={
|
|
397
|
+
labelWrap:true,
|
|
398
|
+
labelCol:{ span: 6 },
|
|
399
|
+
wrapperCol:{ span: 18 },
|
|
400
|
+
colon:false,
|
|
401
|
+
/**
|
|
402
|
+
* @type {'left'|'right'}
|
|
403
|
+
*/
|
|
404
|
+
labelAlign:'left'
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export const FormStyleColumn={
|
|
408
|
+
labelWrap:true,
|
|
409
|
+
labelCol:{ span: 8 },
|
|
410
|
+
wrapperCol:{ span: 16 },
|
|
411
|
+
colon:false,
|
|
412
|
+
/**
|
|
413
|
+
* @type {'left'|'right'}
|
|
414
|
+
*/
|
|
415
|
+
labelAlign:'left'
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export const GetUrlSearch=(key)=>{
|
|
419
|
+
var url = new URL(location.href);
|
|
420
|
+
let req = url.searchParams.get(key);
|
|
421
|
+
if(req==null){
|
|
422
|
+
|
|
423
|
+
// 获取 hash 部分并去掉 #
|
|
424
|
+
const hash = url.hash.substring(1);
|
|
425
|
+
// 检查 hash 部分是否包含查询参数
|
|
426
|
+
const hashParts = hash.split('?');
|
|
427
|
+
const path = hashParts[0];
|
|
428
|
+
const queryString = hashParts[1] || '';
|
|
429
|
+
// 解析查询参数
|
|
430
|
+
const searchParams = new URLSearchParams(queryString);
|
|
431
|
+
req = searchParams.get(key);
|
|
432
|
+
}
|
|
433
|
+
return req||'';
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
export const loadImage= async (url)=>{
|
|
438
|
+
return new Promise((resolve,reject)=>{
|
|
439
|
+
if(typeof url === 'string'){
|
|
440
|
+
var img = new Image();
|
|
441
|
+
img.onload = function() {
|
|
442
|
+
resolve(img);
|
|
443
|
+
};
|
|
444
|
+
img.onerror=()=>{
|
|
445
|
+
reject();
|
|
446
|
+
}
|
|
447
|
+
// @ts-ignore
|
|
448
|
+
img.src =url;
|
|
449
|
+
}else{
|
|
450
|
+
var reader = new FileReader();
|
|
451
|
+
reader.onload = function(e) {
|
|
452
|
+
var img = new Image();
|
|
453
|
+
img.onload = function() {
|
|
454
|
+
resolve(img);
|
|
455
|
+
};
|
|
456
|
+
img.onerror=()=>{
|
|
457
|
+
reject();
|
|
458
|
+
}
|
|
459
|
+
// @ts-ignore
|
|
460
|
+
img.src = e.target.result;
|
|
461
|
+
};
|
|
462
|
+
reader.onerror=()=>{
|
|
463
|
+
reject();
|
|
464
|
+
}
|
|
465
|
+
reader.readAsDataURL(url);
|
|
466
|
+
}
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
export const getVideoInfo= async (file)=>{
|
|
473
|
+
return new Promise((resolve,reject)=>{
|
|
474
|
+
var reader = new FileReader();
|
|
475
|
+
reader.onload =()=>{
|
|
476
|
+
let video = document.createElement('video');
|
|
477
|
+
video.addEventListener('canplay',(e)=>{
|
|
478
|
+
// @ts-ignore
|
|
479
|
+
const {videoWidth,videoHeight} = e.target;
|
|
480
|
+
resolve({width:videoWidth,height:videoHeight});
|
|
481
|
+
})
|
|
482
|
+
video.addEventListener('error',(e)=>{
|
|
483
|
+
// @ts-ignore
|
|
484
|
+
console.error('video play error:',e?.target?.error);
|
|
485
|
+
resolve({width:'',height:''});
|
|
486
|
+
})
|
|
487
|
+
// @ts-ignore
|
|
488
|
+
video.setAttribute('src',reader.result);
|
|
489
|
+
}
|
|
490
|
+
reader.onerror=()=>{
|
|
491
|
+
resolve({width:'',height:''})
|
|
492
|
+
}
|
|
493
|
+
reader.readAsDataURL(file);
|
|
494
|
+
|
|
495
|
+
})
|
|
496
|
+
}
|
|
497
|
+
export const getAudioInfo= async (file)=>{
|
|
498
|
+
return new Promise((resolve,reject)=>{
|
|
499
|
+
var reader = new FileReader();
|
|
500
|
+
reader.onload =()=>{
|
|
501
|
+
let video = document.createElement('audio');
|
|
502
|
+
video.addEventListener('canplay',(e)=>{
|
|
503
|
+
// @ts-ignore
|
|
504
|
+
const { duration } = e.target;
|
|
505
|
+
resolve({duration: +duration.toFixed(2)});
|
|
506
|
+
})
|
|
507
|
+
// @ts-ignore
|
|
508
|
+
video.setAttribute('src',reader.result);
|
|
509
|
+
}
|
|
510
|
+
reader.onerror=()=>{
|
|
511
|
+
resolve({duration:''})
|
|
512
|
+
}
|
|
513
|
+
reader.readAsDataURL(file);
|
|
514
|
+
})
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
/** 复制到剪切板 */
|
|
520
|
+
export function copyToClipboard(text, cb) {
|
|
521
|
+
|
|
522
|
+
function fallbackCopyTextToClipboard(text) {
|
|
523
|
+
const textArea = document.createElement('textarea');
|
|
524
|
+
textArea.value = text;
|
|
525
|
+
|
|
526
|
+
// 防止排版上的干扰
|
|
527
|
+
textArea.style.top = '0';
|
|
528
|
+
textArea.style.left = '0';
|
|
529
|
+
textArea.style.position = 'fixed';
|
|
530
|
+
|
|
531
|
+
document.body.appendChild(textArea);
|
|
532
|
+
textArea.focus();
|
|
533
|
+
textArea.select();
|
|
534
|
+
|
|
535
|
+
try {
|
|
536
|
+
const successful = document.execCommand('copy');
|
|
537
|
+
const msg = successful ? '成功' : '失败';
|
|
538
|
+
cb?.(successful);
|
|
539
|
+
console.log('后备复制方法' + msg);
|
|
540
|
+
} catch (err) {
|
|
541
|
+
cb?.(false);
|
|
542
|
+
console.error('后备复制方法异常', err);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
document.body.removeChild(textArea);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (navigator.clipboard) {
|
|
549
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
550
|
+
console.log('文本已复制到剪切板');
|
|
551
|
+
cb?.(true);
|
|
552
|
+
}).catch(err => {
|
|
553
|
+
console.error('无法复制文本: ', err);
|
|
554
|
+
cb?.(false);
|
|
555
|
+
});
|
|
556
|
+
} else {
|
|
557
|
+
fallbackCopyTextToClipboard(text);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** 记录查询条件参数的key */
|
|
562
|
+
export const paramsKey = '_search_v1';
|
|
563
|
+
/**
|
|
564
|
+
* 整理参数,用于跳转页面时的传参
|
|
565
|
+
* @param {object} values
|
|
566
|
+
* @returns {string}
|
|
567
|
+
*/
|
|
568
|
+
export const encodeParamsToLink = (values) => {
|
|
569
|
+
return `${paramsKey}=${encodeURIComponent(JSON.stringify(values))}`;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* 整理参数,从地址栏获取参数
|
|
573
|
+
* @param {object} _paramsKey 参数的关键词
|
|
574
|
+
* @param {object} isTwoEncode 是否有2层编码
|
|
575
|
+
* @returns {object}
|
|
576
|
+
*/
|
|
577
|
+
export const decodeParamsFromLink = (_paramsKey = paramsKey, isTwoEncode = false) => {
|
|
578
|
+
try {
|
|
579
|
+
const paramsString = location.href.split('?')[1];
|
|
580
|
+
if (!paramsString || paramsString.indexOf(_paramsKey) === -1) {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
const arr = paramsString.split('&');
|
|
584
|
+
const target = arr.find(i => i.indexOf(_paramsKey) > -1);
|
|
585
|
+
let value = target.split('=')[1];
|
|
586
|
+
value = value.split('#')[0];
|
|
587
|
+
return isTwoEncode ? JSON.parse(decodeURIComponent(decodeURIComponent(value))): JSON.parse(decodeURIComponent(value));
|
|
588
|
+
}
|
|
589
|
+
catch(e) {
|
|
590
|
+
return null
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
export const Rand= (min, max)=> {
|
|
596
|
+
|
|
597
|
+
let difference = max - min;
|
|
598
|
+
// 使用 Math.random() 生成 [0, 1) 之间的随机数,乘以差值并加上 min,再使用 Math.floor() 向下取整得到最终结果
|
|
599
|
+
let result = Math.floor(Math.random() * (difference + 1)) + min;
|
|
600
|
+
return result;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
let GLOBAL_SEED=Date.now();
|
|
607
|
+
/**
|
|
608
|
+
* 伪随机
|
|
609
|
+
* @param {*} min
|
|
610
|
+
* @param {*} max
|
|
611
|
+
* @returns {number}
|
|
612
|
+
*/
|
|
613
|
+
export const RandPseudo= (min,max)=>{
|
|
614
|
+
GLOBAL_SEED = (GLOBAL_SEED*9301+49297)%233280;
|
|
615
|
+
let seed= GLOBAL_SEED/233280;
|
|
616
|
+
var ret = Math.floor(seed * (max-min+1) + min);
|
|
617
|
+
return ret;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
export const isPromise=(obj)=> {
|
|
622
|
+
return !!obj && typeof obj.then === 'function';
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export const keySort=(key, value) => {
|
|
626
|
+
if(value==null || value == undefined )return value;
|
|
627
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
628
|
+
// 对对象的键进行排序并重建对象
|
|
629
|
+
const sortedKeys = Object.keys(value).sort();
|
|
630
|
+
const sortedObj = {};
|
|
631
|
+
sortedKeys.forEach(k => {
|
|
632
|
+
sortedObj[k] = value[k];
|
|
633
|
+
});
|
|
634
|
+
return sortedObj;
|
|
635
|
+
}
|
|
636
|
+
return value;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 判断是否是横版素材
|
|
641
|
+
* @param {number} width
|
|
642
|
+
* @param {number} height
|
|
643
|
+
* @returns {boolean}
|
|
644
|
+
*/
|
|
645
|
+
export const isHorizontal=(width,height)=>{
|
|
646
|
+
if(width>height){
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
export const startsWithChinese = (str) => {
|
|
655
|
+
if (!str || str.length === 0) return false;
|
|
656
|
+
// 匹配基本汉字、扩展A、扩展B等
|
|
657
|
+
return /^[\u4e00-\u9fa5\u3400-\u4dbf\uf900-\ufaff\u3300-\u33ff\ud840-\ud868\ud869-\ud86d\ud86e-\ud872\ud873-\ud879\ud880-\ud883]/.test(str);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
// 时间早于当日则设为当日
|
|
662
|
+
export const returnAtLeastToDay = (timeStr) => {
|
|
663
|
+
return moment().isBefore(moment(timeStr)) ? moment(timeStr) : moment();
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* 判断2个数组是否内容一致
|
|
668
|
+
* @param {Array} arr1
|
|
669
|
+
* @param {Array} arr2
|
|
670
|
+
* @returns {boolean}
|
|
671
|
+
*/
|
|
672
|
+
export const isSameArray=(arr1,arr2)=>{
|
|
673
|
+
if(!arr1 && !arr2)return true;
|
|
674
|
+
if(!arr1||!arr2)return false;
|
|
675
|
+
if(!Array.isArray(arr1) || !Array.isArray(arr2))return false;
|
|
676
|
+
|
|
677
|
+
if(arr1.length != arr2.length)return false;
|
|
678
|
+
let _arr1 = arr1.sort()
|
|
679
|
+
let _arr2 = arr2.sort()
|
|
680
|
+
|
|
681
|
+
for(let i=0;i<_arr1.length;i++){
|
|
682
|
+
if(_arr1[i] != _arr2[i]){
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* 计算弹出式的素材选择界面的宽度
|
|
691
|
+
* @param {object} [props]
|
|
692
|
+
* @param {number} [props.min=900] - 最小宽度要求
|
|
693
|
+
* @param {number} [props.max=1264] - 期望最大宽度
|
|
694
|
+
* @returns {number}
|
|
695
|
+
*/
|
|
696
|
+
export const getSelectMaterialDrawerWidth=(props={})=>{
|
|
697
|
+
const {min=900,max=1264}=props;
|
|
698
|
+
let width=max;
|
|
699
|
+
const docEl = document.documentElement;
|
|
700
|
+
// 当前窗口最大值
|
|
701
|
+
let windowWidth = Math.max(window.innerWidth, docEl.clientWidth, docEl.offsetWidth)-24;
|
|
702
|
+
// 如果超过当前屏幕窗口大小则取当前屏幕窗口大小的值
|
|
703
|
+
width = Math.min(width,windowWidth);
|
|
704
|
+
if(min){
|
|
705
|
+
// 如果设置了强制最小宽度值,则取>=min的值
|
|
706
|
+
width = Math.max(min,width);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
return width;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* 将数组进行一次洗牌
|
|
715
|
+
* @param {*} arr
|
|
716
|
+
* @returns {Array}
|
|
717
|
+
*/
|
|
718
|
+
export const shuffle=(arr)=>{
|
|
719
|
+
let len = arr.length;
|
|
720
|
+
for(let i=len-1;i>=0;i--){
|
|
721
|
+
let randIdx = Rand(0,i);
|
|
722
|
+
let temp = arr[randIdx];
|
|
723
|
+
arr[randIdx] = arr[i];
|
|
724
|
+
arr[i] = temp;
|
|
725
|
+
}
|
|
726
|
+
return arr;
|
|
727
|
+
}
|