kn-cli 1.0.134 → 1.0.136
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/package.json +2 -1
- package/build/vite.config.js +1 -0
- package/build/webpack.config.js +16 -2
- package/package.json +1 -1
- package/src/build.js +1 -1
- package/templates/template_admin_antd5/package.json +3 -3
- package/templates/template_admin_antd5/public/src/_antd.less +4 -4
- package/templates/template_admin_antd5/public/src/_reset.module.less +1 -1
- package/templates/template_admin_antd5/public/src/_variable.module.less +5 -5
- package/templates/template_admin_antd5/public/src/assets/images/expand-hover.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/expand.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/icon-add.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/icon-full-size.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/icon-resize.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/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/nav/slogan.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/unexpand-hover.png +0 -0
- package/templates/template_admin_antd5/public/src/assets/images/unexpand.png +0 -0
- package/templates/template_admin_antd5/public/src/components/antd/antProvider.jsx +16 -4
- package/templates/template_admin_antd5/public/src/components/antd/drawer/README.md +336 -0
- package/templates/template_admin_antd5/public/src/components/antd/drawer/index.jsx +264 -0
- package/templates/template_admin_antd5/public/src/components/antd/index.jsx +19 -7
- package/templates/template_admin_antd5/public/src/components/antd/index.module.less +26 -0
- package/templates/template_admin_antd5/public/src/components/antd/modal/README.md +324 -0
- package/templates/template_admin_antd5/public/src/components/antd/modal/index.jsx +185 -0
- package/templates/template_admin_antd5/public/src/components/antd/select/index.jsx +1 -1
- package/templates/template_admin_antd5/public/src/components/antd/spin/index.jsx +92 -0
- package/templates/template_admin_antd5/public/src/components/antd/spin/index.module.less +58 -0
- package/templates/template_admin_antd5/public/src/components/antd/theme.js +19 -8
- package/templates/template_admin_antd5/public/src/components/antd/tooltip/detail/index.jsx +19 -56
- package/templates/template_admin_antd5/public/src/components/debug/index.jsx +7 -2
- package/templates/template_admin_antd5/public/src/components/error/index.jsx +0 -5
- package/templates/template_admin_antd5/public/src/components/icon/expand/index.jsx +17 -0
- package/templates/template_admin_antd5/public/src/components/icon/expand/index.module.less +22 -0
- package/templates/template_admin_antd5/public/src/components/icon/fullSize/index.jsx +13 -0
- package/templates/template_admin_antd5/public/src/components/icon/fullSize/index.module.less +28 -0
- package/templates/template_admin_antd5/public/src/components/icon/index.jsx +7 -1
- package/templates/template_admin_antd5/public/src/components/image/preview.jsx +7 -10
- package/templates/template_admin_antd5/public/src/components/layout/basic/index.module.less +1 -1
- package/templates/template_admin_antd5/public/src/components/leftMenu/index.jsx +1 -2
- package/templates/template_admin_antd5/public/src/components/link/index.module.less +2 -2
- package/templates/template_admin_antd5/public/src/components/menuIcon/index.module.less +3 -3
- package/templates/template_admin_antd5/public/src/components/popup/index.jsx +91 -50
- package/templates/template_admin_antd5/public/src/components/popup/index.module.less +22 -15
- package/templates/template_admin_antd5/public/src/components/react/index.jsx +23 -9
- package/templates/template_admin_antd5/public/src/components/resizeBox/index.jsx +3 -3
- package/templates/template_admin_antd5/public/src/components/select/defaultServicesSelect/index.jsx +151 -40
- package/templates/template_admin_antd5/public/src/components/select/dictSelect/index.jsx +19 -3
- package/templates/template_admin_antd5/public/src/components/select/useSelectList.jsx +65 -65
- package/templates/template_admin_antd5/public/src/components/table/index.jsx +48 -327
- package/templates/template_admin_antd5/public/src/components/table/index.module.less +0 -110
- package/templates/template_admin_antd5/public/src/components/table/table/index.jsx +242 -0
- package/templates/template_admin_antd5/public/src/components/table/table/index.module.less +85 -0
- package/templates/template_admin_antd5/public/src/components/table/withPage.jsx +53 -0
- package/templates/template_admin_antd5/public/src/components/topMenu/index.jsx +46 -11
- package/templates/template_admin_antd5/public/src/components/topMenu/index.module.less +10 -7
- package/templates/template_admin_antd5/public/src/components/topMenu/popmenu/index.jsx +89 -0
- package/templates/template_admin_antd5/public/src/components/topMenu/popmenu/index.module.less +76 -0
- package/templates/template_admin_antd5/public/src/components/topMenu/topBar/index.module.less +4 -3
- package/templates/template_admin_antd5/public/src/components/video/index.jsx +1 -1
- package/templates/template_admin_antd5/public/src/components/video/preview.jsx +7 -10
- package/templates/template_admin_antd5/public/src/config.js +3 -0
- package/templates/template_admin_antd5/public/src/hooks/useLoading.jsx +2 -2
- package/templates/template_admin_antd5/public/src/index.jsx +7 -4
- package/templates/template_admin_antd5/public/src/mock/demo.js +3 -3
- package/templates/template_admin_antd5/public/src/pages/antdComponents/button/index.jsx +22 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/check/index.jsx +12 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/index.jsx +57 -114
- package/templates/template_admin_antd5/public/src/pages/antdComponents/index.module.less +5 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/input/index.jsx +14 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/loading/index.jsx +31 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/message/index.jsx +102 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/message/index.module.less +17 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/radio/index.jsx +26 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/select/index.jsx +13 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/switch/index.jsx +12 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/tableWithPage/index.jsx +70 -0
- package/templates/template_admin_antd5/public/src/pages/antdComponents/text/index.jsx +21 -0
- package/templates/template_admin_antd5/public/src/pages/auth/user/dialog/index.jsx +48 -75
- package/templates/template_admin_antd5/public/src/pages/auth/user/index.jsx +17 -23
- package/templates/template_admin_antd5/public/src/pages/lazyLoad/index.jsx +11 -0
- package/templates/template_admin_antd5/public/src/pages/login/index.jsx +8 -3
- package/templates/template_admin_antd5/public/src/pages/login/index.module.less +18 -10
- package/templates/template_admin_antd5/public/src/provider/menu.jsx +5 -0
- package/templates/template_admin_antd5/public/src/route.jsx +14 -9
- package/templates/template_admin_antd5/public/src/services/demo.js +38 -2
- package/templates/template_admin_antd5/public/src/services/interceptor/index.js +30 -3
- package/templates/template_admin_antd5/public/src/types/global.d.js +306 -0
- package/templates/template_admin_antd5/public/src/utils/format.js +1 -1
- package/templates/template_admin_antd5/public/src/utils/index.js +3 -3
- package/templates/template_admin_antd5/public/src/utils/moment.js +15 -0
- package/templates/template_admin_antd5/public/static/version.json +3 -0
- package/templates/template_admin_antd5/public/src/components/_table/column.jsx +0 -47
- package/templates/template_admin_antd5/public/src/components/_table/column.module.less +0 -12
- package/templates/template_admin_antd5/public/src/components/_table/index.jsx +0 -71
- package/templates/template_admin_antd5/public/src/components/_table/index.module.less +0 -15
- package/templates/template_admin_antd5/public/src/components/badge/index.jsx +0 -47
- package/templates/template_admin_antd5/public/src/components/badge/index.module.less +0 -44
- package/templates/template_admin_antd5/public/src/components/page/pageLoading/index.jsx +0 -51
- package/templates/template_admin_antd5/public/src/components/page/pageLoading/index.module.less +0 -29
- package/templates/template_admin_antd5/public/src/components/table/aliTable/index.jsx +0 -250
- package/templates/template_admin_antd5/public/src/components/table/aliTable/index.module.less +0 -105
- package/templates/template_admin_antd5/public/src/components/toast/index.jsx +0 -79
- package/templates/template_admin_antd5/public/src/components/toast/index.module.less +0 -43
- package/templates/template_admin_antd5/public/src/provider/loading.jsx +0 -47
- package/templates/template_admin_antd5/public/src/provider/menu.module.less +0 -35
- package/templates/template_admin_antd5/public/src/type.js +0 -67
- package/templates/template_admin_antd5/renamejstojsx.js +0 -45
- package/templates/template_admin_antd5/renameless.js +0 -53
- /package/templates/template_admin_antd5/public/src/components/{button → antd/button}/index.jsx +0 -0
- /package/templates/template_admin_antd5/public/src/components/resizeBox/{index.module.css → index.module.less} +0 -0
|
@@ -1,55 +1,7 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
// @ts-ignore
|
|
3
|
-
import {Tooltip} from "@/components/antd";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 各类选择框组件
|
|
9
|
-
* @typedef SelectListProps
|
|
10
|
-
* @property {string} [name] - 调试名称
|
|
11
|
-
* @property {'single'|'multiple'} [mode='single'] - 单选/多选模式
|
|
12
|
-
* @property {(value:string|string[],items:object|object[])=>void} [onChange] - 选择发生变化时的回调
|
|
13
|
-
* @property {string|string[]} [value] - 选择发生变化时的回调
|
|
14
|
-
* @property {object} [style={}] - 样式
|
|
15
|
-
* @property {string} [placeholder] - 提示
|
|
16
|
-
* @property {boolean} [allowClear=false] - 一键删除按钮
|
|
17
|
-
* @property {boolean} [showAll=false] - 是否第一个展示全部选项
|
|
18
|
-
* @property {string} [allValue=''] - 定义全部选项的值是哪种类型,''代表空字符串
|
|
19
|
-
* @property {(id:string)=>SelectItem} [onNoMatchData] - 当没有匹配到数据时的回调
|
|
20
|
-
* @property {{id:number|string,label:string}[]} [noMatchList] - 为匹配到数据时的备用匹配数据
|
|
21
|
-
* @property {string} [onNoMatchDataLabel] - 当单选时,默认选中的数据没有匹配到合法数据时展示的label
|
|
22
|
-
* @property {object} [params={}] - 扩展参数
|
|
23
|
-
* @property {boolean} [disabled=false] - 是否禁止编辑
|
|
24
|
-
* @property {boolean} [noCheckNotFound=false] 是否禁止做不匹配数据的检查补全
|
|
25
|
-
* @property {string} [className='']
|
|
26
|
-
* @property {number} [maxTagCount] - 多选时最多支持的标签数量
|
|
27
|
-
* @property {JSX.Element|string} [suffixIcon] 选择框尾部的icon
|
|
28
|
-
* @property {(value:string|string[],items:object|object[])=>Promise<boolean>} [canChange] - 用于在切换选项时拦截决定是否允许变更
|
|
29
|
-
* @property {boolean} [required=false] - 是否为必选,必选的话不允许allowClear
|
|
30
|
-
* @property {(list:SelectItem[])=>object} [onDefaultSelect] - 初始化后如果需要有默认选中项的计算的话,可以通过这里拦截
|
|
31
|
-
* @property {(list:SelectItem[])=>void} [onListUpdate] - 每当列表内的数据更新时回调
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @typedef SelectItem
|
|
37
|
-
* @property {string} label - 文本下拉框里展示的文本
|
|
38
|
-
* @property {string} value - 文本下拉框里选项的值
|
|
39
|
-
* @property {any} data - 文本下拉框里选项对应的原始数据
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @typedef UseSelectList
|
|
45
|
-
* @property {(list:SelectItem[])=>Promise<boolean>} init - 初始化函数
|
|
46
|
-
* @property {string|number|string[]|number[]} value - 值发生变化时的回调
|
|
47
|
-
* @property {SelectItem[]} list - 选择的数据列表
|
|
48
|
-
* @property {(value)=>void} setValue - 设置当前值
|
|
49
|
-
* @property {object} props - 继承给Select组件的通用属性
|
|
50
|
-
* @property {(value:string|string[])=>object[]} getItemByValue - 通过ID获取到所有匹配的对象数据
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
3
|
+
import {message, Tooltip} from "@/components/antd";
|
|
4
|
+
import { copyToClipboard } from '@/utils';
|
|
53
5
|
|
|
54
6
|
/**
|
|
55
7
|
* 通用的管理选择下拉框数据的hooks
|
|
@@ -67,8 +19,9 @@ const useSelectList=(props)=>{
|
|
|
67
19
|
onNoMatchDataLabel,
|
|
68
20
|
noCheckNotFound=false,
|
|
69
21
|
noMatchList=[],
|
|
22
|
+
size='middle',
|
|
23
|
+
dropdownMatchSelectWidth,
|
|
70
24
|
} = props;
|
|
71
|
-
|
|
72
25
|
const [list,setList]= useState(null);
|
|
73
26
|
const [value,setValue]=useState(mode=='single'?'':[]);
|
|
74
27
|
const [maxTagCount] = useState(()=>{
|
|
@@ -86,14 +39,35 @@ const useSelectList=(props)=>{
|
|
|
86
39
|
|
|
87
40
|
const [suffixIcon] = useState(props.suffixIcon||undefined)
|
|
88
41
|
|
|
42
|
+
const getItemOptions=()=>{
|
|
43
|
+
let currentValue = value;
|
|
44
|
+
if(showAll && mode=='multiple'){
|
|
45
|
+
if(!list)return null;
|
|
46
|
+
const isAll = currentValue && Array.isArray(currentValue) && currentValue.includes(allValue);
|
|
47
|
+
list.forEach(item=>{
|
|
48
|
+
if(isAll){
|
|
49
|
+
if(item.value != allValue){
|
|
50
|
+
item.disabled=true;
|
|
51
|
+
}else{
|
|
52
|
+
item.disabled=false;
|
|
53
|
+
}
|
|
54
|
+
}else{
|
|
55
|
+
item.disabled=false;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return [...list]
|
|
59
|
+
}else{
|
|
60
|
+
return list;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
89
64
|
/**
|
|
90
65
|
* 初始化加载下拉框数据
|
|
91
|
-
* @param {{label:string,value:string,data:any}[]} values
|
|
66
|
+
* @param {{label:string,value:string,data:any,disabled?:boolean}[]} values
|
|
92
67
|
*/
|
|
93
68
|
const init = async (values)=>{
|
|
94
69
|
if(showAll && values?.length>0){
|
|
95
|
-
|
|
96
|
-
values =[{label:'全部',value,data:values},...values]
|
|
70
|
+
values =[{label:'全部',value:allValue,data:values},...values];
|
|
97
71
|
}
|
|
98
72
|
setList(values);
|
|
99
73
|
return true;
|
|
@@ -106,6 +80,7 @@ const useSelectList=(props)=>{
|
|
|
106
80
|
*/
|
|
107
81
|
const getItemByValue=(value)=>{
|
|
108
82
|
if(!value)return [];
|
|
83
|
+
if(!list||list.length<=0)return [];
|
|
109
84
|
let finder = [];
|
|
110
85
|
if(Array.isArray(value)==false){
|
|
111
86
|
finder = [value];
|
|
@@ -169,18 +144,29 @@ const useSelectList=(props)=>{
|
|
|
169
144
|
if(onNoMatchData){
|
|
170
145
|
let data = onNoMatchData(id);
|
|
171
146
|
if(data){
|
|
147
|
+
if(data?._delete){
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
data.isNoFind=true;
|
|
172
151
|
list.splice(0,0,data);
|
|
173
152
|
return;
|
|
174
153
|
}
|
|
175
154
|
}
|
|
176
155
|
if(onNoMatchDataLabel){
|
|
177
|
-
list.splice(0,0,{value:id,label:onNoMatchDataLabel,data:null});
|
|
156
|
+
list.splice(0,0,{value:id,label:onNoMatchDataLabel,data:null,isNoFind:true});
|
|
178
157
|
return;
|
|
179
158
|
}
|
|
180
|
-
list.splice(0,0,{value:id,label:`${id}[不可用]`,data:null});
|
|
159
|
+
list.splice(0,0,{value:id,label:`${id}[不可用]`,data:null,isNoFind:true});
|
|
181
160
|
})
|
|
182
161
|
setList([...list]);
|
|
183
162
|
}
|
|
163
|
+
const getItems=()=>{
|
|
164
|
+
if(!list){
|
|
165
|
+
throw new Error('数据未加载完毕无法getItems获取数据');
|
|
166
|
+
}
|
|
167
|
+
return list?.filter(item=>!item.isNoFind)||[];
|
|
168
|
+
}
|
|
169
|
+
|
|
184
170
|
|
|
185
171
|
useEffect(()=>{
|
|
186
172
|
if(_value==null||_value==undefined){
|
|
@@ -189,9 +175,12 @@ const useSelectList=(props)=>{
|
|
|
189
175
|
}
|
|
190
176
|
let req;
|
|
191
177
|
if(mode=='multiple' && Array.isArray(_value)){
|
|
192
|
-
req= _value.map(id=>`${id}`)
|
|
178
|
+
req= _value.map(id=>`${id}`);
|
|
179
|
+
if(showAll && req?.includes(allValue)){
|
|
180
|
+
req=[allValue];
|
|
181
|
+
}
|
|
193
182
|
}else{
|
|
194
|
-
req = `${_value}
|
|
183
|
+
req = `${_value}`;
|
|
195
184
|
}
|
|
196
185
|
setValue(req);
|
|
197
186
|
},[_value]);
|
|
@@ -200,18 +189,29 @@ const useSelectList=(props)=>{
|
|
|
200
189
|
checkNoFindData();
|
|
201
190
|
},[value,list,noMatchList])
|
|
202
191
|
|
|
203
|
-
return {init,value,list,setValue,getItemByValue,props:{maxTagCount,suffixIcon,
|
|
192
|
+
return {init,value,list:getItemOptions(),setValue,getItemByValue,getItems,props:{dropdownMatchSelectWidth,size,maxTagCount,suffixIcon,
|
|
204
193
|
maxTagPlaceholder:(omittedValues) => (
|
|
205
194
|
<Tooltip
|
|
206
|
-
overlayStyle={{
|
|
207
|
-
|
|
208
|
-
}}
|
|
209
|
-
|
|
195
|
+
// overlayStyle={{
|
|
196
|
+
// pointerEvents: 'none',
|
|
197
|
+
// }}
|
|
198
|
+
onCopyMore={()=>{
|
|
199
|
+
if(omittedValues?.length>200){
|
|
200
|
+
let text=omittedValues.map(({ label }) => label).join(', ');
|
|
201
|
+
copyToClipboard(text,(req)=>{
|
|
202
|
+
message.info(req?'复制成功':'复制失败')
|
|
203
|
+
})
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
}}
|
|
208
|
+
title={
|
|
209
|
+
omittedValues.length>200?'数据太多请复制后查看':omittedValues.map(({ label }) => label).join(', ')
|
|
210
|
+
}
|
|
210
211
|
>
|
|
211
212
|
<span className='antd-show-tag-more-label'><i></i><i></i><i></i></span>
|
|
212
213
|
</Tooltip>
|
|
213
214
|
)
|
|
214
|
-
|
|
215
215
|
}}
|
|
216
216
|
}
|
|
217
217
|
export default useSelectList;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import React
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { Spin, Table } from "@/components/antd";
|
|
1
|
+
import React from 'react';
|
|
4
2
|
|
|
5
3
|
// @ts-ignore
|
|
6
4
|
import styles from './index.module.less';
|
|
7
5
|
import Column,{Wrap} from './column';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { useLayoutEffect } from 'react';
|
|
6
|
+
import WithPageTable from './withPage';
|
|
7
|
+
import {ExpandIcon,FullSizeIcon} from '@/components/icon';
|
|
8
|
+
export {ExpandIcon}
|
|
9
|
+
export {FullSizeIcon}
|
|
10
|
+
|
|
14
11
|
|
|
15
12
|
export {Wrap}
|
|
16
13
|
export const SCROLL_CONFIG={x:'max-content',
|
|
@@ -26,274 +23,6 @@ export const PAGE_SIZE_OPTIONS=PAGE_SIZE_LIST.map(size=>{
|
|
|
26
23
|
return {value:`${size}`,label:`${size} 条/页`}
|
|
27
24
|
});
|
|
28
25
|
|
|
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
26
|
|
|
298
27
|
/**
|
|
299
28
|
* 从 sizeList 中找出与 value 最接近的值,同等距离时优先返回较大的值
|
|
@@ -326,7 +55,6 @@ const getPageSizeFromLocal=()=>{
|
|
|
326
55
|
return +size;
|
|
327
56
|
}
|
|
328
57
|
|
|
329
|
-
|
|
330
58
|
/**
|
|
331
59
|
* 默认分页配置
|
|
332
60
|
*/
|
|
@@ -336,53 +64,6 @@ export const DefaultPagination=()=>{
|
|
|
336
64
|
}
|
|
337
65
|
}
|
|
338
66
|
|
|
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
67
|
|
|
387
68
|
/**
|
|
388
69
|
* @typedef MergeCellConfig
|
|
@@ -458,6 +139,46 @@ const _mergeCellsOnnCell = (key, item, index) => {
|
|
|
458
139
|
return {};
|
|
459
140
|
};
|
|
460
141
|
|
|
142
|
+
const PageTable={}
|
|
143
|
+
PageTable.Column = Column;
|
|
144
|
+
PageTable.onPageChange = (page, current, pageSize) => {
|
|
145
|
+
page.update({ pagination: { current, pageSize }, clear: true });
|
|
146
|
+
};
|
|
147
|
+
PageTable.onSearch = (page) => {
|
|
148
|
+
page.update({ pagination: { current: 1 }, clear: true });
|
|
149
|
+
};
|
|
150
|
+
PageTable.onRest = (page) => {
|
|
151
|
+
page.reset();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
PageTable.expandIcon=({ expanded, onExpand:_onExpand, record }) =>{
|
|
155
|
+
const onExpand = (item,e)=>{
|
|
156
|
+
e.stopPropagation();
|
|
157
|
+
if(_onExpand){
|
|
158
|
+
_onExpand(item,e);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if(!record.children){return <></>}
|
|
162
|
+
return <ExpandIcon expanded={expanded} onClick={onExpand.bind(this,record)} />
|
|
163
|
+
}
|
|
164
|
+
PageTable.createExpandIcon=(props={})=>{
|
|
165
|
+
const {className=''} = props;
|
|
166
|
+
return ({ expanded, onExpand, record }) =>{
|
|
167
|
+
const onClick = (item,e)=>{
|
|
168
|
+
e.stopPropagation();
|
|
169
|
+
if(onExpand){
|
|
170
|
+
onExpand(item,e);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if(!record.children){return <></>}
|
|
174
|
+
return <ExpandIcon expanded={expanded} onClick={onExpand.bind(this,record)} />
|
|
175
|
+
if(expanded){
|
|
176
|
+
return <i className={`${styles.expanded} ${className}`} data-state='close' onClick={onClick.bind(this,record)} />
|
|
177
|
+
}
|
|
178
|
+
return <i className={`${styles.expanded} ${className}`} onClick={onClick.bind(this,record)} />;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
461
182
|
/**
|
|
462
183
|
* 用于动态计算合并单元格的算法
|
|
463
184
|
*/
|
|
@@ -466,10 +187,10 @@ PageTable.MergeCells={
|
|
|
466
187
|
mergeCell:_mergeCells
|
|
467
188
|
}
|
|
468
189
|
|
|
469
|
-
|
|
470
190
|
PageTable.heightMode={
|
|
471
191
|
default:'default',
|
|
472
192
|
inWrap:'inWrap'
|
|
473
193
|
}
|
|
474
194
|
|
|
475
|
-
export
|
|
195
|
+
export {PageTable as TableTools}
|
|
196
|
+
export default WithPageTable
|