ztxkui 4.2.0 → 4.2.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.
@@ -81,6 +81,30 @@ var test = {
81
81
  isWatermark: 0,
82
82
  isElectronicSeal: 0,
83
83
  },
84
+ {
85
+ attachId: '7079304674563981473',
86
+ attachName: '260930039_640_640.jpg',
87
+ attachTypeName: null,
88
+ isCustomerReference: null,
89
+ templateAttachId: null,
90
+ templateAttachName: null,
91
+ templateCrNo: null,
92
+ taskId: null,
93
+ isWatermark: 0,
94
+ isElectronicSeal: 0,
95
+ },
96
+ {
97
+ attachId: '7079304674563981470',
98
+ attachName: '260930040_640_640.jpg',
99
+ attachTypeName: null,
100
+ isCustomerReference: null,
101
+ templateAttachId: null,
102
+ templateAttachName: null,
103
+ templateCrNo: null,
104
+ taskId: null,
105
+ isWatermark: 0,
106
+ isElectronicSeal: 0,
107
+ },
84
108
  {
85
109
  attachId: '1590543945628586394',
86
110
  attachName: '心量于里两222.pdf',
@@ -66,9 +66,10 @@ import { Button, Progress, message, Popconfirm } from '../../index';
66
66
  import Table from '../Table';
67
67
  import dayjs from 'dayjs';
68
68
  import { divide, round, times } from 'number-precision';
69
- import { downloadFileCallBack, downloadPublicFile, previewFile, } from 'ztxkutils/dist/fileOperation';
69
+ import { downloadFileCallBack, downloadPublicFile, previewFile, batchPreviewFile, } from 'ztxkutils/dist/fileOperation';
70
70
  import { transformFileSize, dangerouslySetXss } from 'ztxkutils/dist/tools';
71
71
  import { MAX_PREVIEW_FILE_SIZE } from '../utils/constants';
72
+ import { isImage } from '../utils/upload';
72
73
  var UploadTable = function (_a) {
73
74
  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.startColumns, startColumns = _c === void 0 ? [] : _c, _d = _a.otherColumns, otherColumns = _d === void 0 ? [] : _d, showUploadBtn = _a.showUploadBtn, rowSelection = _a.rowSelection, uploadTableRef = _a.uploadTableRef, tableRestProps = _a.tableRestProps, privateTableRef = _a.privateTableRef;
74
75
  var _e = useState([]), dataSource = _e[0], setDataSource = _e[1];
@@ -91,6 +92,37 @@ var UploadTable = function (_a) {
91
92
  }
92
93
  },
93
94
  }); }, [selectedRows, rowSelection]);
95
+ var previewBtn = function (previewTitle, previewOptions) {
96
+ var record = previewOptions.record, dataSource = previewOptions.dataSource;
97
+ return (React.createElement(Button, { type: "link", style: {
98
+ height: 28,
99
+ }, onClick: function () {
100
+ // 实现批量预览,只针对图片
101
+ var result = isImage(record.fileName);
102
+ if (result) {
103
+ var allImage = dataSource
104
+ .filter(function (item) {
105
+ return isImage(item.fileName) && item.fileId !== record.fileId;
106
+ })
107
+ .map(function (item) { return item.fileId; });
108
+ batchPreviewFile(fileBaseUrl, record.fileId + "," + allImage, {
109
+ titleName: record === null || record === void 0 ? void 0 : record.fileName,
110
+ authToken: authToken,
111
+ });
112
+ return;
113
+ }
114
+ if ((record === null || record === void 0 ? void 0 : record.fileSize) >= MAX_PREVIEW_FILE_SIZE) {
115
+ message.warning('文件大于20MB,暂不支持在线预览,请先下载后查看!');
116
+ }
117
+ else {
118
+ previewFile(fileBaseUrl, record === null || record === void 0 ? void 0 : record.fileId, {
119
+ titleName: record === null || record === void 0 ? void 0 : record.fileName,
120
+ authToken: authToken,
121
+ });
122
+ onPreviewCallbackBefore && onPreviewCallbackBefore(record);
123
+ }
124
+ } }, previewTitle));
125
+ };
94
126
  var columns = showUploadBtn
