@zw-team/react-lib 1.0.1
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/README.md +207 -0
- package/dist/components/AccessReport/index.d.ts +29 -0
- package/dist/components/AccessReport/index.js +129 -0
- package/dist/components/Avatar/Avatar.d.ts +3 -0
- package/dist/components/Avatar/Avatar.js +58 -0
- package/dist/components/Avatar/index.d.ts +2 -0
- package/dist/components/Avatar/index.js +2 -0
- package/dist/components/Avatar/types.d.ts +9 -0
- package/dist/components/Avatar/types.js +0 -0
- package/dist/components/Block/Block.css +8 -0
- package/dist/components/Block/Block.d.ts +4 -0
- package/dist/components/Block/Block.js +11 -0
- package/dist/components/Block/index.d.ts +2 -0
- package/dist/components/Block/index.js +2 -0
- package/dist/components/Block/types.d.ts +3 -0
- package/dist/components/Block/types.js +0 -0
- package/dist/components/ConfigProvider/ConfigContext.d.ts +4 -0
- package/dist/components/ConfigProvider/ConfigContext.js +19 -0
- package/dist/components/ConfigProvider/ConfigProvider.d.ts +4 -0
- package/dist/components/ConfigProvider/ConfigProvider.js +57 -0
- package/dist/components/ConfigProvider/index.d.ts +2 -0
- package/dist/components/ConfigProvider/index.js +2 -0
- package/dist/components/ConfigProvider/types.d.ts +19 -0
- package/dist/components/ConfigProvider/types.js +0 -0
- package/dist/components/CustomColumn/CustomColumn.d.ts +4 -0
- package/dist/components/CustomColumn/CustomColumn.js +388 -0
- package/dist/components/CustomColumn/CustomColumn.scss +135 -0
- package/dist/components/CustomColumn/index.d.ts +2 -0
- package/dist/components/CustomColumn/index.js +2 -0
- package/dist/components/CustomColumn/types.d.ts +19 -0
- package/dist/components/CustomColumn/types.js +0 -0
- package/dist/components/DatePicker/DatePicker.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.js +89 -0
- package/dist/components/DatePicker/datePickerOption.d.ts +14 -0
- package/dist/components/DatePicker/datePickerOption.js +149 -0
- package/dist/components/DatePicker/index.d.ts +2 -0
- package/dist/components/DatePicker/index.js +2 -0
- package/dist/components/DatePicker/types.d.ts +12 -0
- package/dist/components/DatePicker/types.js +0 -0
- package/dist/components/DatePickerPanel/DatePickerPanel.d.ts +6 -0
- package/dist/components/DatePickerPanel/DatePickerPanel.js +397 -0
- package/dist/components/DatePickerPanel/datePickerPanel.scss +362 -0
- package/dist/components/DatePickerPanel/index.d.ts +2 -0
- package/dist/components/DatePickerPanel/index.js +2 -0
- package/dist/components/DatePickerPanel/type.d.ts +23 -0
- package/dist/components/DatePickerPanel/type.js +0 -0
- package/dist/components/DownloadCenter/DownloadCenter.d.ts +5 -0
- package/dist/components/DownloadCenter/DownloadCenter.js +367 -0
- package/dist/components/DownloadCenter/index.css +54 -0
- package/dist/components/DownloadCenter/index.d.ts +2 -0
- package/dist/components/DownloadCenter/index.js +2 -0
- package/dist/components/DownloadCenter/types.d.ts +27 -0
- package/dist/components/DownloadCenter/types.js +0 -0
- package/dist/components/Fireworks/Fireworks.d.ts +11 -0
- package/dist/components/Fireworks/Fireworks.js +415 -0
- package/dist/components/Fireworks/imgs/birthday-cake.svg +180 -0
- package/dist/components/Fireworks/imgs/hb.png +0 -0
- package/dist/components/Fireworks/imgs/sd.png +0 -0
- package/dist/components/Fireworks/imgs/xc.png +0 -0
- package/dist/components/Fireworks/imgs/yd.png +0 -0
- package/dist/components/Fireworks/index.d.ts +2 -0
- package/dist/components/Fireworks/index.js +2 -0
- package/dist/components/Fireworks/index.scss +9 -0
- package/dist/components/Fireworks/types.d.ts +6 -0
- package/dist/components/Fireworks/types.js +0 -0
- package/dist/components/Form/Form.css +4 -0
- package/dist/components/Form/Form.d.ts +9 -0
- package/dist/components/Form/Form.js +18 -0
- package/dist/components/Form/index.d.ts +1 -0
- package/dist/components/Form/index.js +2 -0
- package/dist/components/FormItem/FormItem.css +38 -0
- package/dist/components/FormItem/FormItem.d.ts +9 -0
- package/dist/components/FormItem/FormItem.js +25 -0
- package/dist/components/FormItem/index.d.ts +1 -0
- package/dist/components/FormItem/index.js +2 -0
- package/dist/components/HomeData/HomeData.d.ts +6 -0
- package/dist/components/HomeData/HomeData.js +364 -0
- package/dist/components/HomeData/HomeData.scss +161 -0
- package/dist/components/HomeData/index.d.ts +1 -0
- package/dist/components/HomeData/index.js +2 -0
- package/dist/components/Icon/Icon.d.ts +4 -0
- package/dist/components/Icon/Icon.js +34 -0
- package/dist/components/Icon/index.d.ts +2 -0
- package/dist/components/Icon/index.js +2 -0
- package/dist/components/Icon/types.d.ts +8 -0
- package/dist/components/Icon/types.js +0 -0
- package/dist/components/Log/index.d.ts +2 -0
- package/dist/components/Log/index.js +2 -0
- package/dist/components/Log/src/Detail.d.ts +7 -0
- package/dist/components/Log/src/Detail.js +71 -0
- package/dist/components/Log/src/Detail.scss +27 -0
- package/dist/components/Log/src/Log.d.ts +5 -0
- package/dist/components/Log/src/Log.js +335 -0
- package/dist/components/Log/src/Log.scss +50 -0
- package/dist/components/Log/src/useLogTableColumns.d.ts +2 -0
- package/dist/components/Log/src/useLogTableColumns.js +141 -0
- package/dist/components/Log/types.d.ts +5 -0
- package/dist/components/Log/types.js +0 -0
- package/dist/components/LogButton/LogButton.d.ts +4 -0
- package/dist/components/LogButton/LogButton.js +30 -0
- package/dist/components/LogButton/index.d.ts +2 -0
- package/dist/components/LogButton/index.js +2 -0
- package/dist/components/LogButton/logbutton.css +15 -0
- package/dist/components/LogButton/types.d.ts +10 -0
- package/dist/components/LogButton/types.js +0 -0
- package/dist/components/LogDialog/BiLogManager.d.ts +29 -0
- package/dist/components/LogDialog/BiLogManager.js +78 -0
- package/dist/components/LogDialog/LogDialog.d.ts +8 -0
- package/dist/components/LogDialog/LogDialog.js +106 -0
- package/dist/components/LogDialog/LogDialog.scss +29 -0
- package/dist/components/LogDialog/index.d.ts +3 -0
- package/dist/components/LogDialog/index.js +3 -0
- package/dist/components/LogDialog/types.d.ts +8 -0
- package/dist/components/LogDialog/types.js +0 -0
- package/dist/components/MediaPreview/MediaPreview.d.ts +5 -0
- package/dist/components/MediaPreview/MediaPreview.js +124 -0
- package/dist/components/MediaPreview/hook.d.ts +26 -0
- package/dist/components/MediaPreview/hook.js +174 -0
- package/dist/components/MediaPreview/index.css +202 -0
- package/dist/components/MediaPreview/index.d.ts +2 -0
- package/dist/components/MediaPreview/index.js +2 -0
- package/dist/components/MediaPreview/types.d.ts +24 -0
- package/dist/components/MediaPreview/types.js +0 -0
- package/dist/components/Modal/Modal.d.ts +3 -0
- package/dist/components/Modal/Modal.js +31 -0
- package/dist/components/Modal/index.d.ts +2 -0
- package/dist/components/Modal/index.js +2 -0
- package/dist/components/Modal/types.d.ts +8 -0
- package/dist/components/Modal/types.js +0 -0
- package/dist/components/ModalStore/ModalProvider.d.ts +11 -0
- package/dist/components/ModalStore/ModalProvider.js +15 -0
- package/dist/components/ModalStore/ModalStore.d.ts +78 -0
- package/dist/components/ModalStore/ModalStore.js +188 -0
- package/dist/components/ModalStore/index.d.ts +3 -0
- package/dist/components/ModalStore/index.js +4 -0
- package/dist/components/ModalStore/types.d.ts +73 -0
- package/dist/components/ModalStore/types.js +0 -0
- package/dist/components/MoreButton/MoreButton.d.ts +3 -0
- package/dist/components/MoreButton/MoreButton.js +50 -0
- package/dist/components/MoreButton/index.d.ts +2 -0
- package/dist/components/MoreButton/index.js +2 -0
- package/dist/components/MoreButton/types.d.ts +15 -0
- package/dist/components/MoreButton/types.js +0 -0
- package/dist/components/NavbarTool/NavbarTool.d.ts +5 -0
- package/dist/components/NavbarTool/NavbarTool.js +143 -0
- package/dist/components/NavbarTool/components/index.css +49 -0
- package/dist/components/NavbarTool/components/index.d.ts +5 -0
- package/dist/components/NavbarTool/components/index.js +98 -0
- package/dist/components/NavbarTool/index.css +14 -0
- package/dist/components/NavbarTool/index.d.ts +2 -0
- package/dist/components/NavbarTool/index.js +2 -0
- package/dist/components/NavbarTool/types.d.ts +40 -0
- package/dist/components/NavbarTool/types.js +0 -0
- package/dist/components/NoticeCenter/NoticeCenter.d.ts +4 -0
- package/dist/components/NoticeCenter/NoticeCenter.js +334 -0
- package/dist/components/NoticeCenter/assets/notice.png +0 -0
- package/dist/components/NoticeCenter/assets/tongzhi.png +0 -0
- package/dist/components/NoticeCenter/index.d.ts +2 -0
- package/dist/components/NoticeCenter/index.js +2 -0
- package/dist/components/NoticeCenter/noticeCenter.scss +232 -0
- package/dist/components/NoticeCenter/types.d.ts +6 -0
- package/dist/components/NoticeCenter/types.js +0 -0
- package/dist/components/Pagination/BiPagination.css +152 -0
- package/dist/components/Pagination/Pagination.d.ts +5 -0
- package/dist/components/Pagination/Pagination.js +67 -0
- package/dist/components/Pagination/index.d.ts +2 -0
- package/dist/components/Pagination/index.js +2 -0
- package/dist/components/Pagination/types.d.ts +14 -0
- package/dist/components/Pagination/types.js +0 -0
- package/dist/components/ResponseInterceptor/index.d.ts +17 -0
- package/dist/components/ResponseInterceptor/index.js +43 -0
- package/dist/components/SuperDate/SuperDate.d.ts +6 -0
- package/dist/components/SuperDate/SuperDate.js +113 -0
- package/dist/components/SuperDate/SuperDate.scss +42 -0
- package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.d.ts +5 -0
- package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.js +87 -0
- package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.scss +52 -0
- package/dist/components/SuperDate/components/DynamicTimeCom/DynamicTimeCom.d.ts +6 -0
- package/dist/components/SuperDate/components/DynamicTimeCom/DynamicTimeCom.js +129 -0
- package/dist/components/SuperDate/components/DynamicTimeCom/dynamicTimeCom.scss +70 -0
- package/dist/components/SuperDate/constant.d.ts +35 -0
- package/dist/components/SuperDate/constant.js +27 -0
- package/dist/components/SuperDate/index.d.ts +2 -0
- package/dist/components/SuperDate/index.js +2 -0
- package/dist/components/SuperDate/store.d.ts +68 -0
- package/dist/components/SuperDate/store.js +254 -0
- package/dist/components/SuperDate/types.d.ts +34 -0
- package/dist/components/SuperDate/types.js +0 -0
- package/dist/components/SuperDate/utils.d.ts +18 -0
- package/dist/components/SuperDate/utils.js +14 -0
- package/dist/components/SystemLink/SystemLink.d.ts +4 -0
- package/dist/components/SystemLink/SystemLink.js +85 -0
- package/dist/components/SystemLink/index.d.ts +1 -0
- package/dist/components/SystemLink/index.js +2 -0
- package/dist/components/SystemLink/index.scss +142 -0
- package/dist/components/Table/ResizableTitle.d.ts +3 -0
- package/dist/components/Table/ResizableTitle.js +43 -0
- package/dist/components/Table/Table.d.ts +9 -0
- package/dist/components/Table/Table.js +189 -0
- package/dist/components/Table/index.d.ts +2 -0
- package/dist/components/Table/index.js +2 -0
- package/dist/components/Table/index.scss +42 -0
- package/dist/components/Table/types.d.ts +24 -0
- package/dist/components/Table/types.js +0 -0
- package/dist/components/Table/useHeaderPopper.d.ts +8 -0
- package/dist/components/Table/useHeaderPopper.js +95 -0
- package/dist/components/TableHeaderPopper/EditBox.d.ts +6 -0
- package/dist/components/TableHeaderPopper/EditBox.js +208 -0
- package/dist/components/TableHeaderPopper/Popover.d.ts +6 -0
- package/dist/components/TableHeaderPopper/Popover.js +85 -0
- package/dist/components/TableHeaderPopper/index.d.ts +3 -0
- package/dist/components/TableHeaderPopper/index.js +3 -0
- package/dist/components/TableHeaderPopper/index.scss +96 -0
- package/dist/components/TaskCenter/TaskCenter.d.ts +4 -0
- package/dist/components/TaskCenter/TaskCenter.js +257 -0
- package/dist/components/TaskCenter/TaskCenter.scss +44 -0
- package/dist/components/TaskCenter/api.d.ts +13 -0
- package/dist/components/TaskCenter/api.js +13 -0
- package/dist/components/TaskCenter/index.d.ts +2 -0
- package/dist/components/TaskCenter/index.js +2 -0
- package/dist/components/TaskCenter/types.d.ts +29 -0
- package/dist/components/TaskCenter/types.js +0 -0
- package/dist/components/TooltipIcon/TooltipIcon.d.ts +3 -0
- package/dist/components/TooltipIcon/TooltipIcon.js +43 -0
- package/dist/components/TooltipIcon/index.d.ts +2 -0
- package/dist/components/TooltipIcon/index.js +2 -0
- package/dist/components/TooltipIcon/types.d.ts +14 -0
- package/dist/components/TooltipIcon/types.js +0 -0
- package/dist/components/Verification/content.d.ts +11 -0
- package/dist/components/Verification/content.js +223 -0
- package/dist/components/Verification/index.css +43 -0
- package/dist/components/Verification/index.d.ts +1 -0
- package/dist/components/Verification/index.js +37 -0
- package/dist/components/index.d.ts +32 -0
- package/dist/components/index.js +29 -0
- package/dist/config/index.d.ts +83 -0
- package/dist/config/index.js +115 -0
- package/dist/config/theme/index.d.ts +368 -0
- package/dist/config/theme/index.js +369 -0
- package/dist/hooks/createAlive.d.ts +11 -0
- package/dist/hooks/createAlive.js +22 -0
- package/dist/hooks/createGlobalState.d.ts +7 -0
- package/dist/hooks/createGlobalState.js +28 -0
- package/dist/hooks/index.d.ts +26 -0
- package/dist/hooks/index.js +25 -0
- package/dist/hooks/useAsync.d.ts +27 -0
- package/dist/hooks/useAsync.js +76 -0
- package/dist/hooks/useClickOther.d.ts +10 -0
- package/dist/hooks/useClickOther.js +30 -0
- package/dist/hooks/useCopyToClipboard.d.ts +7 -0
- package/dist/hooks/useCopyToClipboard.js +32 -0
- package/dist/hooks/useCreate.d.ts +7 -0
- package/dist/hooks/useCreate.js +21 -0
- package/dist/hooks/useEventListener.d.ts +22 -0
- package/dist/hooks/useEventListener.js +33 -0
- package/dist/hooks/useHistoryStore.d.ts +16 -0
- package/dist/hooks/useHistoryStore.js +106 -0
- package/dist/hooks/useIntersectionObserver.d.ts +8 -0
- package/dist/hooks/useIntersectionObserver.js +23 -0
- package/dist/hooks/useInterval.d.ts +8 -0
- package/dist/hooks/useInterval.js +19 -0
- package/dist/hooks/useLatest.d.ts +2 -0
- package/dist/hooks/useLatest.js +12 -0
- package/dist/hooks/useLockAsyncFn.d.ts +7 -0
- package/dist/hooks/useLockAsyncFn.js +24 -0
- package/dist/hooks/useLockFn.d.ts +7 -0
- package/dist/hooks/useLockFn.js +17 -0
- package/dist/hooks/useMergedState.d.ts +10 -0
- package/dist/hooks/useMergedState.js +30 -0
- package/dist/hooks/useMountedState.d.ts +4 -0
- package/dist/hooks/useMountedState.js +13 -0
- package/dist/hooks/usePermission.d.ts +8 -0
- package/dist/hooks/usePermission.js +21 -0
- package/dist/hooks/usePersistFn.d.ts +8 -0
- package/dist/hooks/usePersistFn.js +13 -0
- package/dist/hooks/useReactive.d.ts +7 -0
- package/dist/hooks/useReactive.js +34 -0
- package/dist/hooks/useRefresh.d.ts +5 -0
- package/dist/hooks/useRefresh.js +8 -0
- package/dist/hooks/useToggle.d.ts +16 -0
- package/dist/hooks/useToggle.js +20 -0
- package/dist/hooks/useUnmount.d.ts +6 -0
- package/dist/hooks/useUnmount.js +10 -0
- package/dist/hooks/useUpdateEffect.d.ts +9 -0
- package/dist/hooks/useUpdateEffect.js +10 -0
- package/dist/hooks/useWindowSize.d.ts +6 -0
- package/dist/hooks/useWindowSize.js +15 -0
- package/dist/hooks/util.d.ts +9 -0
- package/dist/hooks/util.js +6 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/utils/array.d.ts +12 -0
- package/dist/utils/array.js +15 -0
- package/dist/utils/classNames.d.ts +4 -0
- package/dist/utils/classNames.js +19 -0
- package/dist/utils/date.d.ts +98 -0
- package/dist/utils/date.js +101 -0
- package/dist/utils/debounce.d.ts +8 -0
- package/dist/utils/debounce.js +38 -0
- package/dist/utils/deepClone.d.ts +6 -0
- package/dist/utils/deepClone.js +10 -0
- package/dist/utils/empty.d.ts +16 -0
- package/dist/utils/empty.js +24 -0
- package/dist/utils/formatPrice.d.ts +2 -0
- package/dist/utils/formatPrice.js +15 -0
- package/dist/utils/getUUID.d.ts +1 -0
- package/dist/utils/getUUID.js +17 -0
- package/dist/utils/getUrlParams.d.ts +11 -0
- package/dist/utils/getUrlParams.js +10 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/listToTree.d.ts +12 -0
- package/dist/utils/listToTree.js +14 -0
- package/dist/utils/object.d.ts +6 -0
- package/dist/utils/object.js +5 -0
- package/dist/utils/ossUpload.d.ts +45 -0
- package/dist/utils/ossUpload.js +88 -0
- package/dist/utils/parseTo.d.ts +6 -0
- package/dist/utils/parseTo.js +9 -0
- package/dist/utils/request/accessReport.d.ts +2 -0
- package/dist/utils/request/accessReport.js +27 -0
- package/dist/utils/request/defaultRequest.d.ts +9 -0
- package/dist/utils/request/defaultRequest.js +33 -0
- package/dist/utils/request/exportDownload.d.ts +2 -0
- package/dist/utils/request/exportDownload.js +28 -0
- package/dist/utils/request/index.d.ts +29 -0
- package/dist/utils/request/index.js +40 -0
- package/dist/utils/request/noticeCenter.d.ts +2 -0
- package/dist/utils/request/noticeCenter.js +28 -0
- package/dist/utils/svgIcon/index.d.ts +47 -0
- package/dist/utils/svgIcon/index.js +76 -0
- package/dist/utils/throttle.d.ts +10 -0
- package/dist/utils/throttle.js +21 -0
- package/dist/utils/time/index.d.ts +7 -0
- package/dist/utils/time/index.js +12 -0
- package/dist/utils/tools.d.ts +43 -0
- package/dist/utils/tools.js +57 -0
- package/package.json +116 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将一个大数组转换为指定数量的小数组
|
|
3
|
+
* @param array 要分割的数组
|
|
4
|
+
* @param size 分割后每个数组的长度
|
|
5
|
+
*/
|
|
6
|
+
export declare const chunkArray: <T>(array: T[], size?: number) => T[][];
|
|
7
|
+
/**
|
|
8
|
+
* 去除数组中重复的对象
|
|
9
|
+
* @param arr 原数组
|
|
10
|
+
* @param key 去重依据的key值
|
|
11
|
+
*/
|
|
12
|
+
export declare const uniqueArrayObject: <T>(arr: T[], key: keyof T) => T[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const chunkArray = (array, size = 1)=>array.reduce((rows, currentValue, index)=>{
|
|
2
|
+
if (index % size === 0) rows.push([
|
|
3
|
+
currentValue
|
|
4
|
+
]);
|
|
5
|
+
else rows[rows.length - 1].push(currentValue);
|
|
6
|
+
return rows;
|
|
7
|
+
}, []);
|
|
8
|
+
const uniqueArrayObject = (arr, key)=>arr.reduce((acc, cur)=>{
|
|
9
|
+
const keys = acc.map((v)=>v[key]);
|
|
10
|
+
return keys.includes(cur[key]) ? acc : [
|
|
11
|
+
...acc,
|
|
12
|
+
cur
|
|
13
|
+
];
|
|
14
|
+
}, []);
|
|
15
|
+
export { chunkArray, uniqueArrayObject };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const classNames = (...args)=>{
|
|
2
|
+
const classes = [];
|
|
3
|
+
for (const arg of args){
|
|
4
|
+
if (!arg) continue;
|
|
5
|
+
const argType = typeof arg;
|
|
6
|
+
if ('string' === argType || 'number' === argType) classes.push(arg);
|
|
7
|
+
else if (Array.isArray(arg)) {
|
|
8
|
+
if (arg.length > 0) {
|
|
9
|
+
const inner = classNames(...arg);
|
|
10
|
+
if (inner) classes.push(inner);
|
|
11
|
+
}
|
|
12
|
+
} else if ('object' === argType) {
|
|
13
|
+
if (arg.toString !== Object.prototype.toString) classes.push(arg.toString());
|
|
14
|
+
else for(const key in arg)if (Object.hasOwn(arg, key) && arg[key]) classes.push(key);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return classes.join(' ');
|
|
18
|
+
};
|
|
19
|
+
export { classNames };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轻量级日期工具函数,替代moment.js减少包体积
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 日期范围接口
|
|
6
|
+
*/
|
|
7
|
+
export interface DateRange {
|
|
8
|
+
/** 开始时间 */
|
|
9
|
+
start: string;
|
|
10
|
+
/** 结束时间 */
|
|
11
|
+
end: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 日期格式化函数
|
|
15
|
+
* @param date 日期对象或日期字符串
|
|
16
|
+
* @param format 日期格式,默认为'YYYY-MM-DD'
|
|
17
|
+
* @returns 格式化后的日期字符串
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatDate(date: Date | string | number | null | undefined, format?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 获取今天的开始和结束时间
|
|
22
|
+
* @returns 包含开始和结束时间的对象
|
|
23
|
+
*/
|
|
24
|
+
export declare function getToday(): DateRange;
|
|
25
|
+
/**
|
|
26
|
+
* 获取昨天的开始和结束时间
|
|
27
|
+
* @returns 包含开始和结束时间的对象
|
|
28
|
+
*/
|
|
29
|
+
export declare function getYesterday(): DateRange;
|
|
30
|
+
/**
|
|
31
|
+
* 获取最近几天的开始和结束时间
|
|
32
|
+
* @param days 天数
|
|
33
|
+
* @returns 包含开始和结束时间的对象
|
|
34
|
+
*/
|
|
35
|
+
export declare function getRecentDays(days: number): DateRange;
|
|
36
|
+
/**
|
|
37
|
+
* 获取本月开始和结束时间
|
|
38
|
+
* @returns 包含开始和结束时间的对象
|
|
39
|
+
*/
|
|
40
|
+
export declare function getCurrentMonth(): DateRange;
|
|
41
|
+
/**
|
|
42
|
+
* 获取上月开始和结束时间
|
|
43
|
+
* @returns 包含开始和结束时间的对象
|
|
44
|
+
*/
|
|
45
|
+
export declare function getLastMonth(): DateRange;
|
|
46
|
+
/**
|
|
47
|
+
* 获取本年开始和结束时间
|
|
48
|
+
* @returns 包含开始和结束时间的对象
|
|
49
|
+
*/
|
|
50
|
+
export declare function getCurrentYear(): DateRange;
|
|
51
|
+
/**
|
|
52
|
+
* 计算两个日期之间的秒数差异
|
|
53
|
+
* @param date1 第一个日期
|
|
54
|
+
* @param date2 第二个日期
|
|
55
|
+
* @param format 日期格式(仅当date1和date2为字符串时有效)
|
|
56
|
+
* @returns 两个日期之间的秒数差异(绝对值)
|
|
57
|
+
*/
|
|
58
|
+
export declare function dateDiff(date1: Date | string | number, date2: Date | string | number, format?: string): number;
|
|
59
|
+
/**
|
|
60
|
+
* 在日期上添加指定天数
|
|
61
|
+
* @param date 原始日期
|
|
62
|
+
* @param days 要添加的天数
|
|
63
|
+
* @returns 新的日期对象
|
|
64
|
+
*/
|
|
65
|
+
export declare function addDays(date: Date | string | number, days: number): Date;
|
|
66
|
+
/**
|
|
67
|
+
* 在日期上添加指定月数
|
|
68
|
+
* @param date 原始日期
|
|
69
|
+
* @param months 要添加的月数
|
|
70
|
+
* @returns 新的日期对象
|
|
71
|
+
*/
|
|
72
|
+
export declare function addMonths(date: Date | string | number, months: number): Date;
|
|
73
|
+
/**
|
|
74
|
+
* 在日期上减去指定天数
|
|
75
|
+
* @param date 原始日期
|
|
76
|
+
* @param days 要减去的天数
|
|
77
|
+
* @returns 新的日期对象
|
|
78
|
+
*/
|
|
79
|
+
export declare function subtractDays(date: Date | string | number, days: number): Date;
|
|
80
|
+
/**
|
|
81
|
+
* 在日期上减去指定月数
|
|
82
|
+
* @param date 原始日期
|
|
83
|
+
* @param months 要减去的月数
|
|
84
|
+
* @returns 新的日期对象
|
|
85
|
+
*/
|
|
86
|
+
export declare function subtractMonths(date: Date | string | number, months: number): Date;
|
|
87
|
+
/**
|
|
88
|
+
* 获取指定日期所在月份的第一天
|
|
89
|
+
* @param date 原始日期
|
|
90
|
+
* @returns 月份第一天的日期对象
|
|
91
|
+
*/
|
|
92
|
+
export declare function getMonthStart(date: Date | string | number): Date;
|
|
93
|
+
/**
|
|
94
|
+
* 获取指定日期所在月份的最后一天
|
|
95
|
+
* @param date 原始日期
|
|
96
|
+
* @returns 月份最后一天的日期对象
|
|
97
|
+
*/
|
|
98
|
+
export declare function getMonthEnd(date: Date | string | number): Date;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
function formatDate(date, format = 'YYYY-MM-DD') {
|
|
2
|
+
if (!date) return '';
|
|
3
|
+
const d = new Date(date);
|
|
4
|
+
if (isNaN(d.getTime())) return '';
|
|
5
|
+
const year = d.getFullYear();
|
|
6
|
+
const month = String(d.getMonth() + 1).padStart(2, '0');
|
|
7
|
+
const day = String(d.getDate()).padStart(2, '0');
|
|
8
|
+
const hour = String(d.getHours()).padStart(2, '0');
|
|
9
|
+
const minute = String(d.getMinutes()).padStart(2, '0');
|
|
10
|
+
const second = String(d.getSeconds()).padStart(2, '0');
|
|
11
|
+
return format.replace('YYYY', year.toString()).replace('MM', month).replace('DD', day).replace('HH', hour).replace('mm', minute).replace('ss', second);
|
|
12
|
+
}
|
|
13
|
+
function getToday() {
|
|
14
|
+
const today = new Date();
|
|
15
|
+
const start = formatDate(today, 'YYYY-MM-DD') + ' 00:00:00';
|
|
16
|
+
const end = formatDate(today, 'YYYY-MM-DD') + ' 23:59:59';
|
|
17
|
+
return {
|
|
18
|
+
start,
|
|
19
|
+
end
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function getYesterday() {
|
|
23
|
+
const yesterday = new Date();
|
|
24
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
25
|
+
const start = formatDate(yesterday, 'YYYY-MM-DD') + ' 00:00:00';
|
|
26
|
+
const end = formatDate(yesterday, 'YYYY-MM-DD') + ' 23:59:59';
|
|
27
|
+
return {
|
|
28
|
+
start,
|
|
29
|
+
end
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getRecentDays(days) {
|
|
33
|
+
const end = new Date();
|
|
34
|
+
const start = new Date();
|
|
35
|
+
start.setDate(start.getDate() - days);
|
|
36
|
+
return {
|
|
37
|
+
start: formatDate(start, 'YYYY-MM-DD') + ' 00:00:00',
|
|
38
|
+
end: formatDate(end, 'YYYY-MM-DD') + ' 23:59:59'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function getCurrentMonth() {
|
|
42
|
+
const now = new Date();
|
|
43
|
+
const start = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
44
|
+
const end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
|
45
|
+
return {
|
|
46
|
+
start: formatDate(start, 'YYYY-MM-DD') + ' 00:00:00',
|
|
47
|
+
end: formatDate(end, 'YYYY-MM-DD') + ' 23:59:59'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getLastMonth() {
|
|
51
|
+
const now = new Date();
|
|
52
|
+
const start = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
53
|
+
const end = new Date(now.getFullYear(), now.getMonth(), 0);
|
|
54
|
+
return {
|
|
55
|
+
start: formatDate(start, 'YYYY-MM-DD') + ' 00:00:00',
|
|
56
|
+
end: formatDate(end, 'YYYY-MM-DD') + ' 23:59:59'
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getCurrentYear() {
|
|
60
|
+
const now = new Date();
|
|
61
|
+
const start = new Date(now.getFullYear(), 0, 1);
|
|
62
|
+
const end = new Date(now.getFullYear(), 11, 31);
|
|
63
|
+
return {
|
|
64
|
+
start: formatDate(start, 'YYYY-MM-DD') + ' 00:00:00',
|
|
65
|
+
end: formatDate(end, 'YYYY-MM-DD') + ' 23:59:59'
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function dateDiff(date1, date2, format = 'YYYY-MM-DD HH:mm:ss') {
|
|
69
|
+
const time1 = 'string' == typeof date1 ? new Date(date1.replace(/-/g, '/')) : new Date(date1);
|
|
70
|
+
const time2 = 'string' == typeof date2 ? new Date(date2.replace(/-/g, '/')) : new Date(date2);
|
|
71
|
+
if (isNaN(time1.getTime()) || isNaN(time2.getTime())) {
|
|
72
|
+
console.warn('Invalid date provided to dateDiff function');
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
return Math.abs(time2.getTime() - time1.getTime()) / 1000;
|
|
76
|
+
}
|
|
77
|
+
function addDays(date, days) {
|
|
78
|
+
const result = new Date(date);
|
|
79
|
+
result.setDate(result.getDate() + days);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
function addMonths(date, months) {
|
|
83
|
+
const result = new Date(date);
|
|
84
|
+
result.setMonth(result.getMonth() + months);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
function subtractDays(date, days) {
|
|
88
|
+
return addDays(date, -days);
|
|
89
|
+
}
|
|
90
|
+
function subtractMonths(date, months) {
|
|
91
|
+
return addMonths(date, -months);
|
|
92
|
+
}
|
|
93
|
+
function getMonthStart(date) {
|
|
94
|
+
const d = new Date(date);
|
|
95
|
+
return new Date(d.getFullYear(), d.getMonth(), 1);
|
|
96
|
+
}
|
|
97
|
+
function getMonthEnd(date) {
|
|
98
|
+
const d = new Date(date);
|
|
99
|
+
return new Date(d.getFullYear(), d.getMonth() + 1, 0);
|
|
100
|
+
}
|
|
101
|
+
export { addDays, addMonths, dateDiff, formatDate, getCurrentMonth, getCurrentYear, getLastMonth, getMonthEnd, getMonthStart, getRecentDays, getToday, getYesterday, subtractDays, subtractMonths };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Procedure = (...args: any[]) => any;
|
|
2
|
+
export type Options<TT> = {
|
|
3
|
+
isImmediate?: boolean;
|
|
4
|
+
maxWait?: number;
|
|
5
|
+
callback?: (data: TT) => void;
|
|
6
|
+
};
|
|
7
|
+
declare const debounce: <F extends Procedure>(func: F, wait?: number, options?: Options<ReturnType<F>>) => (this: ThisParameterType<F>, ...args: Parameters<F>) => Promise<ReturnType<F>>;
|
|
8
|
+
export default debounce;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const debounce = (func, wait = 300, options = {})=>{
|
|
2
|
+
let timeoutId;
|
|
3
|
+
const isImmediate = options.isImmediate ?? false;
|
|
4
|
+
const callback = options.callback ?? false;
|
|
5
|
+
const maxWait = options.maxWait;
|
|
6
|
+
let lastInvokeTime = Date.now();
|
|
7
|
+
const nextInvokeTimeout = ()=>{
|
|
8
|
+
if (void 0 !== maxWait) {
|
|
9
|
+
const timeSinceLastInvocation = Date.now() - lastInvokeTime;
|
|
10
|
+
if (timeSinceLastInvocation + wait >= maxWait) return maxWait - timeSinceLastInvocation;
|
|
11
|
+
}
|
|
12
|
+
return wait;
|
|
13
|
+
};
|
|
14
|
+
const debounced = function(...args) {
|
|
15
|
+
const context = this;
|
|
16
|
+
return new Promise((resolve)=>{
|
|
17
|
+
const invokeFunction = function() {
|
|
18
|
+
timeoutId = void 0;
|
|
19
|
+
lastInvokeTime = Date.now();
|
|
20
|
+
if (!isImmediate) {
|
|
21
|
+
const result = func.apply(context, args);
|
|
22
|
+
callback && callback(result);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const shouldCallNow = isImmediate && void 0 === timeoutId;
|
|
26
|
+
if (void 0 !== timeoutId) clearTimeout(timeoutId);
|
|
27
|
+
timeoutId = setTimeout(invokeFunction, nextInvokeTimeout());
|
|
28
|
+
if (shouldCallNow) {
|
|
29
|
+
const result = func.apply(context, args);
|
|
30
|
+
callback && callback(result);
|
|
31
|
+
return resolve(result);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
return debounced;
|
|
36
|
+
};
|
|
37
|
+
const utils_debounce = debounce;
|
|
38
|
+
export { utils_debounce as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const deepClone_deepClone = (obj)=>{
|
|
2
|
+
if (!obj) return;
|
|
3
|
+
const clone = {
|
|
4
|
+
...obj
|
|
5
|
+
};
|
|
6
|
+
Object.keys(clone).forEach((key)=>clone[key] = 'object' == typeof obj[key] ? deepClone_deepClone(obj[key]) : obj[key]);
|
|
7
|
+
return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone;
|
|
8
|
+
};
|
|
9
|
+
const deepClone = deepClone_deepClone;
|
|
10
|
+
export { deepClone as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检测是否不是null
|
|
3
|
+
*/
|
|
4
|
+
export declare const isNotNull: (value: unknown) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* 检测是否是null
|
|
7
|
+
*/
|
|
8
|
+
export declare const isNull: (value: unknown) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 检测是否是空(数组、对象、字符串、undefined、null)
|
|
11
|
+
*/
|
|
12
|
+
export declare const isEmpty: (val: unknown) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 检测是否不是空(数组、对象、字符串、undefined、null)
|
|
15
|
+
*/
|
|
16
|
+
export declare const isNotEmpty: (val: unknown) => boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const isNotNull = (value)=>null !== value;
|
|
2
|
+
const isNull = (value)=>null === value;
|
|
3
|
+
const isEmpty = (val)=>{
|
|
4
|
+
if (Array.isArray(val) && 0 === val.length) return true;
|
|
5
|
+
if ('object' == typeof val) {
|
|
6
|
+
if (!val || 0 === Object.keys(val).length) return true;
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (null == val || '' === val) return true;
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
const isNotEmpty = (val)=>{
|
|
13
|
+
if (Array.isArray(val)) {
|
|
14
|
+
if (0 !== val.length) return true;
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if ('object' == typeof val) {
|
|
18
|
+
if (val && 0 !== Object.keys(val).length) return true;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (null != val && '' !== val) return true;
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
export { isEmpty, isNotEmpty, isNotNull, isNull };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const formatPrice_formatPrice = (price)=>{
|
|
2
|
+
let _price = price.toString();
|
|
3
|
+
let isDecimal = false;
|
|
4
|
+
let needZeroCount = 2;
|
|
5
|
+
for(let i = 0; i < _price.length; i++){
|
|
6
|
+
const c = _price.charAt(i);
|
|
7
|
+
if ('.' === c) isDecimal = true;
|
|
8
|
+
else if (isDecimal) needZeroCount -= 1;
|
|
9
|
+
}
|
|
10
|
+
if (1 === needZeroCount) _price += '0';
|
|
11
|
+
else if (2 === needZeroCount) _price += '.00';
|
|
12
|
+
return _price;
|
|
13
|
+
};
|
|
14
|
+
const formatPrice = formatPrice_formatPrice;
|
|
15
|
+
export { formatPrice as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getUUID(len?: number, radix?: number): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function getUUID(len = 10, radix = 10) {
|
|
2
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
3
|
+
const uuid = [];
|
|
4
|
+
radix = radix || chars.length;
|
|
5
|
+
if (len) for(let i = 0; i < len; i++)uuid[i] = chars[0 | Math.random() * radix];
|
|
6
|
+
else {
|
|
7
|
+
let r;
|
|
8
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
|
9
|
+
uuid[14] = '4';
|
|
10
|
+
for(let i = 0; i < 36; i++)if (!uuid[i]) {
|
|
11
|
+
r = 0 | 16 * Math.random();
|
|
12
|
+
uuid[i] = chars[19 === i ? 0x3 & r | 0x8 : r];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return uuid.join('');
|
|
16
|
+
}
|
|
17
|
+
export { getUUID as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type MergeValue<Val, OtherVla> = Val extends OtherVla ? Val : OtherVla extends unknown[] ? [Val, ...OtherVla] : [Val, OtherVla];
|
|
2
|
+
type ParseParam<Str extends string> = Str extends `${infer Key}=${infer Val}` ? {
|
|
3
|
+
[K in Key]: Val;
|
|
4
|
+
} : {};
|
|
5
|
+
type MergeParam<Result extends Record<string, string>, OtherResult extends Record<string, string>> = {
|
|
6
|
+
[K in keyof Result | keyof OtherResult]: K extends keyof Result ? K extends keyof OtherResult ? MergeValue<Result[K], OtherResult[K]> : Result[K] : K extends keyof OtherResult ? OtherResult[K] : never;
|
|
7
|
+
};
|
|
8
|
+
type ParseString<Str extends string> = Str extends `${infer Param}&${infer Rest}` ? MergeParam<ParseParam<Param>, ParseString<Rest>> : ParseParam<Str>;
|
|
9
|
+
type ParseQueryString<Str extends string> = Str extends `${infer Url}?${infer Qs}` ? ParseString<Qs> : ParseString<Str>;
|
|
10
|
+
declare const getUrlParams: <S extends string>(url: S) => ParseQueryString<S>;
|
|
11
|
+
export default getUrlParams;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const getUrlParams_getUrlParams = (url)=>(url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce((a, v)=>{
|
|
2
|
+
const [key, value] = v.split('=');
|
|
3
|
+
if (a[key]) a[key] = ('string' == typeof a[key] ? [
|
|
4
|
+
a[key]
|
|
5
|
+
] : a[key]).concat(value);
|
|
6
|
+
else a[key] = value;
|
|
7
|
+
return a;
|
|
8
|
+
}, {});
|
|
9
|
+
const getUrlParams = getUrlParams_getUrlParams;
|
|
10
|
+
export { getUrlParams as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './classNames';
|
|
2
|
+
export * from './date';
|
|
3
|
+
export * from './empty';
|
|
4
|
+
export * from './svgIcon';
|
|
5
|
+
export * from './time';
|
|
6
|
+
export * from './tools';
|
|
7
|
+
export * from './array';
|
|
8
|
+
export * from './object';
|
|
9
|
+
export type { OssUploadConfig, ProgressCallback, StsTokenResponse, UploadResult, } from './ossUpload';
|
|
10
|
+
export type { RequestConfig } from './request';
|
|
11
|
+
export { default as ossUpload } from './ossUpload';
|
|
12
|
+
export { default as request, SystemType } from './request';
|
|
13
|
+
export { default as debounce } from './debounce';
|
|
14
|
+
export { default as deepClone } from './deepClone';
|
|
15
|
+
export { default as formatPrice } from './formatPrice';
|
|
16
|
+
export { default as getUrlParams } from './getUrlParams';
|
|
17
|
+
export { default as getUUID } from './getUUID';
|
|
18
|
+
export { default as listToTree } from './listToTree';
|
|
19
|
+
export { default as parseTo } from './parseTo';
|
|
20
|
+
export { default as throttle } from './throttle';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ossUpload from "./ossUpload.js";
|
|
2
|
+
import request, { SystemType } from "./request/index.js";
|
|
3
|
+
import debounce from "./debounce.js";
|
|
4
|
+
import deepClone from "./deepClone.js";
|
|
5
|
+
import formatPrice from "./formatPrice.js";
|
|
6
|
+
import getUrlParams from "./getUrlParams.js";
|
|
7
|
+
import getUUID from "./getUUID.js";
|
|
8
|
+
import listToTree from "./listToTree.js";
|
|
9
|
+
import parseTo from "./parseTo.js";
|
|
10
|
+
import throttle from "./throttle.js";
|
|
11
|
+
export * from "./classNames.js";
|
|
12
|
+
export * from "./date.js";
|
|
13
|
+
export * from "./empty.js";
|
|
14
|
+
export * from "./svgIcon/index.js";
|
|
15
|
+
export * from "./time/index.js";
|
|
16
|
+
export * from "./tools.js";
|
|
17
|
+
export * from "./array.js";
|
|
18
|
+
export * from "./object.js";
|
|
19
|
+
export { SystemType, debounce, deepClone, formatPrice, getUUID, getUrlParams, listToTree, ossUpload, parseTo, request, throttle };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface List<T> {
|
|
2
|
+
id: number;
|
|
3
|
+
value: T;
|
|
4
|
+
parent: number;
|
|
5
|
+
children?: List<T>[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 将列表数据转化为树结构
|
|
9
|
+
* @param list 需要转换的列表数据
|
|
10
|
+
* @param 是否直接改变原数组
|
|
11
|
+
*/
|
|
12
|
+
export default function listToTree<T>(list: List<T>[], mutateOrigin?: boolean): List<T>[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import deepClone from "./deepClone.js";
|
|
2
|
+
function listToTree(list, mutateOrigin = true) {
|
|
3
|
+
const array = mutateOrigin ? list : deepClone(list);
|
|
4
|
+
array.forEach((outerV)=>{
|
|
5
|
+
if (0 !== Number(outerV.parent)) array.forEach((innerV)=>{
|
|
6
|
+
if (Number(innerV.id) === Number(outerV.parent)) {
|
|
7
|
+
if (!innerV.children) innerV.children = [];
|
|
8
|
+
innerV.children.push(outerV);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
return array.filter((v)=>0 === Number(v.parent));
|
|
13
|
+
}
|
|
14
|
+
export { listToTree as default };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import OSS from 'ali-oss';
|
|
2
|
+
/**
|
|
3
|
+
* OSS上传配置接口
|
|
4
|
+
*/
|
|
5
|
+
export interface OssUploadConfig {
|
|
6
|
+
/** 文件存储目录 */
|
|
7
|
+
dir?: string;
|
|
8
|
+
/** OSS区域 */
|
|
9
|
+
region?: string;
|
|
10
|
+
/** 协议 */
|
|
11
|
+
pact?: string;
|
|
12
|
+
/** 是否使用HTTPS */
|
|
13
|
+
secure?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 上传进度回调函数接口
|
|
17
|
+
*/
|
|
18
|
+
export type ProgressCallback = (progress: number, checkpoint: any, response: any) => void;
|
|
19
|
+
/**
|
|
20
|
+
* 上传结果接口
|
|
21
|
+
*/
|
|
22
|
+
export interface UploadResult {
|
|
23
|
+
status_code: number;
|
|
24
|
+
msg: string;
|
|
25
|
+
data: any;
|
|
26
|
+
config: OSS.MultipartUploadOptions;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* STS Token响应接口
|
|
30
|
+
*/
|
|
31
|
+
export interface StsTokenResponse {
|
|
32
|
+
accessKeyId: string;
|
|
33
|
+
accessKeySecret: string;
|
|
34
|
+
securityToken: string;
|
|
35
|
+
bucket: string;
|
|
36
|
+
endpoint: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* OSS文件上传工具
|
|
40
|
+
* @param file 要上传的文件对象
|
|
41
|
+
* @param config 上传配置
|
|
42
|
+
* @param progressCallback 上传进度回调函数
|
|
43
|
+
* @returns Promise<UploadResult> 上传结果
|
|
44
|
+
*/
|
|
45
|
+
export default function ossUpload(file: File, config?: OssUploadConfig, progressCallback?: ProgressCallback): Promise<UploadResult>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import ali_oss from "ali-oss";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import request from "./request/index.js";
|
|
4
|
+
import { getEnv, getSystem, randomStr } from "./tools.js";
|
|
5
|
+
async function ossUpload(file, config = {}, progressCallback) {
|
|
6
|
+
const system = getSystem();
|
|
7
|
+
const env = getEnv();
|
|
8
|
+
const uploadConfig = {
|
|
9
|
+
dir: '',
|
|
10
|
+
region: 'oss-cn-hangzhou',
|
|
11
|
+
file: null,
|
|
12
|
+
date: dayjs().format('YYYYMMDD'),
|
|
13
|
+
str: '',
|
|
14
|
+
ext: null,
|
|
15
|
+
secure: true,
|
|
16
|
+
pact: 'https://',
|
|
17
|
+
...config
|
|
18
|
+
};
|
|
19
|
+
uploadConfig.file = file;
|
|
20
|
+
uploadConfig.ext = file.name.slice(file.name.lastIndexOf('.') + 1);
|
|
21
|
+
try {
|
|
22
|
+
const tokenResponse = await request({
|
|
23
|
+
env,
|
|
24
|
+
system: 'zq',
|
|
25
|
+
api: '/common/oss/stsToken',
|
|
26
|
+
headers: {
|
|
27
|
+
System: system || ''
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const { accessKeyId, accessKeySecret, securityToken, bucket, endpoint } = tokenResponse.data;
|
|
31
|
+
const client = new ali_oss({
|
|
32
|
+
region: uploadConfig.region,
|
|
33
|
+
accessKeyId,
|
|
34
|
+
accessKeySecret,
|
|
35
|
+
stsToken: securityToken,
|
|
36
|
+
bucket,
|
|
37
|
+
secure: true,
|
|
38
|
+
endpoint,
|
|
39
|
+
cname: true,
|
|
40
|
+
refreshSTSTokenInterval: 300000,
|
|
41
|
+
refreshSTSToken: async ()=>{
|
|
42
|
+
const refreshToken = await request({
|
|
43
|
+
env,
|
|
44
|
+
system: 'zq',
|
|
45
|
+
api: '/common/oss/stsToken',
|
|
46
|
+
headers: {
|
|
47
|
+
System: system || ''
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
accessKeyId: refreshToken.data.accessKeyId,
|
|
52
|
+
accessKeySecret: refreshToken.data.accessKeySecret,
|
|
53
|
+
stsToken: refreshToken.data.securityToken
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const fileName = randomStr(16) + '.' + uploadConfig.ext;
|
|
58
|
+
const options = {
|
|
59
|
+
progress: (p, cpt, res)=>{
|
|
60
|
+
progressCallback?.(p, cpt, res);
|
|
61
|
+
},
|
|
62
|
+
parallel: 4
|
|
63
|
+
};
|
|
64
|
+
const envPath = 'production' === env ? '/production' : '/staging';
|
|
65
|
+
const objectName = `/table_head${envPath}${uploadConfig.dir}${fileName}`;
|
|
66
|
+
const uploadResult = await client.multipartUpload(objectName, uploadConfig.file, options);
|
|
67
|
+
if (200 === uploadResult.res.status) return {
|
|
68
|
+
status_code: 1,
|
|
69
|
+
msg: '上传成功',
|
|
70
|
+
data: endpoint + uploadResult.name,
|
|
71
|
+
config: uploadConfig
|
|
72
|
+
};
|
|
73
|
+
throw {
|
|
74
|
+
status_code: -1,
|
|
75
|
+
msg: '上传失败,请稍后再试',
|
|
76
|
+
data: uploadResult,
|
|
77
|
+
config: uploadConfig
|
|
78
|
+
};
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return Promise.reject({
|
|
81
|
+
status_code: -1,
|
|
82
|
+
msg: '上传失败',
|
|
83
|
+
data: error,
|
|
84
|
+
config: uploadConfig
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export { ossUpload as default };
|