ztxkui 1.5.6 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,6 +74,12 @@ function EnhanceSelect(_a) {
74
74
  var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.dataKey, dataKey = _c === void 0 ? 'id' : _c, componentKey = _a.componentKey, _d = _a.titleKey, titleKey = _d === void 0 ? 'name' : _d, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, transformData = _a.transformData, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "transformData"]);
75
75
  // 下拉数据源
76
76
  var _e = useFetchState([]), selectList = _e[0], setSelectList = _e[1];
77
+ // 如果selectList 发生改变,那么触发onCompleted事件
78
+ useEffect(function () {
79
+ if (Array.isArray(selectList) && onCompleted) {
80
+ onCompleted(selectList);
81
+ }
82
+ }, [selectList, onCompleted]);
77
83
  // 获取数据,并设置数据
78
84
  var getDataHandle = useCallback(function (request, options, appointObj) {
79
85
  getData(request, options)
@@ -42,10 +42,14 @@ export interface IProps extends TreeProps {
42
42
  * 是否显示总计、已选条目
43
43
  */
44
44
  showTotal?: boolean;
45
+ /**
46
+ * 数据加载完毕触发
47
+ */
48
+ onCompleted?: (data: any) => void;
45
49
  }
46
50
  /**
47
51
  * 增强树组件
48
52
  * 添加远程搜索
49
53
  */
50
- declare function EnhanceTree({ treeData: outTreeData, defaultTreeData, params, url, method, request, asyncLoadChildren, asyncLoadChildrenKey, transformData, showSearch, showTotal, ...restProps }: IProps): JSX.Element;
54
+ declare function EnhanceTree({ treeData: outTreeData, defaultTreeData, params, url, method, request, asyncLoadChildren, asyncLoadChildrenKey, transformData, showSearch, showTotal, onCompleted, ...restProps }: IProps): JSX.Element;
51
55
  export default EnhanceTree;
@@ -58,13 +58,19 @@ function updateTreeData(list, key, children) {
58
58
  * 添加远程搜索
59
59
  */
60
60
  function EnhanceTree(_a) {
61
- var outTreeData = _a.treeData, defaultTreeData = _a.defaultTreeData, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, request = _a.request, asyncLoadChildren = _a.asyncLoadChildren, _c = _a.asyncLoadChildrenKey, asyncLoadChildrenKey = _c === void 0 ? 'parentId' : _c, transformData = _a.transformData, showSearch = _a.showSearch, showTotal = _a.showTotal, restProps = __rest(_a, ["treeData", "defaultTreeData", "params", "url", "method", "request", "asyncLoadChildren", "asyncLoadChildrenKey", "transformData", "showSearch", "showTotal"]);
61
+ var outTreeData = _a.treeData, defaultTreeData = _a.defaultTreeData, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, request = _a.request, asyncLoadChildren = _a.asyncLoadChildren, _c = _a.asyncLoadChildrenKey, asyncLoadChildrenKey = _c === void 0 ? 'parentId' : _c, transformData = _a.transformData, showSearch = _a.showSearch, showTotal = _a.showTotal, onCompleted = _a.onCompleted, restProps = __rest(_a, ["treeData", "defaultTreeData", "params", "url", "method", "request", "asyncLoadChildren", "asyncLoadChildrenKey", "transformData", "showSearch", "showTotal", "onCompleted"]);
62
62
  /**
63
63
  * treeData 为当前组件使用的数据源
64
64
  * 这样做的目的,是因为如果做远程搜索和搜索方法组件内部处理时
65
65
  * 保证数据源唯一
66
66
  */
67
67
  var _d = useFetchState([]), treeData = _d[0], setTreeData = _d[1];
68
+ // 如果selectList 发生改变,那么触发onCompleted事件
69
+ useEffect(function () {
70
+ if (Array.isArray(treeData) && onCompleted) {
71
+ onCompleted(treeData);
72
+ }
73
+ }, [treeData, onCompleted]);
68
74
  // 获取数据,并设置数据
69
75
  var getDataHandle = useCallback(function (request, options, isConcat, dataNode) {
70
76
  return getData(request, options)
@@ -34,10 +34,14 @@ export interface IProps<T> extends Omit<TreeSelectProps<T>, 'onChange'> {
34
34
  * 接口数据格式转换
35
35
  */
36
36
  transformData?: (res: any) => any;
37
+ /**
38
+ * 数据加载完毕触发
39
+ */
40
+ onCompleted?: (data: any) => void;
37
41
  }
38
42
  /**
39
43
  * 增强下拉树
40
44
  * 添加远程搜索
41
45
  */
42
- declare function EnhanceTreeSelect<VT extends SelectValue = SelectValue>({ treeData: outTreeData, defaultTreeData, params, url, method, request, asyncLoadChildren, asyncLoadChildrenKey, transformData, treeDataSimpleMode, ...restProps }: IProps<VT>): JSX.Element;
46
+ declare function EnhanceTreeSelect<VT extends SelectValue = SelectValue>({ treeData: outTreeData, defaultTreeData, params, url, method, request, asyncLoadChildren, asyncLoadChildrenKey, transformData, treeDataSimpleMode, onCompleted, ...restProps }: IProps<VT>): JSX.Element;
43
47
  export default EnhanceTreeSelect;
@@ -46,13 +46,19 @@ function getData(request, options) {
46
46
  * 添加远程搜索
47
47
  */
48
48
  function EnhanceTreeSelect(_a) {
49
- var outTreeData = _a.treeData, defaultTreeData = _a.defaultTreeData, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, request = _a.request, asyncLoadChildren = _a.asyncLoadChildren, _c = _a.asyncLoadChildrenKey, asyncLoadChildrenKey = _c === void 0 ? 'parentId' : _c, transformData = _a.transformData, treeDataSimpleMode = _a.treeDataSimpleMode, restProps = __rest(_a, ["treeData", "defaultTreeData", "params", "url", "method", "request", "asyncLoadChildren", "asyncLoadChildrenKey", "transformData", "treeDataSimpleMode"]);
49
+ var outTreeData = _a.treeData, defaultTreeData = _a.defaultTreeData, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, request = _a.request, asyncLoadChildren = _a.asyncLoadChildren, _c = _a.asyncLoadChildrenKey, asyncLoadChildrenKey = _c === void 0 ? 'parentId' : _c, transformData = _a.transformData, treeDataSimpleMode = _a.treeDataSimpleMode, onCompleted = _a.onCompleted, restProps = __rest(_a, ["treeData", "defaultTreeData", "params", "url", "method", "request", "asyncLoadChildren", "asyncLoadChildrenKey", "transformData", "treeDataSimpleMode", "onCompleted"]);
50
50
  /**
51
51
  * treeData 为当前组件使用的数据源
52
52
  * 这样做的目的,是因为如果做远程搜索和搜索方法组件内部处理时
53
53
  * 保证数据源唯一
54
54
  */
55
55
  var _d = useFetchState([]), treeData = _d[0], setTreeData = _d[1];
56
+ // 如果selectList 发生改变,那么触发onCompleted事件
57
+ useEffect(function () {
58
+ if (Array.isArray(treeData) && onCompleted) {
59
+ onCompleted(treeData);
60
+ }
61
+ }, [treeData, onCompleted]);
56
62
  // 获取数据,并设置数据
57
63
  var getDataHandle = useCallback(function (request, options, isConcat) {
58
64
  return getData(request, options)
@@ -24,6 +24,7 @@ interface IProps {
24
24
  isPublic?: boolean;
25
25
  /**额外的上传表格列配置 */
26
26
  otherColumns?: any;
27
+ showUploadBtn?: boolean;
27
28
  }
28
29
  declare const _default: React.NamedExoticComponent<IProps>;
29
30
  export default _default;
@@ -58,10 +58,102 @@ import { divide, round, times } from 'number-precision';
58
58
  import { downloadFileCallBack, downloadPublicFile, previewFile, } from 'ztxkutils/dist/fileOperation';
59
59
  import { transformFileSize } from 'ztxkutils/dist/tools';
60
60
  var UploadTable = function (_a) {
61
- var fileList = _a.fileList, action = _a.action, headers = _a.headers, authToken = _a.authToken, method = _a.method, apiBaseUrl = _a.apiBaseUrl, uploadUser = _a.uploadUser, _b = _a.fileBaseUrl, fileBaseUrl = _b === void 0 ? '' : _b, onDelete = _a.onDelete, onUpload = _a.onUpload, showDeleteBtn = _a.showDeleteBtn, isAutoDelete = _a.isAutoDelete, onDownLoadCallbackBefore = _a.onDownLoadCallbackBefore, showDownloadBtn = _a.showDownloadBtn, onDownLoadCallbackAfter = _a.onDownLoadCallbackAfter, onPreviewCallbackBefore = _a.onPreviewCallbackBefore, showPreviewBtn = _a.showPreviewBtn, isPublic = _a.isPublic, data = _a.data, _c = _a.otherColumns, otherColumns = _c === void 0 ? [] : _c;
61
+ var fileList = _a.fileList, action = _a.action, headers = _a.headers, authToken = _a.authToken, method = _a.method, apiBaseUrl = _a.apiBaseUrl, uploadUser = _a.uploadUser, _b = _a.fileBaseUrl, fileBaseUrl = _b === void 0 ? '' : _b, onDelete = _a.onDelete, onUpload = _a.onUpload, showDeleteBtn = _a.showDeleteBtn, isAutoDelete = _a.isAutoDelete, onDownLoadCallbackBefore = _a.onDownLoadCallbackBefore, showDownloadBtn = _a.showDownloadBtn, onDownLoadCallbackAfter = _a.onDownLoadCallbackAfter, onPreviewCallbackBefore = _a.onPreviewCallbackBefore, showPreviewBtn = _a.showPreviewBtn, isPublic = _a.isPublic, data = _a.data, _c = _a.otherColumns, otherColumns = _c === void 0 ? [] : _c, showUploadBtn = _a.showUploadBtn;
62
62
  var _d = useState([]), dataSource = _d[0], setDataSource = _d[1];
63
63
  var _e = useState(false), loading = _e[0], setLoading = _e[1];
64
- var columns = __spreadArray(__spreadArray([
64
+ var columns = showUploadBtn
65
+ ? __spreadArray(__spreadArray([
66
+ {
67
+ title: '文件名称',
68
+ width: 200,
69
+ fixed: 'left',
70
+ dataIndex: 'fileName',
71
+ key: 'fileName',
72
+ },
73
+ {
74
+ title: '文件大小',
75
+ width: 60,
76
+ dataIndex: 'fileSize',
77
+ key: 'fileSize',
78
+ render: function (value, record, index) {
79
+ return transformFileSize(value);
80
+ },
81
+ },
82
+ {
83
+ title: '上传时间',
84
+ width: 100,
85
+ dataIndex: 'uploadTime',
86
+ key: 'uploadTime',
87
+ },
88
+ {
89
+ title: '上传人',
90
+ width: 80,
91
+ dataIndex: 'uploadUser',
92
+ key: 'uploadUser',
93
+ }
94
+ ], otherColumns), [
95
+ {
96
+ title: '上传进度',
97
+ width: 200,
98
+ render: function (text, record, index) {
99
+ // uploading done error removed
100
+ var status = record.status === 'error' ? 'exception' : undefined;
101
+ if (record.status === 'error') {
102
+ return (React.createElement(Button, { type: "link", style: { color: '#ff4d4f' }, onClick: function () { return onSubmitFile(record.originFileObj, index); } }, "\u56FE\u7247\u4E0A\u4F20\u5931\u8D25\uFF0C\u91CD\u65B0\u4E0A\u4F20"));
103
+ }
104
+ return React.createElement(Progress, { percent: record === null || record === void 0 ? void 0 : record.percent, status: status });
105
+ },
106
+ },
107
+ {
108
+ title: '操作',
109
+ width: 80,
110
+ fixed: 'right',
111
+ render: function (text, record, index) {
112
+ return (React.createElement(React.Fragment, null,
113
+ showDownloadBtn && (React.createElement(Button, { type: "link", style: {
114
+ height: 28,
115
+ }, onClick: function () {
116
+ if (isPublic) {
117
+ downloadPublicFile(apiBaseUrl, record === null || record === void 0 ? void 0 : record.fileId, record === null || record === void 0 ? void 0 : record.fileName);
118
+ }
119
+ else {
120
+ // downloadFile(
121
+ // apiBaseUrl,
122
+ // record?.fileId,
123
+ // record?.fileName,
124
+ // authToken
125
+ // );
126
+ downloadFileCallBack(apiBaseUrl, record === null || record === void 0 ? void 0 : record.fileId, record === null || record === void 0 ? void 0 : record.fileName, {
127
+ authToken: authToken,
128
+ callbackAfter: function () {
129
+ onDownLoadCallbackAfter &&
130
+ onDownLoadCallbackAfter(record);
131
+ },
132
+ });
133
+ }
134
+ } }, "\u4E0B\u8F7D")),
135
+ showPreviewBtn && (React.createElement(Button, { type: "link", style: {
136
+ height: 28,
137
+ }, onClick: function () {
138
+ if ((record === null || record === void 0 ? void 0 : record.fileSize) >= 10 * 1024 * 1024) {
139
+ message.warning('文件过大,暂不支持在线预览,请先下载后查看!');
140
+ }
141
+ else {
142
+ previewFile(fileBaseUrl, record === null || record === void 0 ? void 0 : record.fileId, {
143
+ titleName: record === null || record === void 0 ? void 0 : record.fileName,
144
+ authToken: authToken,
145
+ });
146
+ onPreviewCallbackBefore &&
147
+ onPreviewCallbackBefore(record);
148
+ }
149
+ } }, "\u9884\u89C8")),
150
+ showDeleteBtn && (React.createElement(Popconfirm, { title: "\u662F\u5426\u5220\u9664\u8BE5\u6761\u6570\u636E?", cancelText: "\u5426", okText: "\u662F", onConfirm: function () { return onDeleteFile(record, index); } },
151
+ React.createElement(Button, { style: {
152
+ height: 28,
153
+ }, type: "link" }, "\u5220\u9664")))));
154
+ },
155
+ },
156
+ ]) : __spreadArray(__spreadArray([
65
157
  {
66
158
  title: '文件名称',
67
159
  width: 200,
@@ -81,7 +173,6 @@ var UploadTable = function (_a) {
81
173
  {
82
174
  title: '上传时间',
83
175
  width: 100,
84
- align: 'center',
85
176
  dataIndex: 'uploadTime',
86
177
  key: 'uploadTime',
87
178
  },
@@ -92,23 +183,10 @@ var UploadTable = function (_a) {
92
183
  key: 'uploadUser',
93
184
  }
94
185
  ], otherColumns), [
95
- {
96
- title: '上传进度',
97
- width: 200,
98
- render: function (text, record, index) {
99
- // uploading done error removed
100
- var status = record.status === 'error' ? 'exception' : undefined;
101
- if (record.status === 'error') {
102
- return (React.createElement(Button, { type: "link", style: { color: '#ff4d4f' }, onClick: function () { return onSubmitFile(record.originFileObj, index); } }, "\u56FE\u7247\u4E0A\u4F20\u5931\u8D25\uFF0C\u91CD\u65B0\u4E0A\u4F20"));
103
- }
104
- return React.createElement(Progress, { percent: record === null || record === void 0 ? void 0 : record.percent, status: status });
105
- },
106
- },
107
186
  {
108
187
  title: '操作',
109
188
  width: 80,
110
189
  fixed: 'right',
111
- align: 'center',
112
190
  render: function (text, record, index) {
113
191
  return (React.createElement(React.Fragment, null,
114
192
  showDownloadBtn && (React.createElement(Button, { type: "link", style: {
@@ -140,8 +218,12 @@ var UploadTable = function (_a) {
140
218
  message.warning('文件过大,暂不支持在线预览,请先下载后查看!');
141
219
  }
142
220
  else {
143
- previewFile(fileBaseUrl, record === null || record === void 0 ? void 0 : record.fileId, authToken);
144
- onPreviewCallbackBefore && onPreviewCallbackBefore(record);
221
+ previewFile(fileBaseUrl, record === null || record === void 0 ? void 0 : record.fileId, {
222
+ titleName: record === null || record === void 0 ? void 0 : record.fileName,
223
+ authToken: authToken,
224
+ });
225
+ onPreviewCallbackBefore &&
226
+ onPreviewCallbackBefore(record);
145
227
  }
146
228
  } }, "\u9884\u89C8")),
147
229
  showDeleteBtn && (React.createElement(Popconfirm, { title: "\u662F\u5426\u5220\u9664\u8BE5\u6761\u6570\u636E?", cancelText: "\u5426", okText: "\u662F", onConfirm: function () { return onDeleteFile(record, index); } },
@@ -154,12 +154,15 @@ var Upload = function (props) {
154
154
  var onFilePreview = function (file) {
155
155
  try {
156
156
  console.log(file);
157
- var attachId = file.response.data.attachId, size = file.size;
157
+ var _a = file.response.data, attachId = _a.attachId, attachName = _a.attachName, size = file.size;
158
158
  if (size >= 10 * 1024 * 1024) {
159
159
  message.warning('文件过大,暂不支持在线预览,请先下载后查看!');
160
160
  }
161
161
  else {
162
- previewFile(fileBaseUrl, attachId, authToken);
162
+ previewFile(fileBaseUrl, attachId, {
163
+ titleName: (file === null || file === void 0 ? void 0 : file.fileName) || attachName,
164
+ authToken: authToken,
165
+ });
163
166
  onPreviewCallbackBefore && onPreviewCallbackBefore(file);
164
167
  }
165
168
  }
@@ -181,6 +184,6 @@ var Upload = function (props) {
181
184
  "(\u5355\u4E2A\u9644\u4EF6\u6700\u5927\u652F\u6301",
182
185
  maxSizeTransStr,
183
186
  "\uFF0C\u652F\u6301\u683C\u5F0F\uFF1APDF\u3001Word\u3001Excel\u3001Txt\u3001JPG\u3001PNG\u3001BMP\u3001GIF\u3001RAR\u3001ZIP)")))),
184
- showTable && (React.createElement(UploadTable, { fileList: fileList, action: fileAction, apiBaseUrl: apiBaseUrl, fileBaseUrl: fileBaseUrl, headers: headers, method: method, uploadUser: uploadUser, onDelete: onDeleteHandle, onUpload: onUploadHandle, showDeleteBtn: showDeleteBtn, onDownLoadCallbackBefore: onDownLoadCallbackBefore, showDownloadBtn: showDownloadBtn, onDownLoadCallbackAfter: onDownLoadCallbackAfter, showPreviewBtn: showPreviewBtn, onPreviewCallbackBefore: onPreviewCallbackBefore, isAutoDelete: isAutoDelete, authToken: authToken, isPublic: isPublic, data: data, otherColumns: otherColumns }))));
187
+ showTable && (React.createElement(UploadTable, { fileList: fileList, action: fileAction, apiBaseUrl: apiBaseUrl, fileBaseUrl: fileBaseUrl, headers: headers, method: method, uploadUser: uploadUser, onDelete: onDeleteHandle, onUpload: onUploadHandle, showDeleteBtn: showDeleteBtn, onDownLoadCallbackBefore: onDownLoadCallbackBefore, showDownloadBtn: showDownloadBtn, onDownLoadCallbackAfter: onDownLoadCallbackAfter, showPreviewBtn: showPreviewBtn, onPreviewCallbackBefore: onPreviewCallbackBefore, isAutoDelete: isAutoDelete, authToken: authToken, isPublic: isPublic, data: data, otherColumns: otherColumns, showUploadBtn: showUploadBtn }))));
185
188
  };
186
189
  export default Upload;
@@ -83,7 +83,9 @@ var DetailList = function (_a) {
83
83
  message.warning('文件过大,暂不支持在线预览,请先下载后查看!');
84
84
  }
85
85
  else {
86
- previewFile(fileBaseUrl, item === null || item === void 0 ? void 0 : item.attachId);
86
+ previewFile(fileBaseUrl, item === null || item === void 0 ? void 0 : item.attachId, {
87
+ titleName: item === null || item === void 0 ? void 0 : item.attachName,
88
+ });
87
89
  onPreviewCallbackBefore &&
88
90
  onPreviewCallbackBefore(item);
89
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "1.5.6",
3
+ "version": "1.6.0",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",
@@ -78,7 +78,7 @@
78
78
  "source-map-explorer": "^2.5.2",
79
79
  "typescript": "^4.1.2",
80
80
  "web-vitals": "^1.0.1",
81
- "ztxkutils": "^1.9.0"
81
+ "ztxkutils": "^2.0.1"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "axios": ">=0.21.1",