gxxc-ui 1.0.43 → 1.0.45

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格式
@@ -109,10 +110,10 @@ var UploadUI = function UploadUI(props) {
109
110
  }
110
111
  };
111
112
 
112
- // 自定义上传
113
+ // 自定义上传 在Form.Item 中使用受控模式 onError 等 on 方法不能使用
113
114
  var customRequest = /*#__PURE__*/function () {
114
115
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
115
- 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;
116
117
  return _regeneratorRuntime().wrap(function _callee$(_context) {
117
118
  while (1) switch (_context.prev = _context.next) {
118
119
  case 0:
@@ -134,10 +135,22 @@ var UploadUI = function UploadUI(props) {
134
135
  return getOssDataAPI(scene, _fileName, md5Hash);
135
136
  case 11:
136
137
  ossData = _context.sent;
137
- if (!((ossData === null || ossData === void 0 ? void 0 : ossData.code) === '0')) {
138
- _context.next = 37;
138
+ if (!((ossData === null || ossData === void 0 ? void 0 : ossData.code) != '0')) {
139
+ _context.next = 16;
139
140
  break;
140
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);
141
154
  formData = new FormData();
142
155
  formData.append('key', ossData === null || ossData === void 0 || (_ossData$body = ossData.body) === null || _ossData$body === void 0 ? void 0 : _ossData$body.dir);
143
156
  formData.append('OSSAccessKeyId', ossData === null || ossData === void 0 || (_ossData$body2 = ossData.body) === null || _ossData$body2 === void 0 ? void 0 : _ossData$body2.accessId);
@@ -148,55 +161,62 @@ var UploadUI = function UploadUI(props) {
148
161
  formData.append('accessId', ossData === null || ossData === void 0 || (_ossData$body7 = ossData.body) === null || _ossData$body7 === void 0 ? void 0 : _ossData$body7.accessId);
149
162
  formData.append('dir', ossData === null || ossData === void 0 || (_ossData$body8 = ossData.body) === null || _ossData$body8 === void 0 ? void 0 : _ossData$body8.dir);
150
163
  formData.append('file', options === null || options === void 0 ? void 0 : options.file);
151
- _context.next = 25;
152
- return fetch(ossData === null || ossData === void 0 || (_ossData$body9 = ossData.body) === null || _ossData$body9 === void 0 ? void 0 : _ossData$body9.host, {
153
- method: 'POST',
154
- 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
+ }
155
177
  });
156
- case 25:
178
+ case 31:
157
179
  res = _context.sent;
158
- if (!(res !== null && res !== void 0 && res.ok)) {
159
- _context.next = 33;
160
- break;
161
- }
162
- _context.next = 29;
163
- return res.json();
164
- case 29:
165
- data = _context.sent;
166
- if ((data === null || data === void 0 ? void 0 : data.code) === '0') {
167
- 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);
168
- newFileList = [].concat(_toConsumableArray(fileList), [_objectSpread(_objectSpread({}, data === null || data === void 0 ? void 0 : data.body), {}, {
169
- name: _fileName
170
- })]).slice(-maxCount);
171
- setFileList(newFileList);
172
- 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
+ if (code === '0') {
183
+ item.url = body.url;
184
+ item.md5 = body.md5;
185
+ item.status = 'done';
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
+ item.status = 'error';
200
+ if (options !== null && options !== void 0 && options.onError) options.onError(msg, options === null || options === void 0 ? void 0 : options.file);
201
+ MessageUI.error(msg);
202
+ }
173
203
  } else {
174
- 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);
175
- MessageUI.error(data === null || data === void 0 ? void 0 : data.msg);
204
+ item.status = 'error';
205
+ errText = res.statusText;
206
+ if (options !== null && options !== void 0 && options.onError) options.onError(errText, options === null || options === void 0 ? void 0 : options.file);
207
+ MessageUI.error(errText);
176
208
  }
177
- _context.next = 35;
209
+ _context.next = 38;
178
210
  break;
179
- case 33:
180
- 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);
181
- MessageUI.error(res === null || res === void 0 ? void 0 : res.statusText);
182
211
  case 35:
183
- _context.next = 39;
184
- break;
185
- case 37:
186
- 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);
187
- MessageUI.error(ossData === null || ossData === void 0 ? void 0 : ossData.msg);
188
- case 39:
189
- _context.next = 44;
190
- break;
191
- case 41:
192
- _context.prev = 41;
212
+ _context.prev = 35;
193
213
  _context.t0 = _context["catch"](0);
194
214
  MessageUI.error('上传失败,请稍后重试!');
195
- case 44:
215
+ case 38:
196
216
  case "end":
197
217
  return _context.stop();
198
218
  }
199
- }, _callee, null, [[0, 41]]);
219
+ }, _callee, null, [[0, 35]]);
200
220
  }));
201
221
  return function customRequest(_x) {
202
222
  return _ref.apply(this, arguments);
@@ -260,13 +280,28 @@ var UploadUI = function UploadUI(props) {
260
280
  customRequest: customRequest,
261
281
  onRemove: onRemove
262
282
  }, otherProps);
283
+ var itemRender = function itemRender(originNode, file) {
284
+ if (file.status === 'uploading') {
285
+ return /*#__PURE__*/React.createElement("div", {
286
+ className: "uploadUI-mode2-content",
287
+ style: {
288
+ backgroundImage: "url(".concat(backgroundImage, ")")
289
+ }
290
+ }, /*#__PURE__*/React.createElement(Spin, {
291
+ percent: file.percent
292
+ }));
293
+ } else {
294
+ return originNode;
295
+ }
296
+ };
263
297
  return /*#__PURE__*/React.createElement(React.Fragment, null, mode === 1 && /*#__PURE__*/React.createElement(Upload, _extends({
264
298
  className: "uploadUI uploadUI-mode1 ".concat(className !== null && className !== void 0 ? className : ''),
265
299
  showUploadList: false
266
300
  }, uploadProps), children), mode === 2 && /*#__PURE__*/React.createElement(Upload, _extends({
267
301
  className: "uploadUI uploadUI-mode2 ".concat(className !== null && className !== void 0 ? className : ''),
268
302
  listType: "picture-card",
269
- onPreview: onPreview
303
+ onPreview: onPreview,
304
+ itemRender: itemRender
270
305
  }, uploadProps), (fileList === null || fileList === void 0 ? void 0 : fileList.length) >= maxCount ? null : /*#__PURE__*/React.createElement("div", {
271
306
  className: "uploadUI-mode2-content",
272
307
  style: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gxxc-ui",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
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",