95
127
  ? __spreadArray(__spreadArray(__spreadArray(__spreadArray([], startColumns), [
96
128
  {
@@ -99,8 +131,20 @@ var UploadTable = function (_a) {
99
131
  // fixed: 'left',
100
132
  dataIndex: 'fileName',
101
133
  key: 'fileName',
102
- render: function (value) {
103
- return dangerouslySetXss(value);
134
+ render: function (value, record) {
135
+ var operationAuth = record === null || record === void 0 ? void 0 : record.operationAuth;
136
+ var authPreviewBtn = typeof operationAuth === 'string' &&
137
+ operationAuth.indexOf('1') !== -1
138
+ ? true
139
+ : false;
140
+ return (typeof operationAuth === 'string'
141
+ ? authPreviewBtn
142
+ : showPreviewBtn)
143
+ ? previewBtn(dangerouslySetXss(value), {
144
+ record: record,
145
+ dataSource: dataSource,
146
+ })
147
+ : dangerouslySetXss(value);
104
148
  },
105
149
  },
106
150
  {
@@ -268,20 +312,11 @@ var UploadTable = function (_a) {
268
312
  } }, "\u4E0B\u8F7D")),
269
313
  (typeof operationAuth === 'string'
270
314
  ? authPreviewBtn
271
- : showPreviewBtn) && (React.createElement(Button, { type: "link", style: {
272
- height: 28,
273
- }, onClick: function () {
274
- if ((record === null || record === void 0 ? void 0 : record.fileSize) >= MAX_PREVIEW_FILE_SIZE) {
275
- message.warning('文件大于20MB,暂不支持在线预览,请先下载后查看!');
276
- }
277
- else {
278
- previewFile(fileBaseUrl, record === null || record === void 0 ? void 0 : record.fileId, {
279
- titleName: record === null || record === void 0 ? void 0 : record.fileName,
280
- authToken: authToken,
281
- });
282
- onPreviewCallbackBefore && onPreviewCallbackBefore(record);
283
- }
284
- } }, "\u9884\u89C8")),
315
+ : showPreviewBtn) &&
316
+ previewBtn('预览', {
317
+ record: record,
318
+ dataSource: dataSource,
319
+ }),
285
320
  (typeof operationAuth === 'string'
286
321
  ? authDeleteBtn
287
322
  : showDeleteBtn) && (React.createElement(Popconfirm, { title: "\u662F\u5426\u5220\u9664\u8BE5\u6761\u6570\u636E?", cancelText: "\u5426", okText: "\u662F", onConfirm: function () { return onDeleteFile(record, index); } },
@@ -12,6 +12,7 @@ interface IProps {
12
12
  attachSize?: any;
13
13
  showDeleteBtn?: boolean;
14
14
  onDeleteFile?: any;
15
+ dataSource?: any;
15
16
  }
16
17
  declare const AttachOperation: React.FC<IProps>;
17
18
  export default AttachOperation;
@@ -10,30 +10,46 @@ import { Button, message, Popconfirm } from '../../../../index';
10
10
  // store
11
11
  // 自定义组件
12
12
  // 其他文件
13
- import { downloadFileCallBack, previewFile, } from 'ztxkutils/dist/fileOperation';
13
+ import { downloadFileCallBack, previewFile, batchPreviewFile, } from 'ztxkutils/dist/fileOperation';
14
14
  import { dangerouslySetXss } from 'ztxkutils/dist/tools';
15
15
  import { MAX_PREVIEW_FILE_SIZE } from '../../../utils/constants';
16
+ import { isImage } from '../../../utils/upload';
16
17
  var AttachOperation = function (_a) {
17
- var attachId = _a.attachId, attachName = _a.attachName, attachSize = _a.attachSize, ZT_API_BASEURL = _a.ZT_API_BASEURL, ZT_FILE_BASEURL = _a.ZT_FILE_BASEURL, token = _a.token, _b = _a.showDeleteBtn, showDeleteBtn = _b === void 0 ? false : _b, onDeleteFile = _a.onDeleteFile;
18
+ var attachId = _a.attachId, attachName = _a.attachName, attachSize = _a.attachSize, ZT_API_BASEURL = _a.ZT_API_BASEURL, ZT_FILE_BASEURL = _a.ZT_FILE_BASEURL, token = _a.token, _b = _a.showDeleteBtn, showDeleteBtn = _b === void 0 ? false : _b, onDeleteFile = _a.onDeleteFile, dataSource = _a.dataSource;
19
+ var previewBtn = function (attachId, previewTitle) {
20
+ return (React.createElement(Button, { type: "link", onClick: function () {
21
+ // 实现批量预览,只针对图片
22
+ var result = isImage(attachName);
23
+ if (result) {
24
+ var allImage = (Array.isArray(dataSource) ? dataSource : [])
25
+ .filter(function (item) { return isImage(item.attachName) && item.attachId !== attachId; })
26
+ .map(function (item) { return item.attachId; });
27
+ batchPreviewFile(ZT_FILE_BASEURL, attachId + "," + allImage, {
28
+ titleName: attachName,
29
+ authToken: token,
30
+ });
31
+ return;
32
+ }
33
+ if (attachSize >= MAX_PREVIEW_FILE_SIZE) {
34
+ message.warning('文件过大,暂不支持在线预览,请先下载后查看!');
35
+ }
36
+ else {
37
+ previewFile(ZT_FILE_BASEURL, attachId, {
38
+ titleName: dangerouslySetXss(attachName),
39
+ authToken: token,
40
+ });
41
+ }
42
+ } }, previewTitle));
43
+ };
18
44
  return attachId ? (React.createElement("div", { className: "signatures-attach" },
19
- React.createElement("div", { className: "signatures-attach--text", title: dangerouslySetXss(attachName) }, dangerouslySetXss(attachName)),
45
+ React.createElement("div", { className: "signatures-attach--text", title: dangerouslySetXss(attachName) }, previewBtn(attachId, dangerouslySetXss(attachName))),
20
46
  React.createElement("div", { className: "signatures-attach--operation" },
21
47
  React.createElement(Button, { type: "link", onClick: function () {
22
48
  downloadFileCallBack(ZT_API_BASEURL, attachId, dangerouslySetXss(attachName) || '附件', {
23
49
  authToken: token,
24
50
  });
25
51
  } }, "\u4E0B\u8F7D"),
26
- React.createElement(Button, { type: "link", onClick: function () {
27
- if (attachSize >= MAX_PREVIEW_FILE_SIZE) {
28
- message.warning('文件过大,暂不支持在线预览,请先下载后查看!');
29
- }
30
- else {
31
- previewFile(ZT_FILE_BASEURL, attachId, {
32
- titleName: dangerouslySetXss(attachName),
33
- authToken: token,
34
- });
35
- }
36
- } }, "\u9884\u89C8"),
52
+ previewBtn(attachId, '预览'),
37
53
  showDeleteBtn && (React.createElement(Popconfirm, { title: "\u662F\u5426\u5220\u9664\u8BE5\u6761\u6570\u636E?", cancelText: "\u5426", okText: "\u662F", onConfirm: function () { return onDeleteFile(); } },
38
54
  React.createElement(Button, { type: "link" }, "\u5220\u9664")))))) : null;
39
55
  };
@@ -74,7 +74,7 @@ var DetailTable = function (_a) {
74
74
  width: 240,
75
75
  render: function (text, record, index) {
76
76
  return (React.createElement(React.Fragment, null,
77
- React.createElement(AttachOperation, { ZT_API_BASEURL: ZT_API_BASEURL, ZT_FILE_BASEURL: ZT_FILE_BASEURL, token: authToken, attachId: record === null || record === void 0 ? void 0 : record.attachId, attachName: record === null || record === void 0 ? void 0 : record.attachName, attachSize: record === null || record === void 0 ? void 0 : record.attachSize })));
77
+ React.createElement(AttachOperation, { ZT_API_BASEURL: ZT_API_BASEURL, ZT_FILE_BASEURL: ZT_FILE_BASEURL, token: authToken, attachId: record === null || record === void 0 ? void 0 : record.attachId, attachName: record === null || record === void 0 ? void 0 : record.attachName, attachSize: record === null || record === void 0 ? void 0 : record.attachSize, dataSource: records })));
78
78
  },
79
79
  },
80
80
  {
@@ -3,6 +3,10 @@ import { RcFile } from 'antd/lib/upload';
3
3
  * 截取文件后缀
4
4
  */
5
5
  export declare function getFileSuffix(fileName: string): string;
6
+ /**
7
+ * 判断是否是图片
8
+ */
9
+ export declare function isImage(fileName: string | undefined): boolean;
6
10
  interface ICheckFileProps {
7
11
  /**允许上传的文件类型 */
8
12
  ztAccept?: string[];
@@ -13,6 +13,38 @@ export function getFileSuffix(fileName) {
13
13
  var len = fileName.length;
14
14
  return fileName.substring(index, len).toLowerCase() || '-';
15
15
  }
16
+ /**
17
+ * 判断是否是图片
18
+ */
19
+ export function isImage(fileName) {
20
+ if (!fileName) {
21
+ return false;
22
+ }
23
+ try {
24
+ var fileSuffix = getFileSuffix(fileName);
25
+ var imageSuffix = [
26
+ '.jpg',
27
+ '.png',
28
+ '.jpeg',
29
+ '.gif',
30
+ '.tif',
31
+ '.tga',
32
+ '.bmp',
33
+ '.dds',
34
+ '.svg',
35
+ '.webp',
36
+ ];
37
+ if (imageSuffix.includes(fileSuffix)) {
38
+ return true;
39
+ }
40
+ else {
41
+ return false;
42
+ }
43
+ }
44
+ catch (err) {
45
+ return false;
46
+ }
47
+ }
16
48
  var _accept = [
17
49
  '.pdf',
18
50
  '.txt',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",