kn-cli 1.0.130 → 1.0.133
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/vite.config.js +1 -1
- package/build/webpack.config.js +2 -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,475 @@
|
|
|
1
|
+
import React,{useCallback} from 'react';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { Spin, Table } from "@/components/antd";
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import styles from './index.module.less';
|
|
7
|
+
import Column,{Wrap} from './column';
|
|
8
|
+
import { useRef } from 'react';
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
import { useState } from 'react';
|
|
11
|
+
import {useEsc} from '@/hooks';
|
|
12
|
+
import useDebounceFn from '@/hooks/useDebounceFn';
|
|
13
|
+
import { useLayoutEffect } from 'react';
|
|
14
|
+
|
|
15
|
+
export {Wrap}
|
|
16
|
+
export const SCROLL_CONFIG={x:'max-content',
|
|
17
|
+
// y:Math.max(320,window.innerHeight-500)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const updatePageSizeToLocal=(size)=>{
|
|
21
|
+
localStorage.setItem('pageSize',''+size);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const PAGE_SIZE_LIST=[10, 15, 20, 50, 100];
|
|
25
|
+
export const PAGE_SIZE_OPTIONS=PAGE_SIZE_LIST.map(size=>{
|
|
26
|
+
return {value:`${size}`,label:`${size} 条/页`}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 页面公共Table组件
|
|
31
|
+
* @param {object} [props]
|
|
32
|
+
* @param {string|function} [props.rowKey] - Table主键
|
|
33
|
+
* @param {string} [props.className] - 自定义类名
|
|
34
|
+
* @param {boolean} [props.loading] - 是否加载中
|
|
35
|
+
* @param {Array} [props.columns] - 表格列
|
|
36
|
+
* @param {Array} [props.dataSource] - 数据数组
|
|
37
|
+
* @param {object} [props.pagination] - 分页器,参考配置项或 pagination 文档,设为 false 时不展示和进行分页
|
|
38
|
+
* @param {object} [props.scroll] - 表格是否可滚动
|
|
39
|
+
* @param {object} [props.page] - 表格数据,包括数据数组、分页参数、loading等
|
|
40
|
+
* @param {number} [props.minWidth] - 表格无数据时的最小宽度限制
|
|
41
|
+
* @param {*} [props.rowSelection] - 行配置
|
|
42
|
+
* @param {*} [props.expandable] - antd的展开配置
|
|
43
|
+
* @param {boolean} [props.sticky] - 表头是否吸附固定
|
|
44
|
+
* @param {string} [props.heightMode] - 高度适配模式,默认为无限向下拓展,'inWrap':最大高度不超过父容器
|
|
45
|
+
* @param {boolean} [props.fullScreen=false] - 是否全屏展示
|
|
46
|
+
* @param {()=>void} [props.onCancelFullScreen] - 退出全屏的回调
|
|
47
|
+
* @param {(column,index)=>object} [props.onHeaderRow] -
|
|
48
|
+
* @param {JSX.Element} [props.footer] - 表格底部额外的东西
|
|
49
|
+
* @param {string|number} [props.updateCount] - 用于强制刷新table
|
|
50
|
+
* @param {array} [props.sortDirections] - 排序的顺序
|
|
51
|
+
* @param {boolean} [props.virtual=false] - 是否开启虚拟滚动,如果开启scroll必须指定值
|
|
52
|
+
*
|
|
53
|
+
* @returns {JSX.Element}
|
|
54
|
+
*/
|
|
55
|
+
const PageTable = (props) => {
|
|
56
|
+
const {
|
|
57
|
+
rowKey='id',
|
|
58
|
+
loading,
|
|
59
|
+
columns,
|
|
60
|
+
dataSource,
|
|
61
|
+
pagination,
|
|
62
|
+
scroll,
|
|
63
|
+
page,
|
|
64
|
+
minWidth=undefined,
|
|
65
|
+
sticky,
|
|
66
|
+
heightMode='default',
|
|
67
|
+
fullScreen=false,
|
|
68
|
+
onCancelFullScreen,
|
|
69
|
+
footer=null,
|
|
70
|
+
updateCount=0,
|
|
71
|
+
...others
|
|
72
|
+
} = props;
|
|
73
|
+
|
|
74
|
+
// const Table = (props?.virtual?Antd5Table:Antd4Table);
|
|
75
|
+
const domTheadName= props?.virtual?`.ant5-table-thead`:`.ant-table-thead`;
|
|
76
|
+
|
|
77
|
+
const escControl = useEsc({name:'table'});
|
|
78
|
+
/**
|
|
79
|
+
* @type {React.MutableRefObject<object>}
|
|
80
|
+
*/
|
|
81
|
+
const refTable=useRef();
|
|
82
|
+
/**
|
|
83
|
+
* @type {React.MutableRefObject<object>}
|
|
84
|
+
*/
|
|
85
|
+
const refSelf = useRef();
|
|
86
|
+
const refDestory = useRef(false);
|
|
87
|
+
/**
|
|
88
|
+
* @type {React.MutableRefObject<object>}
|
|
89
|
+
*/
|
|
90
|
+
const refFooter = useRef();
|
|
91
|
+
|
|
92
|
+
const refResize=useRef(()=>{
|
|
93
|
+
refSelf.current.setResize(1);
|
|
94
|
+
})
|
|
95
|
+
const [resizeLazy] = useDebounceFn(refResize.current,{wait:1000})
|
|
96
|
+
|
|
97
|
+
const paginationFn = useCallback(() => {
|
|
98
|
+
// pagination=false时不分页
|
|
99
|
+
if (typeof pagination === 'boolean') {
|
|
100
|
+
return pagination;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if( page?.pagination?.pageSize){
|
|
105
|
+
updatePageSizeToLocal( page?.pagination?.pageSize )
|
|
106
|
+
let sizeList = pagination?.pageSizeOptions||PAGE_SIZE_LIST;
|
|
107
|
+
page.pagination.pageSize= calPageSize(page.pagination.pageSize,sizeList);
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
showSizeChanger:true,
|
|
112
|
+
showQuickJumper:true,
|
|
113
|
+
pageSizeOptions: PAGE_SIZE_LIST,
|
|
114
|
+
current: page?.pagination?.current,
|
|
115
|
+
pageSize: page?.pagination?.pageSize,
|
|
116
|
+
total: page?.pagination?.total,
|
|
117
|
+
showTotal: (total) => `总计${total}条`,
|
|
118
|
+
...pagination,
|
|
119
|
+
};
|
|
120
|
+
}, [pagination, page]);
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
const [resize,setResize]=useState(0);
|
|
125
|
+
|
|
126
|
+
const getList=()=>{
|
|
127
|
+
if(dataSource)return dataSource;
|
|
128
|
+
if(page?.mode == 'scrollLoad'){
|
|
129
|
+
return page.scrollData || [];
|
|
130
|
+
}else{
|
|
131
|
+
return page?.data?.[page?.pagination?.current - 1] ||[];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let list = getList();
|
|
135
|
+
|
|
136
|
+
const [scrollConfig,setScrollConfig] = useState(()=>{
|
|
137
|
+
const scrollConfig = scroll?{...SCROLL_CONFIG,...scroll}: {...SCROLL_CONFIG};
|
|
138
|
+
// 当没数据时,列的宽度取minWidth
|
|
139
|
+
if(minWidth && (!list||list.length<=0) ){
|
|
140
|
+
scrollConfig.x = minWidth;
|
|
141
|
+
}
|
|
142
|
+
return scrollConfig;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const onCancelFull=()=>{
|
|
146
|
+
if(fullScreen){
|
|
147
|
+
if(onCancelFullScreen){
|
|
148
|
+
onCancelFullScreen();
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// const scrollConfig = scroll?{...SCROLL_CONFIG,...scroll}: {...SCROLL_CONFIG};
|
|
154
|
+
// // 当没数据时,列的宽度取minWidth
|
|
155
|
+
// if(minWidth && (!list||list.length<=0) ){
|
|
156
|
+
// scrollConfig.x = minWidth;
|
|
157
|
+
// }
|
|
158
|
+
|
|
159
|
+
refSelf.current={
|
|
160
|
+
onCancelFull,
|
|
161
|
+
setResize,
|
|
162
|
+
resize,
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
useEffect(()=>{
|
|
168
|
+
escControl.addEventListener(onCancelFull);
|
|
169
|
+
return ()=>{
|
|
170
|
+
escControl.removeEventListener(onCancelFull);
|
|
171
|
+
}
|
|
172
|
+
},[onCancelFull])
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
useLayoutEffect(()=>{
|
|
178
|
+
let list = getList();
|
|
179
|
+
let observer;
|
|
180
|
+
const scrollConfig = scroll?{...SCROLL_CONFIG,...scroll}: {...SCROLL_CONFIG};
|
|
181
|
+
// 当没数据时,列的宽度取minWidth
|
|
182
|
+
if(minWidth && (!list||list.length<=0) ){
|
|
183
|
+
scrollConfig.x = minWidth;
|
|
184
|
+
}
|
|
185
|
+
if(refTable?.current){
|
|
186
|
+
if(fullScreen){
|
|
187
|
+
let dom = refTable.current;
|
|
188
|
+
// @ts-ignore
|
|
189
|
+
const thead = dom.querySelector(domTheadName);
|
|
190
|
+
observer = new ResizeObserver((entries) => {
|
|
191
|
+
entries.forEach(entry => {
|
|
192
|
+
const height = entry.contentRect.height;
|
|
193
|
+
if(refSelf.current.resize != height){
|
|
194
|
+
refSelf.current.setResize(height)
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
observer.observe(thead);
|
|
199
|
+
|
|
200
|
+
let theadHeight=60;
|
|
201
|
+
if(thead){
|
|
202
|
+
theadHeight = thead.clientHeight+16;
|
|
203
|
+
}
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
let maxHeight= dom.clientHeight;
|
|
206
|
+
let pagationHeight = pagination?24:0;
|
|
207
|
+
let footerHeight = footer?refFooter.current.clientHeight:0;
|
|
208
|
+
scrollConfig.y = maxHeight-(theadHeight+16+pagationHeight+footerHeight);
|
|
209
|
+
}
|
|
210
|
+
else if(heightMode=='inWrap'){
|
|
211
|
+
let dom = refTable.current;
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
const thead = dom.querySelector(domTheadName);
|
|
214
|
+
observer = new ResizeObserver((entries) => {
|
|
215
|
+
entries.forEach(entry => {
|
|
216
|
+
const height = entry.contentRect.height;
|
|
217
|
+
if(refSelf.current.resize != height){
|
|
218
|
+
refSelf.current.setResize(height)
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
observer.observe(thead);
|
|
223
|
+
|
|
224
|
+
let theadHeight=60;
|
|
225
|
+
if(thead){
|
|
226
|
+
theadHeight = thead.clientHeight+16;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
let maxHeight= dom.clientHeight;
|
|
231
|
+
let pagationHeight = pagination?28:0;
|
|
232
|
+
let footerHeight = footer?refFooter.current.clientHeight:0;
|
|
233
|
+
let h= maxHeight-(theadHeight+pagationHeight+footerHeight);
|
|
234
|
+
scrollConfig.y = h;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
setScrollConfig(scrollConfig)
|
|
239
|
+
if(observer){
|
|
240
|
+
return ()=>{
|
|
241
|
+
observer.disconnect();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
},[dataSource,page,fullScreen,resize,updateCount])
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
useEffect(()=>{
|
|
249
|
+
const resize = ()=>{
|
|
250
|
+
resizeLazy();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
window.addEventListener('resize',resize)
|
|
254
|
+
return ()=>{
|
|
255
|
+
window.removeEventListener('resize',resize);
|
|
256
|
+
refDestory.current=true;
|
|
257
|
+
}
|
|
258
|
+
},[])
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
// if(!scrollConfig)return <></>
|
|
262
|
+
return (
|
|
263
|
+
<section ref={refTable} className={`${styles.tableScrollWrap} ${sticky ? styles.sticky: ''}`} data-full={fullScreen}>
|
|
264
|
+
{
|
|
265
|
+
loading??(page?.loading?.state && page?.data?.length<=0)?
|
|
266
|
+
<Table
|
|
267
|
+
bordered
|
|
268
|
+
size="small"
|
|
269
|
+
columns={columns}
|
|
270
|
+
key='loading'
|
|
271
|
+
loading={true}
|
|
272
|
+
scroll={ scrollConfig }
|
|
273
|
+
/>:
|
|
274
|
+
<Table
|
|
275
|
+
rowKey={rowKey}
|
|
276
|
+
bordered
|
|
277
|
+
size="small"
|
|
278
|
+
// loading={loading ?? page?.loading?.state}
|
|
279
|
+
columns={columns}
|
|
280
|
+
dataSource={list}
|
|
281
|
+
pagination={paginationFn()}
|
|
282
|
+
scroll={ scrollConfig }
|
|
283
|
+
sticky={sticky}
|
|
284
|
+
{...others}
|
|
285
|
+
/>
|
|
286
|
+
}
|
|
287
|
+
{footer?<div className={styles.footer} ref={refFooter}>{footer}</div>:''}
|
|
288
|
+
<div className={styles.loading} data-show={ loading || page?.loading?.state }><Spin /></div>
|
|
289
|
+
|
|
290
|
+
{
|
|
291
|
+
fullScreen?<FullSizeIcon className={styles.resizeTable} full={fullScreen} onClick={onCancelFull}/>:<></>
|
|
292
|
+
}
|
|
293
|
+
</section>
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 从 sizeList 中找出与 value 最接近的值,同等距离时优先返回较大的值
|
|
300
|
+
* @param {string|number} value
|
|
301
|
+
* @param {string[]|number[]} sizeList
|
|
302
|
+
* @return {number}
|
|
303
|
+
*/
|
|
304
|
+
export const calPageSize = (value, sizeList) => {
|
|
305
|
+
const num = Number(value);
|
|
306
|
+
if(!sizeList||sizeList?.length<=0)return num;
|
|
307
|
+
return sizeList
|
|
308
|
+
.map(Number)
|
|
309
|
+
.reduce((closest, current) => {
|
|
310
|
+
const closestDiff = Math.abs(closest - num);
|
|
311
|
+
const currentDiff = Math.abs(current - num);
|
|
312
|
+
if (currentDiff < closestDiff) return current;
|
|
313
|
+
if (currentDiff === closestDiff) return current > closest ? current :closest;
|
|
314
|
+
return closest;
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const getPageSizeFromLocal=()=>{
|
|
319
|
+
let size;
|
|
320
|
+
try{
|
|
321
|
+
size = localStorage.getItem('pageSize');
|
|
322
|
+
if(size)size=+size || 20;
|
|
323
|
+
}catch(ex){
|
|
324
|
+
size=20;
|
|
325
|
+
}
|
|
326
|
+
return +size;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 默认分页配置
|
|
332
|
+
*/
|
|
333
|
+
export const DefaultPagination=()=>{
|
|
334
|
+
return {
|
|
335
|
+
pageSize:getPageSizeFromLocal()
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
PageTable.Column = Column;
|
|
340
|
+
PageTable.onPageChange = (page, current, pageSize) => {
|
|
341
|
+
page.update({ pagination: { current, pageSize }, clear: true });
|
|
342
|
+
};
|
|
343
|
+
PageTable.onSearch = (page) => {
|
|
344
|
+
page.update({ pagination: { current: 1 }, clear: true });
|
|
345
|
+
};
|
|
346
|
+
PageTable.onRest = (page) => {
|
|
347
|
+
page.reset();
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
PageTable.expandIcon=({ expanded, onExpand:_onExpand, record }) =>{
|
|
351
|
+
const onExpand = (item,e)=>{
|
|
352
|
+
e.stopPropagation();
|
|
353
|
+
if(_onExpand){
|
|
354
|
+
_onExpand(item,e);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if(!record.children){return <></>}
|
|
358
|
+
if(expanded){
|
|
359
|
+
return <i className={styles.expanded} data-state='close' onClick={e => onExpand(record, e)} />
|
|
360
|
+
}
|
|
361
|
+
return <i className={styles.expanded} onClick={e => onExpand(record, e)} />;
|
|
362
|
+
}
|
|
363
|
+
PageTable.createExpandIcon=(props={})=>{
|
|
364
|
+
const {className=''} = props;
|
|
365
|
+
return ({ expanded, onExpand, record }) =>{
|
|
366
|
+
if(!record.children){return <></>}
|
|
367
|
+
if(expanded){
|
|
368
|
+
return <i className={`${styles.expanded} ${className}`} data-state='close' onClick={e => {e.stopPropagation();onExpand(record, e)}} />
|
|
369
|
+
}
|
|
370
|
+
return <i className={`${styles.expanded} ${className}`} onClick={e => {e.stopPropagation();onExpand(record, e)}} />;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
export const ExpandIcon=props=>{
|
|
374
|
+
const {expanded,onClick,className=''} = props;
|
|
375
|
+
if(expanded){
|
|
376
|
+
return <i className={`${styles.expanded} ${className}`} data-state='close' onClick={onClick} />
|
|
377
|
+
}
|
|
378
|
+
return <i className={`${styles.expanded} ${className}`} onClick={onClick} />;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
export const FullSizeIcon=props=>{
|
|
383
|
+
const {full=false,onClick,className=''} = props;
|
|
384
|
+
return <div className={`${styles.fullSize} ${className}`} onClick={onClick} ><i className={`${styles.icon}`} data-full={full} /></div>;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @typedef MergeCellConfig
|
|
389
|
+
* @property {string[]} row - 参与行合并计算的列名列表
|
|
390
|
+
*/
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 动态计算合并单元格
|
|
394
|
+
* @param {object[]} list - 数据
|
|
395
|
+
* @param {MergeCellConfig} config
|
|
396
|
+
* @param {number} [rowIndex]
|
|
397
|
+
* @returns {object[]}
|
|
398
|
+
*/
|
|
399
|
+
const _mergeCells = (list, config, rowIndex = 0) => {
|
|
400
|
+
let result = [];
|
|
401
|
+
let _prevItem = {};
|
|
402
|
+
for (let row of list) {
|
|
403
|
+
let _row = { ...row };
|
|
404
|
+
if (_row.children) {
|
|
405
|
+
_row.children = _mergeCells(row.children, config, rowIndex);
|
|
406
|
+
_prevItem = {};
|
|
407
|
+
rowIndex += _row.children.length;
|
|
408
|
+
result.push(_row);
|
|
409
|
+
} else {
|
|
410
|
+
for (let attrName of config.row) {
|
|
411
|
+
let prevItem = _prevItem[attrName];
|
|
412
|
+
if (!prevItem) {
|
|
413
|
+
_prevItem[attrName] = _row;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
let same = false;
|
|
417
|
+
if (_row[attrName] == prevItem[attrName]) {
|
|
418
|
+
same = true;
|
|
419
|
+
}
|
|
420
|
+
if (same) {
|
|
421
|
+
prevItem._rowSpanConfig = prevItem._rowSpanConfig || {};
|
|
422
|
+
const { _rowSpanConfig } = prevItem;
|
|
423
|
+
_rowSpanConfig[attrName] = _rowSpanConfig[attrName] || {
|
|
424
|
+
startIndex: rowIndex - 1,
|
|
425
|
+
endIndex: rowIndex,
|
|
426
|
+
};
|
|
427
|
+
_rowSpanConfig[attrName].endIndex = rowIndex;
|
|
428
|
+
_row._rowSpanConfig = _row._rowSpanConfig || {};
|
|
429
|
+
_row._rowSpanConfig[attrName] = {
|
|
430
|
+
rowSpan: 0,
|
|
431
|
+
};
|
|
432
|
+
} else {
|
|
433
|
+
_prevItem[attrName] = _row;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
result.push(_row);
|
|
437
|
+
rowIndex++;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return result;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const _mergeCellsOnnCell = (key, item, index) => {
|
|
444
|
+
// console.log('合并 onCell ',index,item)
|
|
445
|
+
if (item._rowSpanConfig && item._rowSpanConfig[key]) {
|
|
446
|
+
const _config = item._rowSpanConfig[key];
|
|
447
|
+
if ('startIndex' in _config) {
|
|
448
|
+
// console.log("合并", key, item, index);
|
|
449
|
+
return {
|
|
450
|
+
rowSpan: _config.endIndex - _config.startIndex + 1,
|
|
451
|
+
};
|
|
452
|
+
} else if (_config.rowSpan == 0) {
|
|
453
|
+
// console.log("合并隐藏", key, item, index);
|
|
454
|
+
return { rowSpan: 0 };
|
|
455
|
+
}
|
|
456
|
+
return {};
|
|
457
|
+
}
|
|
458
|
+
return {};
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 用于动态计算合并单元格的算法
|
|
463
|
+
*/
|
|
464
|
+
PageTable.MergeCells={
|
|
465
|
+
onCell:_mergeCellsOnnCell,
|
|
466
|
+
mergeCell:_mergeCells
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
PageTable.heightMode={
|
|
471
|
+
default:'default',
|
|
472
|
+
inWrap:'inWrap'
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export default PageTable;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
.tableScrollWrap{
|
|
4
|
+
flex:1;
|
|
5
|
+
height: 100%;
|
|
6
|
+
width: 100%;
|
|
7
|
+
overflow: auto;
|
|
8
|
+
position: relative;
|
|
9
|
+
&.sticky {
|
|
10
|
+
overflow: visible;
|
|
11
|
+
:global {
|
|
12
|
+
.ant-table-body:has(+ .ant-table-sticky-scroll) {
|
|
13
|
+
&::-webkit-scrollbar {
|
|
14
|
+
display: none;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
&[data-full='true']{
|
|
20
|
+
position: fixed;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
z-index: 2;
|
|
24
|
+
padding:8px;
|
|
25
|
+
background-color: #fff;
|
|
26
|
+
left:0;
|
|
27
|
+
top:0;
|
|
28
|
+
z-index:9999;
|
|
29
|
+
}
|
|
30
|
+
.resizeTable{
|
|
31
|
+
position: absolute;
|
|
32
|
+
right:4px;
|
|
33
|
+
top:4px;
|
|
34
|
+
z-index: 20;
|
|
35
|
+
box-shadow: 0 0 2px #000;
|
|
36
|
+
}
|
|
37
|
+
.close{
|
|
38
|
+
font-size: 24px;
|
|
39
|
+
position: absolute;
|
|
40
|
+
right:16px;
|
|
41
|
+
top:16px;
|
|
42
|
+
z-index: 2;
|
|
43
|
+
}
|
|
44
|
+
:global {
|
|
45
|
+
.ant-table-selection-extra {
|
|
46
|
+
left: 18px;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
.footer{
|
|
51
|
+
width: 100%;
|
|
52
|
+
position: relative;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.tableWrap{
|
|
56
|
+
flex:1;
|
|
57
|
+
display: flex;
|
|
58
|
+
width: 100%;
|
|
59
|
+
flex-direction: column;
|
|
60
|
+
overflow: hidden;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.iconAdd{
|
|
64
|
+
background-image: url('~@/assets/images/icon-add.png');
|
|
65
|
+
background-size: contain;
|
|
66
|
+
width: 24px;
|
|
67
|
+
height:24px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.expanded{
|
|
71
|
+
background-image: url('~@/assets/images/expand.png');
|
|
72
|
+
background-size:100% 100%;
|
|
73
|
+
width: 20px;
|
|
74
|
+
height: 20px;
|
|
75
|
+
display: block;
|
|
76
|
+
transition: background .3s ease-in-out;
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
&:hover{
|
|
81
|
+
background-image: url('~@/assets/images/expand-hover.png');
|
|
82
|
+
}
|
|
83
|
+
&[data-state='close']{
|
|
84
|
+
background-image: url('~@/assets/images/unexpand.png');
|
|
85
|
+
&:hover{
|
|
86
|
+
background-image: url('~@/assets/images/unexpand-hover.png');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.fullSize{
|
|
92
|
+
position: relative;
|
|
93
|
+
|
|
94
|
+
display: flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
justify-content: center;
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
width: 32px;
|
|
99
|
+
height: 32px;
|
|
100
|
+
border-radius: 4px;
|
|
101
|
+
border:1px solid #ccc;
|
|
102
|
+
|
|
103
|
+
.icon{
|
|
104
|
+
display: inline-block;
|
|
105
|
+
background-image: url('~@/assets/images/icon-full-size.png');
|
|
106
|
+
background-size:100% 100%;
|
|
107
|
+
width: 20px;
|
|
108
|
+
height: 20px;
|
|
109
|
+
&[data-full='true']{
|
|
110
|
+
background-image: url('~@/assets/images/icon-resize.png');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
.loading{
|
|
120
|
+
position: absolute;
|
|
121
|
+
display: none;
|
|
122
|
+
left:0;
|
|
123
|
+
top:0;
|
|
124
|
+
width: 100%;
|
|
125
|
+
height: 100%;
|
|
126
|
+
background-color: rgba(255,255,255,.8);
|
|
127
|
+
z-index: 3;
|
|
128
|
+
&[data-show='true']{
|
|
129
|
+
display: flex;
|
|
130
|
+
justify-content: center;
|
|
131
|
+
align-items: center;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { Tooltip } from '@/components/antd';
|
|
4
|
+
import { getStrByteLen } from '@/utils';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import styles from './index.module.less';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 获取字符串末尾字节数的字符串、所在位置
|
|
10
|
+
* @param {string} str - 必填项;要处理的字符串
|
|
11
|
+
* @param {number} bytes - 必填项;末尾字节数
|
|
12
|
+
* @returns {object}
|
|
13
|
+
*/
|
|
14
|
+
const endBytesStr = (str, bytes) => {
|
|
15
|
+
if (!str) return { index: 0, text: '' };
|
|
16
|
+
let num = 0;
|
|
17
|
+
let result = '';
|
|
18
|
+
let index = 0;
|
|
19
|
+
for (let i = str.length - 1; i >=0; i--) {
|
|
20
|
+
num += str.charCodeAt(i) > 255 ? 3 : 1; // 中文三个字节,英文一个字节
|
|
21
|
+
if (num > bytes) {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
result = str.substring(i, str.length);
|
|
25
|
+
index = i;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
index,
|
|
29
|
+
text:result,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 字符串省略效果:末尾省略 | 中间省略
|
|
35
|
+
* @param {object} props
|
|
36
|
+
* @param {string} props.str - 必填项;要处理的字符
|
|
37
|
+
* @param {number} [props.endBytes] - 可选项;不传默认末尾省略,中间省略时,字符串末尾显示几个“字节”
|
|
38
|
+
* @param {string} [props.className] - 可选项;类名
|
|
39
|
+
* @returns {JSX.Element}
|
|
40
|
+
*/
|
|
41
|
+
const Text = (props) => {
|
|
42
|
+
const { str, endBytes=null, className='' } = props;
|
|
43
|
+
const [strEnd, setStrEnd] = useState({
|
|
44
|
+
index: 0,
|
|
45
|
+
text: '',
|
|
46
|
+
});
|
|
47
|
+
const [isOverflow, setIsOverflow] = useState(false);
|
|
48
|
+
const prevRef = useRef(null);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if(!str) return;
|
|
52
|
+
const strBytes = getStrByteLen(str);
|
|
53
|
+
if (endBytes && strBytes > endBytes) {
|
|
54
|
+
const { index, text } = endBytesStr(str, endBytes);
|
|
55
|
+
setStrEnd({
|
|
56
|
+
index,
|
|
57
|
+
text,
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
setStrEnd({
|
|
61
|
+
index: 0,
|
|
62
|
+
text: '',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}, [str, endBytes]);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const checkOverflow = () => {
|
|
69
|
+
if (prevRef.current) {
|
|
70
|
+
const isOverflowing =
|
|
71
|
+
prevRef.current.scrollWidth > prevRef.current.clientWidth;
|
|
72
|
+
setIsOverflow(isOverflowing);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
checkOverflow();
|
|
77
|
+
}, [strEnd]);
|
|
78
|
+
|
|
79
|
+
const ContentDom = (
|
|
80
|
+
<section className={`${styles.parent} ${className}`}>
|
|
81
|
+
{strEnd?.text ? (
|
|
82
|
+
<>
|
|
83
|
+
<div className={styles.prev} ref={prevRef}>
|
|
84
|
+
{str.slice(0, strEnd?.index)}
|
|
85
|
+
</div>
|
|
86
|
+
<div className={styles.next}>{strEnd?.text}</div>
|
|
87
|
+
</>
|
|
88
|
+
) : (
|
|
89
|
+
<div className={styles.prev} ref={prevRef}>
|
|
90
|
+
{str}
|
|
91
|
+
</div>
|
|
92
|
+
)}
|
|
93
|
+
</section>
|
|
94
|
+
);
|
|
95
|
+
return isOverflow ? <Tooltip title={str}>{ContentDom}</Tooltip> : ContentDom;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default React.memo(Text);
|