gxxc-ui 1.0.42 → 1.0.44

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.
@@ -22,15 +22,16 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
22
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
23
23
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
24
24
  import { DownloadOutlined, RotateLeftOutlined, RotateRightOutlined, SwapOutlined, UndoOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons';
25
- import { Image, Space, Upload } from 'antd';
25
+ import { Image, Space, Upload, Spin } from 'antd';
26
26
  import React, { useEffect, useState } from 'react';
27
27
  import { IconUI, MessageUI } from "./..";
28
28
  import { file_calculate_md5, file_url_is_image, file_url_is_video_H264, getUrlConfig } from 'gxxc-util';
29
29
  import "./index.scss";
30
30
  import { DraggerFileItems } from "./type";
31
+ import axios from 'axios';
31
32
  // 文件名转义 后端解析地址需要排除部分符号
32
33
  var getCheckFileName = function getCheckFileName(name) {
33
- var fileName = name.replace(/\s*/g, '').replace(/&/g, '_').replace(/%/g, '').replace(/\.(?=.*\.)/g, '');
34
+ var fileName = name.replace(/\s*/g, '').replace(/&/g, '_').replace(/%/g, '').replace(/\[/g, '').replace(/]/g, '').replace(/\.(?=.*\.)/g, '');
34
35
  return fileName;
35
36
  };
36
37
  // 获取图片base64格式
@@ -86,10 +87,15 @@ var UploadUI = function UploadUI(props) {
86
87
  useEffect(function () {
87
88
  var newFileList = (value === null || value === void 0 ? void 0 : value.map(function (item, index) {
88
89
  var _getUrlConfig, _item$url;
89
- return _objectSpread(_objectSpread({}, item), {}, {
90
+ var param = _objectSpread(_objectSpread({}, item), {}, {
90
91
  uid: (item === null || item === void 0 ? void 0 : item.uid) || (item === null || item === void 0 ? void 0 : item.md5) || "temp_uid_".concat(Date.now(), "_").concat(index),
91
92
  name: (item === null || item === void 0 ? void 0 : item.name) || ((_getUrlConfig = getUrlConfig((_item$url = item === null || item === void 0 ? void 0 : item.url) !== null && _item$url !== void 0 ? _item$url : '')) === null || _getUrlConfig === void 0 ? void 0 : _getUrlConfig.fileName) || "file_".concat(index + 1)
92
93
  });
94
+ /// 如果是 h264 编码 显示第一帧
95
+ if (file_url_is_video_H264(param.url)) {
96
+ param.thumbUrl = "".concat(item.url, "?x-oss-process=video/snapshot,t_1000,f_jpg");
97
+ }
98
+ return param;
93
99
  })) || [];
94
100
  setFileList(newFileList);
95
101
  }, [value]);
@@ -104,10 +110,10 @@ var UploadUI = function UploadUI(props) {
104
110
  }
105
111
  };
106
112
 
107
- // 自定义上传
113
+ // 自定义上传 在Form.Item 中使用受控模式 onError 等 on 方法不能使用
108
114
  var customRequest = /*#__PURE__*/function () {
109
115
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
110
- var md5Hash, _fileName, ossData, _ossData$body, _ossData$body2, _ossData$body3, _ossData$body4, _ossData$body5, _ossData$body6, _ossData$body7, _ossData$body8, _ossData$body9, formData, res, data, newFileList;
116
+ var _ossData$body, _ossData$body2, _ossData$body3, _ossData$body4, _ossData$body5, _ossData$body6, _ossData$body7, _ossData$body8, _ossData$body9, md5Hash, _fileName, ossData, item, newFileList, formData, res, _res$data, code, body, msg, errText;
111
117
  return _regeneratorRuntime().wrap(function _callee$(_context) {
112
118
  while (1) switch (_context.prev = _context.next) {
113
119
  case 0:
@@ -129,10 +135,22 @@ var UploadUI = function UploadUI(props) {
129
135
  return getOssDataAPI(scene, _fileName, md5Hash);
130
136
  case 11:
131
137
  ossData = _context.sent;
132
- if (!((ossData === null || ossData === void 0 ? void 0 : ossData.code) === '0')) {
133
- _context.next = 37;
138
+ if (!((ossData === null || ossData === void 0 ? void 0 : ossData.code) != '0')) {
139
+ _context.next = 16;
134
140
  break;
135
141
  }
142
+ if (options !== null && options !== void 0 && options.onError) options.onError(ossData === null || ossData === void 0 ? void 0 : ossData.msg, options === null || options === void 0 ? void 0 : options.file);
143
+ MessageUI.error(ossData === null || ossData === void 0 ? void 0 : ossData.msg);
144
+ return _context.abrupt("return");
145
+ case 16:
146
+ /// 设置默认 上传状态
147
+ item = {
148
+ name: _fileName,
149
+ status: 'uploading',
150
+ percent: 0
151
+ };
152
+ newFileList = [].concat(_toConsumableArray(fileList), [item]).slice(-maxCount);
153
+ setFileList(newFileList);
136
154
  formData = new FormData();
137
155
  formData.append('key', ossData === null || ossData === void 0 || (_ossData$body = ossData.body) === null || _ossData$body === void 0 ? void 0 : _ossData$body.dir);
138
156
  formData.append('OSSAccessKeyId', ossData === null || ossData === void 0 || (_ossData$body2 = ossData.body) === null || _ossData$body2 === void 0 ? void 0 : _ossData$body2.accessId);
@@ -143,55 +161,61 @@ var UploadUI = function UploadUI(props) {
143
161
  formData.append('accessId', ossData === null || ossData === void 0 || (_ossData$body7 = ossData.body) === null || _ossData$body7 === void 0 ? void 0 : _ossData$body7.accessId);
144
162
  formData.append('dir', ossData === null || ossData === void 0 || (_ossData$body8 = ossData.body) === null || _ossData$body8 === void 0 ? void 0 : _ossData$body8.dir);
145
163
  formData.append('file', options === null || options === void 0 ? void 0 : options.file);
146
- _context.next = 25;
147
- return fetch(ossData === null || ossData === void 0 || (_ossData$body9 = ossData.body) === null || _ossData$body9 === void 0 ? void 0 : _ossData$body9.host, {
148
- method: 'POST',
149
- body: formData
164
+ _context.next = 31;
165
+ return axios.post(ossData === null || ossData === void 0 || (_ossData$body9 = ossData.body) === null || _ossData$body9 === void 0 ? void 0 : _ossData$body9.host, formData, {
166
+ // 如果需要监听上传进度,可以添加此回调
167
+ onUploadProgress: function onUploadProgress(progressEvent) {
168
+ setFileList(function (prevList) {
169
+ var percent = 0;
170
+ if (progressEvent.total) {
171
+ percent = Math.floor(progressEvent.loaded / progressEvent.total * 100);
172
+ }
173
+ item.percent = percent;
174
+ return _toConsumableArray(prevList);
175
+ });
176
+ }
150
177
  });
151
- case 25:
178
+ case 31:
152
179
  res = _context.sent;
153
- if (!(res !== null && res !== void 0 && res.ok)) {
154
- _context.next = 33;
155
- break;
156
- }
157
- _context.next = 29;
158
- return res.json();
159
- case 29:
160
- data = _context.sent;
161
- if ((data === null || data === void 0 ? void 0 : data.code) === '0') {
162
- if (options !== null && options !== void 0 && options.onSuccess) options.onSuccess(data === null || data === void 0 ? void 0 : data.body, options === null || options === void 0 ? void 0 : options.file);
163
- newFileList = [].concat(_toConsumableArray(fileList), [_objectSpread(_objectSpread({}, data === null || data === void 0 ? void 0 : data.body), {}, {
164
- name: _fileName
165
- })]).slice(-maxCount);
166
- setFileList(newFileList);
167
- if (onChange) onChange(newFileList);
180
+ if (res.status == 200) {
181
+ _res$data = res.data, code = _res$data.code, body = _res$data.body, msg = _res$data.msg;
182
+ item.status = '';
183
+ if (code === '0') {
184
+ item.url = body.url;
185
+ item.md5 = body.md5;
186
+ /// 如果是 h264 编码 显示第一帧
187
+ if (file_url_is_video_H264(item.url)) {
188
+ item.thumbUrl = "".concat(item.url, "?x-oss-process=video/snapshot,t_1000,f_jpg");
189
+ }
190
+ if (options !== null && options !== void 0 && options.onSuccess) options.onSuccess(item, options === null || options === void 0 ? void 0 : options.file);
191
+ if (onChange) {
192
+ onChange(newFileList);
193
+ } else {
194
+ setFileList(function (prevList) {
195
+ return _toConsumableArray(prevList);
196
+ });
197
+ }
198
+ } else {
199
+ if (options !== null && options !== void 0 && options.onError) options.onError(msg, options === null || options === void 0 ? void 0 : options.file);
200
+ MessageUI.error(msg);
201
+ }
168
202
  } else {
169
- if (options !== null && options !== void 0 && options.onError) options.onError(data === null || data === void 0 ? void 0 : data.msg, options === null || options === void 0 ? void 0 : options.file);
170
- MessageUI.error(data === null || data === void 0 ? void 0 : data.msg);
203
+ item.status = 'error';
204
+ errText = res.statusText;
205
+ if (options !== null && options !== void 0 && options.onError) options.onError(errText, options === null || options === void 0 ? void 0 : options.file);
206
+ MessageUI.error(errText);
171
207
  }
172
- _context.next = 35;
208
+ _context.next = 38;
173
209
  break;
174
- case 33:
175
- if (options !== null && options !== void 0 && options.onError) options.onError(res === null || res === void 0 ? void 0 : res.statusText, options === null || options === void 0 ? void 0 : options.file);
176
- MessageUI.error(res === null || res === void 0 ? void 0 : res.statusText);
177
210
  case 35:
178
- _context.next = 39;
179
- break;
180
- case 37:
181
- if (options !== null && options !== void 0 && options.onError) options.onError(ossData === null || ossData === void 0 ? void 0 : ossData.msg, options === null || options === void 0 ? void 0 : options.file);
182
- MessageUI.error(ossData === null || ossData === void 0 ? void 0 : ossData.msg);
183
- case 39:
184
- _context.next = 44;
185
- break;
186
- case 41:
187
- _context.prev = 41;
211
+ _context.prev = 35;
188
212
  _context.t0 = _context["catch"](0);
189
213
  MessageUI.error('上传失败,请稍后重试!');
190
- case 44:
214
+ case 38:
191
215
  case "end":
192
216
  return _context.stop();
193
217
  }
194
- }, _callee, null, [[0, 41]]);
218
+ }, _callee, null, [[0, 35]]);
195
219
  }));
196
220
  return function customRequest(_x) {
197
221
  return _ref.apply(this, arguments);
@@ -206,7 +230,6 @@ var UploadUI = function UploadUI(props) {
206
230
  };
207
231
  var onPreview = /*#__PURE__*/function () {
208
232
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(file) {
209
- var mp4Url;
210
233
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
211
234
  while (1) switch (_context2.prev = _context2.next) {
212
235
  case 0:
@@ -219,25 +242,13 @@ var UploadUI = function UploadUI(props) {
219
242
  case 3:
220
243
  file.preview = _context2.sent;
221
244
  case 4:
222
- if (!file_url_is_image(file.url)) {
223
- _context2.next = 8;
224
- break;
225
- }
226
- setPreviewImage(file.url || file.preview);
227
- setPreviewOpen(true);
228
- return _context2.abrupt("return");
229
- case 8:
230
- if (!file_url_is_video_H264(file.url)) {
231
- _context2.next = 13;
232
- break;
245
+ if (file_url_is_image(file.url)) {
246
+ setPreviewImage(file.url || file.preview);
247
+ setPreviewOpen(true);
248
+ } else {
249
+ open(file.url);
233
250
  }
234
- mp4Url = file.url + "?x-oss-process=video/snapshot,t_1000,f_jp" || file.preview;
235
- setPreviewImage(mp4Url);
236
- setPreviewOpen(true);
237
- return _context2.abrupt("return");
238
- case 13:
239
- open(file.url);
240
- case 14:
251
+ case 5:
241
252
  case "end":
242
253
  return _context2.stop();
243
254
  }
@@ -268,13 +279,28 @@ var UploadUI = function UploadUI(props) {
268
279
  customRequest: customRequest,
269
280
  onRemove: onRemove
270
281
  }, otherProps);
282
+ var itemRender = function itemRender(originNode, file) {
283
+ if (file.status === 'uploading') {
284
+ return /*#__PURE__*/React.createElement("div", {
285
+ className: "uploadUI-mode2-content",
286
+ style: {
287
+ backgroundImage: "url(".concat(backgroundImage, ")")
288
+ }
289
+ }, /*#__PURE__*/React.createElement(Spin, {
290
+ percent: file.percent
291
+ }));
292
+ } else {
293
+ return originNode;
294
+ }
295
+ };
271
296
  return /*#__PURE__*/React.createElement(React.Fragment, null, mode === 1 && /*#__PURE__*/React.createElement(Upload, _extends({
272
297
  className: "uploadUI uploadUI-mode1 ".concat(className !== null && className !== void 0 ? className : ''),
273
298
  showUploadList: false
274
299
  }, uploadProps), children), mode === 2 && /*#__PURE__*/React.createElement(Upload, _extends({
275
300
  className: "uploadUI uploadUI-mode2 ".concat(className !== null && className !== void 0 ? className : ''),
276
301
  listType: "picture-card",
277
- onPreview: onPreview
302
+ onPreview: onPreview,
303
+ itemRender: itemRender
278
304
  }, uploadProps), (fileList === null || fileList === void 0 ? void 0 : fileList.length) >= maxCount ? null : /*#__PURE__*/React.createElement("div", {
279
305
  className: "uploadUI-mode2-content",
280
306
  style: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gxxc-ui",
3
- "version": "1.0.42",
3
+ "version": "1.0.44",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -49,6 +49,7 @@
49
49
  "@wangeditor/editor": "^5.1.23",
50
50
  "@wangeditor/editor-for-react": "^1.0.6",
51
51
  "antd": "^5.27.1",
52
+ "axios": "^1.7.9",
52
53
  "dayjs": "^1.11.11",
53
54
  "lodash": "^4.17.21",
54
55
  "react-countup": "^6.5.3",