@titaui/pc 1.13.2-beta.1 → 1.13.2-beta.12

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.
Files changed (41) hide show
  1. package/lib/components/dynamic/dynamic-item/components/okr-progress/index.js +2 -1
  2. package/lib/components/dynamic/dynamic-item/components/table-row-okr/index.css +12 -0
  3. package/lib/components/dynamic/dynamic-item/components/table-row-okr/index.js +13 -2
  4. package/lib/components/dynamic/dynamic-item/components/table-row-okr/utils.js +56 -0
  5. package/lib/components/dynamic/dynamic-item/dynamic-new-report/components/remind-user-view/index.css +16 -1
  6. package/lib/components/dynamic/dynamic-item/dynamic-new-report/components/remind-user-view/index.js +51 -9
  7. package/lib/components/dynamic/dynamic-item/dynamic-new-report/index.js +27 -10
  8. package/lib/components/dynamic/dynamic-item/index.js +23 -3
  9. package/lib/components/dynamic/request-api.js +9 -2
  10. package/lib/components/file-list/components/single-file/index.js +1 -3
  11. package/lib/components/file-list/index.js +1 -2
  12. package/lib/components/nav-top/components/app-center/index.js +1 -6
  13. package/lib/components/nav-top/components/menu/index.js +14 -44
  14. package/lib/components/rich-editor-at/index.js +85 -13
  15. package/lib/components/scroll-container/index.js +6 -27
  16. package/lib/components/search-input/index.js +0 -3
  17. package/lib/components/upload/index.js +456 -260
  18. package/lib/utils/tools.js +1 -11
  19. package/package.json +2 -2
  20. package/lib/components/checkbox-list/index.css +0 -18
  21. package/lib/components/checkbox-list/index.js +0 -66
  22. package/lib/components/dialog-qq-docs/index.css +0 -90
  23. package/lib/components/dialog-qq-docs/index.js +0 -488
  24. package/lib/components/dialog-qq-docs/request-apis.js +0 -16
  25. package/lib/components/dialog-qq-docs/utils.js +0 -76
  26. package/lib/components/dialog-select/index.css +0 -9
  27. package/lib/components/dialog-select/index.js +0 -48
  28. package/lib/components/dialog-upload-type/assets/folder.svg +0 -20
  29. package/lib/components/dialog-upload-type/assets/qq-docs.svg +0 -20
  30. package/lib/components/dialog-upload-type/components/upload-type-item/index.css +0 -14
  31. package/lib/components/dialog-upload-type/components/upload-type-item/index.js +0 -36
  32. package/lib/components/dialog-upload-type/index.css +0 -7
  33. package/lib/components/dialog-upload-type/index.js +0 -75
  34. package/lib/components/file-preview/index.css +0 -37
  35. package/lib/components/file-preview/index.js +0 -68
  36. package/lib/components/loading/assets/loading.gif +0 -0
  37. package/lib/components/loading/index.css +0 -23
  38. package/lib/components/loading/index.js +0 -30
  39. package/lib/components/nav/index.css +0 -23
  40. package/lib/components/nav/index.js +0 -31
  41. package/lib/components/upload/upload.js +0 -555
@@ -11,27 +11,25 @@ var _react = _interopRequireWildcard(require("react"));
11
11
 
12
12
  var _titaUi = require("tita-ui");
13
13
 
14
- var _dialogUploadType = _interopRequireDefault(require("../dialog-upload-type"));
15
-
16
- var _dialogQqDocs = _interopRequireDefault(require("../dialog-qq-docs"));
17
-
18
- var _getLocale = require("../../utils/getLocale");
14
+ var _uuid = _interopRequireDefault(require("uuid"));
19
15
 
20
16
  var _Portals = _interopRequireDefault(require("../../components-v1/portals/Portals"));
21
17
 
22
- var _upload = _interopRequireDefault(require("../upload/upload"));
18
+ var _requestV = require("../../utils/request-v1");
23
19
 
24
- require("./index.css");
20
+ var _toast = _interopRequireDefault(require("../toast"));
25
21
 
26
- var _utils = require("../dialog-qq-docs/utils");
22
+ var _uploadedPreview = _interopRequireDefault(require("./components/uploadedPreview"));
27
23
 
28
- var _platform = require("../../utils/platform");
24
+ var _type = require("./type");
29
25
 
30
- var _uploadedPreview = _interopRequireDefault(require("./components/uploadedPreview"));
26
+ var _style = require("./style");
31
27
 
32
- var _tools = require("../../utils/tools");
28
+ var _imgViewer = _interopRequireDefault(require("../img-viewer"));
33
29
 
34
- var _excluded = ["children", "onlyLocal", "attachmentTipText"];
30
+ var _util = require("./util");
31
+
32
+ var _getLocale = require("../../utils/getLocale");
35
33
 
36
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
37
35
 
@@ -39,307 +37,505 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
39
37
 
40
38
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
39
 
40
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
41
+
42
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
43
+
44
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
45
+
46
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
47
+
48
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
49
+
50
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
51
+
42
52
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
43
53
 
44
54
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
45
55
 
46
56
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
47
57
 
48
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
58
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
49
59
 
50
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
60
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
51
61
 
52
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
62
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
53
63
 
54
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
64
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
55
65
 
56
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
66
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
57
67
 
58
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
68
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
59
69
 
60
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
70
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
61
71
 
62
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
72
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
63
73
 
64
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
74
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
65
75
 
66
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
76
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
67
77
 
68
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
78
+ var Upload = /*#__PURE__*/function (_PureComponent) {
79
+ _inherits(Upload, _PureComponent);
69
80
 
70
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
81
+ var _super = _createSuper(Upload);
71
82
 
72
- 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; }
83
+ function Upload(props) {
84
+ var _this;
73
85
 
74
- 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; }
86
+ _classCallCheck(this, Upload);
75
87
 
76
- /** 是否开启腾讯文档选项 */
77
- var openTencentDocFile = window.BSGlobal && window.BSGlobal.TenantAdvancedSetting.TenantFunAdvancedSetting.TencentDocFile && // 默认在钉钉环境下禁用
78
- !(0, _platform.isDD)(true);
88
+ _this = _super.call(this, props);
79
89
 
80
- var onDefaultSubmit = function onDefaultSubmit() {};
90
+ _this.onFileInputChange = function () {
91
+ var fileInput = _this.refs.fileInput; // @ts-ignore
81
92
 
82
- var UploadMode = function UploadMode(_ref) {
83
- var children = _ref.children,
84
- _ref$onlyLocal = _ref.onlyLocal,
85
- onlyLocal = _ref$onlyLocal === void 0 ? !openTencentDocFile : _ref$onlyLocal,
86
- _ref$attachmentTipTex = _ref.attachmentTipText,
87
- attachmentTipText = _ref$attachmentTipTex === void 0 ? (0, _getLocale.getLocale)('OKR_MyO_KRP_Draganddropu') : _ref$attachmentTipTex,
88
- restProps = _objectWithoutProperties(_ref, _excluded);
93
+ var selectFiles = fileInput.files; // 选择的文件
94
+ // @ts-ignore
89
95
 
90
- var _useState = (0, _react.useState)(),
91
- _useState2 = _slicedToArray(_useState, 2),
92
- defaultQQDocsData = _useState2[0],
93
- setDefaultQQDocsData = _useState2[1]; // 区分存储腾讯文档数据和本地文件
96
+ if (!fileInput.value) return; // 未选择文件或选择文件超出个数限制时
94
97
 
98
+ _this.dealSelectFiles(Array.from(selectFiles));
95
99
 
96
- var _useState3 = (0, _react.useState)([]),
97
- _useState4 = _slicedToArray(_useState3, 2),
98
- qqFileData = _useState4[0],
99
- setQQFileData = _useState4[1];
100
+ if (fileInput) {
101
+ // @ts-ignore
102
+ fileInput.value = '';
103
+ }
104
+ };
105
+
106
+ _this.dealSelectFiles = function (uploadSelectFilesObj) {
107
+ var _this$state = _this.state,
108
+ uploadSuccessFiles = _this$state.uploadSuccessFiles,
109
+ selectFiles = _this$state.selectFiles;
110
+ var _this$props = _this.props,
111
+ action = _this$props.action,
112
+ fileNumLimit = _this$props.fileNumLimit,
113
+ fileSizeLimit = _this$props.fileSizeLimit,
114
+ filesTotal = _this$props.filesTotal;
115
+ var uploadSelectFilesLen = uploadSelectFilesObj.length; // 选中上传的文件数量
116
+
117
+ var uploadSuccessFilesLen = uploadSuccessFiles.length; // 已上传成功的文件数量
100
118
 
101
- var _useState5 = (0, _react.useState)([]),
102
- _useState6 = _slicedToArray(_useState5, 2),
103
- localFileData = _useState6[0],
104
- setLocalFileData = _useState6[1];
119
+ var allFilesTotal = uploadSuccessFilesLen + uploadSelectFilesLen; // 把文件字节流保存,用来文件重传用
105
120
 
106
- var _useState7 = (0, _react.useState)([]),
107
- _useState8 = _slicedToArray(_useState7, 2),
108
- allFileData = _useState8[0],
109
- setAllFileData = _useState8[1];
121
+ uploadSelectFilesObj.forEach(function (ele) {
122
+ if (!selectFiles[ele.name]) {
123
+ selectFiles[ele.name] = ele;
124
+ }
125
+ });
126
+
127
+ _this.setState({
128
+ selectFiles: selectFiles
129
+ });
110
130
 
111
- var onSubmit = restProps.onSubmit;
112
- (0, _react.useEffect)(function () {
113
- function handleMessage(event) {
114
- var origin = event.origin;
115
- console.log('origin', origin); // 腾讯授权完成通知
131
+ if (filesTotal && allFilesTotal > filesTotal) {
132
+ _toast["default"].Error("\u6700\u591A\u53EF\u4E0A\u4F20 ".concat(filesTotal, " \u4E2A\u6587\u4EF6"), {
133
+ canClose: false
134
+ });
116
135
 
117
- if (event.data.tencentAuthSuccess) {
118
- console.log('授权完成');
136
+ uploadSelectFilesObj = uploadSelectFilesObj.slice(0, filesTotal - uploadSuccessFilesLen);
119
137
  }
120
- }
121
138
 
122
- if (typeof window.addEventListener !== 'undefined') {
123
- window.addEventListener('message', handleMessage, false);
124
- } else if (typeof window.attachEvent !== 'undefined') {
125
- window.attachEvent('onmessage', handleMessage);
126
- }
139
+ if (fileNumLimit && uploadSelectFilesObj.length > fileNumLimit) {
140
+ _toast["default"].Error("\u5355\u6B21\u6700\u591A\u53EF\u4E0A\u4F20 ".concat(fileNumLimit, " \u4E2A\u6587\u4EF6"), {
141
+ canClose: false
142
+ });
127
143
 
128
- return function () {
129
- if (typeof window.removeEventListener !== 'undefined') {
130
- window.removeEventListener('message', handleMessage);
131
- } else if (typeof window.detachEvent !== 'undefined') {
132
- window.detachEvent('onmessage', handleMessage);
144
+ uploadSelectFilesObj = uploadSelectFilesObj.slice(0, fileNumLimit);
133
145
  }
146
+
147
+ if (!uploadSelectFilesObj.length) return;
148
+ var uploadSelectFilesSize = uploadSelectFilesObj.map(function (item) {
149
+ return item.size;
150
+ }).reduce(function (total, num) {
151
+ return total + num;
152
+ }); // 上传文件的大小
153
+
154
+ if (uploadSelectFilesSize > fileNumLimit * fileSizeLimit * 1024 * 1024) return _toast["default"].Error("\u5355\u6B21\u6700\u591A\u53EF\u4E0A\u4F20 ".concat(fileNumLimit, " \u4E2A\u6587\u4EF6\uFF0C\u6BCF\u4E2A\u4E0D\u8D85\u8FC7 ").concat(fileSizeLimit, "M")); // 文件大小超出限制
155
+
156
+ var uploadStartFiles = []; // 开始上传的文件
157
+
158
+ uploadSelectFilesObj.forEach(function (element, index) {
159
+ var formData = new FormData(); // FormData 对象
160
+
161
+ var uploadStartFile = null;
162
+ var timestamp = new Date().getTime(); // 给每个文件加一个时间戳
163
+
164
+ var uploadFileType = element.name.substring(element.name.lastIndexOf('.') + 1);
165
+ uploadStartFile = {
166
+ FileName: element.name,
167
+ FileType: (0, _type._dealAttachmentType)(uploadFileType).FileType,
168
+ FileSize: element.size,
169
+ FileLastModified: element.lastModified,
170
+ IsImage: (0, _type._dealAttachmentType)(uploadFileType).IsImage,
171
+ percentComplete: 0,
172
+ uploadStatus: 1,
173
+ // 开始上传
174
+ IsSuccess: false,
175
+ uid: (0, _uuid["default"])(),
176
+ _smallImageUrl: '',
177
+ _bigImageUrl: '',
178
+ MediaType: '',
179
+ UserId: 0,
180
+ MaxDocCount: 0,
181
+ DfsPath: '',
182
+ ClientUrl: '',
183
+ SmallImageUrl: '',
184
+ BigImageUrl: '',
185
+ DownloadUrl: '',
186
+ Msg: '',
187
+ AllowUploadAttachmentSize: 50,
188
+ Deleteable: true,
189
+ requestXHR: new XMLHttpRequest() // 在这创建是为了取消用
190
+
191
+ };
192
+ var sameFile = uploadSuccessFiles.find(function (file) {
193
+ return _this.isSameFile(file, uploadStartFile) && file.uploadStatus !== 4;
194
+ });
195
+
196
+ if (sameFile) {
197
+ return;
198
+ }
199
+
200
+ uploadStartFiles.push(uploadStartFile);
201
+
202
+ _this._dealUploadStart(uploadStartFiles); // 处理开始上传的文件
203
+
204
+
205
+ formData.append('file', element);
206
+ var url = action || (0, _requestV.getApiUrl)("Upload/PostFiles?format=json&timestamp=".concat(timestamp));
207
+
208
+ _this._dealUploadXHRRequest(formData, url, uploadStartFile);
209
+ });
134
210
  };
135
- }, []);
136
-
137
- var _useState9 = (0, _react.useState)(false),
138
- _useState10 = _slicedToArray(_useState9, 2),
139
- dialogUploadTypeVidible = _useState10[0],
140
- setDialogUploadTypeVidible = _useState10[1];
141
-
142
- var onShowDialogUploadType = (0, _react.useCallback)(function () {
143
- setDialogUploadTypeVidible(true);
144
- }, []);
145
- var onHideDialogUploadType = (0, _react.useCallback)(function () {
146
- setDialogUploadTypeVidible(false);
147
- }, []);
148
-
149
- var _useState11 = (0, _react.useState)(false),
150
- _useState12 = _slicedToArray(_useState11, 2),
151
- dialogQQDocsVidible = _useState12[0],
152
- setDialogQQDocsVidible = _useState12[1];
153
-
154
- var onShowDialogQQDocs = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
155
- var data;
156
- return regeneratorRuntime.wrap(function _callee$(_context) {
157
- while (1) {
158
- switch (_context.prev = _context.next) {
159
- case 0:
160
- _context.next = 2;
161
- return (0, _utils.checkTencentAuth)({});
162
-
163
- case 2:
164
- data = _context.sent;
165
-
166
- if (data) {
167
- _context.next = 5;
168
- break;
211
+
212
+ _this._dealUploadXHRRequest = function (formData, url, uploadStartFile) {
213
+ if (uploadStartFile.FileSize > _this.props.fileSizeLimit * 1024 * 1024) {
214
+ setTimeout(function () {
215
+ _this._dealUploadSuccess(_objectSpread(_objectSpread({}, uploadStartFile), {
216
+ Msg: '上传失败,文件过大',
217
+ IsImage: false,
218
+ uploadStatus: 5
219
+ }));
220
+ }, 300);
221
+ return;
222
+ }
223
+
224
+ var xhr = uploadStartFile.requestXHR; // xhr.onreadystatechange = () => {
225
+ // if (xhr.readyState == 4 && xhr.status == 200) {
226
+ // const result = { ...JSON.parse(xhr.responseText).Result[0] }; // 上传成功接口返回数据
227
+ // result.percentComplete = 100;
228
+ // result.IsSuccess = !!result.IsSuccess;
229
+ // result.uploadStatus = result.IsSuccess ? 3 : 4; // 3上传成功;4上传失败
230
+ // this._dealUploadSuccess({ ...uploadStartFile, ...result });
231
+ // }
232
+ // };
233
+ // // 进度条部分
234
+ // xhr.upload.onprogress = (evt) => {
235
+ // const uploadSuccessFiles = [...this.state.uploadSuccessFiles];
236
+ // if (evt.lengthComputable) {
237
+ // uploadSuccessFiles.forEach((item: UploadResultObj) => {
238
+ // if (this.isSameFile(item, uploadStartFile)) {
239
+ // item.uploadStatus = 2; // 上传中
240
+ // item.percentComplete = Math.round((evt.loaded * 100) / evt.total);
241
+ // }
242
+ // });
243
+ // this.setState({ uploadSuccessFiles });
244
+ // }
245
+ // };
246
+
247
+ xhr.onreadystatechange = function () {
248
+ if (xhr.readyState == 4 && xhr.status == 200) {
249
+ var result = Object.assign({}, _objectSpread({}, JSON.parse(xhr.responseText).Result[0])); // 上传成功接口返回数据
250
+
251
+ result.percentComplete = 100;
252
+ result.IsSuccess = !!result.IsSuccess;
253
+ result.uploadStatus = result.IsSuccess ? 3 : 4; // 3上传成功;4上传失败
254
+
255
+ _this._dealUploadSuccess(_objectSpread(_objectSpread({}, uploadStartFile), result));
256
+ }
257
+ }; //进度条部分
258
+
259
+
260
+ xhr.upload.onprogress = function (evt) {
261
+ var uploadSuccessFiles = JSON.parse(JSON.stringify(_this.state.uploadSuccessFiles));
262
+
263
+ if (evt.lengthComputable) {
264
+ uploadSuccessFiles.forEach(function (item) {
265
+ if (_this.isSameFile(item, uploadStartFile)) {
266
+ item.uploadStatus = 2; // 上传中
267
+
268
+ item.percentComplete = Math.round(evt.loaded * 100 / evt.total);
169
269
  }
270
+ });
271
+
272
+ _this.setState({
273
+ uploadSuccessFiles: uploadSuccessFiles
274
+ });
275
+ }
276
+ };
277
+
278
+ xhr.upload.onerror = function (evt) {
279
+ var uploadSuccessFiles = _toConsumableArray(_this.state.uploadSuccessFiles);
280
+
281
+ uploadSuccessFiles.forEach(function (item) {
282
+ if (_this.isSameFile(item, uploadStartFile)) {
283
+ item.uploadStatus = 4; // 上传失败
170
284
 
171
- return _context.abrupt("return");
285
+ item.percentComplete = Math.round(evt.loaded * 100 / evt.total);
286
+ item.Msg = '网络异常,请重新上传';
287
+ }
288
+ });
172
289
 
173
- case 5:
174
- // 设置默认的文档数据,避免在弹窗内部再查询一次
175
- setDefaultQQDocsData(data);
176
- setDialogUploadTypeVidible(false);
177
- setDialogQQDocsVidible(true);
290
+ _this.setState({
291
+ uploadSuccessFiles: uploadSuccessFiles
292
+ });
293
+ };
178
294
 
179
- case 8:
180
- case "end":
181
- return _context.stop();
295
+ xhr.open('POST', url, true);
296
+ xhr.send(formData); // 开始上传,发送form数据
297
+ };
298
+
299
+ _this._dealUploadStart = function (uploadStartFiles) {
300
+ var uploadSuccessFiles = [];
301
+
302
+ var uploadedFiles = _toConsumableArray(_this.state.uploadSuccessFiles); // 处理重传文件,直接展开会导致同样的文件展示两个
303
+
304
+
305
+ var uploadFilesConcatArr = uploadedFiles;
306
+ var isReloadFile = uploadFilesConcatArr.filter(function (item) {
307
+ return _this.isSameFile(item, uploadStartFiles[0]);
308
+ });
309
+
310
+ if (!isReloadFile || isReloadFile.length === 0) {
311
+ uploadFilesConcatArr = [].concat(_toConsumableArray(uploadedFiles), _toConsumableArray(uploadStartFiles));
312
+ }
313
+
314
+ uploadFilesConcatArr.forEach(function (item) {
315
+ var res = uploadSuccessFiles.filter(function (v) {
316
+ return _this.isSameFile(item, v);
317
+ });
318
+ uploadSuccessFiles.forEach(function (element) {
319
+ if (_this.isSameFile(item, element)) {
320
+ element = item;
321
+ }
322
+ });
323
+
324
+ if (res.length === 0) {
325
+ uploadSuccessFiles.push(item);
182
326
  }
327
+ });
328
+
329
+ _this.setState({
330
+ uploadSuccessFiles: uploadSuccessFiles
331
+ });
332
+ };
333
+
334
+ _this._dealUploadSuccess = function (uploadSuccessFile) {
335
+ var onSubmit = _this.props.onSubmit;
336
+
337
+ var uploadSuccessFiles = _toConsumableArray(_this.state.uploadSuccessFiles);
338
+
339
+ var uploadSuccessFilesFormat = uploadSuccessFiles.map(function (element) {
340
+ return _this.isSameFile(uploadSuccessFile, element) ? uploadSuccessFile : element;
341
+ });
342
+ var uploadSuccessFilesPath = uploadSuccessFilesFormat.map(function (item) {
343
+ return item.DfsPath;
344
+ }); // 获取文件上传后返回的路径
345
+
346
+ onSubmit(uploadSuccessFilesPath); // 将上传完成的文件路径传递给父组件
347
+
348
+ _this.setState({
349
+ uploadSuccessFiles: uploadSuccessFilesFormat,
350
+ attachmentPreviewUrl: (0, _util.getPreviewImgs)(uploadSuccessFilesFormat)
351
+ });
352
+ };
353
+
354
+ _this.isImg = function (fileType) {
355
+ if (/^(jpg|png|gif|jpeg|image|JPG|PNG|GIF|JPEG)$/.test(fileType)) {
356
+ return true;
183
357
  }
184
- }, _callee);
185
- })), []);
186
- var onHideDialogQQDocs = (0, _react.useCallback)(function () {
187
- setDialogQQDocsVidible(false);
188
- }, []);
189
-
190
- if (onlyLocal) {
191
- return /*#__PURE__*/_react["default"].createElement(_upload["default"], restProps, children);
192
- }
193
358
 
194
- (0, _react.useEffect)(function () {
195
- var filePaths = allFileData.map(function (_ref3) {
196
- var type = _ref3.type,
197
- fileData = _ref3.fileData;
198
-
199
- if (type === 'qq') {
200
- // 需要返回 url|type|title|tencentdoc 格式的字符串数组
201
- var url = fileData.url,
202
- _type = fileData.type,
203
- title = fileData.title;
204
- return "".concat(url, "|").concat(_type, "|").concat(title, "|tencentdoc");
359
+ return false;
360
+ };
361
+
362
+ _this.getImgIndex = function (index) {
363
+ var newIndex = 0;
364
+ var uploadSuccessFiles = _this.state.uploadSuccessFiles;
365
+
366
+ for (var i = 0; i < index; i++) {
367
+ if (_this.isImg(uploadSuccessFiles[i].FileType)) {
368
+ newIndex++;
369
+ }
205
370
  }
206
371
 
207
- if (type === 'local') {
208
- return fileData.DfsPath;
372
+ return newIndex;
373
+ };
374
+
375
+ _this.handlerUploadPreviewOptions = function (index, options) {
376
+ var _this$props2 = _this.props,
377
+ onSubmit = _this$props2.onSubmit,
378
+ onDelete = _this$props2.onDelete;
379
+
380
+ if (options === 'cancel') {
381
+ var reUploadFileInfo = _this.state.uploadSuccessFiles[index];
382
+ reUploadFileInfo.requestXHR.abort();
209
383
  }
210
384
 
211
- return '';
212
- });
213
- if (onSubmit) onSubmit(filePaths);
214
- }, [allFileData]);
215
- (0, _react.useEffect)(function () {
216
- console.log('allFileData', _toConsumableArray(allFileData));
217
- console.log('localFileData', _toConsumableArray(localFileData)); // upload 组件返回的是选择的所有文件对象,需要对其进行重新排序
218
-
219
- var localFileListKeys = allFileData.filter(function (_ref4) {
220
- var type = _ref4.type;
221
- return type === 'local';
222
- }).map(function (_ref5) {
223
- var key = _ref5.key;
224
- return key;
225
- }); // 递归查找第一个不存在的 key
226
-
227
- var sliceStartIndex = localFileData.findIndex(function (item) {
228
- return !localFileListKeys.includes(item.uid);
229
- }); // 然后从该位置开始截取并追加到 allFileData
230
-
231
- var newLocalFile = sliceStartIndex === -1 ? [] : localFileData.slice(sliceStartIndex);
232
- console.log('sliceStartIndex', sliceStartIndex);
233
- console.log('newLocalFile', newLocalFile); // 追加
234
- // 由于 upload 内部使用了 setTimeout,导致 onLocalUploadSuccessHandler 没有被更新,allFileData 取到的是旧的
235
-
236
- setAllFileData([].concat(_toConsumableArray(allFileData), _toConsumableArray(newLocalFile.map(function (item) {
237
- return {
238
- key: item.uid,
239
- type: 'local',
240
- fileData: item
241
- };
242
- }))));
243
- }, [localFileData]);
244
- var onSelectQQDocsFileHandler = (0, _react.useCallback)(function (checkedDocsList) {
245
- setQQFileData([].concat(_toConsumableArray(qqFileData), _toConsumableArray(checkedDocsList))); // qq 文档只会返回每次新增的文档数组,所以直接在后面追加即可
246
-
247
- setAllFileData([].concat(_toConsumableArray(allFileData), _toConsumableArray(checkedDocsList.map(function (item) {
248
- return {
249
- key: item.id,
250
- type: 'qq',
251
- fileData: item
252
- };
253
- }))));
254
- onHideDialogQQDocs();
255
- }, [qqFileData, allFileData]);
256
- var onLocalUploadSuccessHandler = (0, _react.useCallback)(function (localFileList) {
257
- setLocalFileData(localFileList);
258
- }, []);
259
- var onClickFileHandler = (0, _react.useCallback)(function (index, options) {
260
- var currentFile = allFileData[index];
261
-
262
- if (options === 'delete' || options === 'cancel') {
263
- if (currentFile.type === 'qq') {
264
- var removeIndex = qqFileData.findIndex(function (item) {
265
- return item.id === currentFile.key;
385
+ if (options === 'delete' || options === 'cancel') {
386
+ var uploadResultFiles = _toConsumableArray(_this.state.uploadSuccessFiles);
387
+
388
+ var deleteFiles = uploadResultFiles[index];
389
+ onDelete && onDelete(deleteFiles.documentId ? deleteFiles.documentId : deleteFiles.DfsPath);
390
+ uploadResultFiles.splice(index, 1);
391
+
392
+ var _uploadSuccessFilesPath = uploadResultFiles.map(function (item) {
393
+ return item.DfsPath;
266
394
  });
267
- qqFileData.splice(removeIndex, 1);
268
- setQQFileData(_toConsumableArray(qqFileData));
269
- } else {
270
- var _removeIndex = localFileData.findIndex(function (item) {
271
- return item.uid === currentFile.key;
395
+
396
+ onSubmit(_uploadSuccessFilesPath, options);
397
+
398
+ _this.setState({
399
+ uploadSuccessFiles: uploadResultFiles
272
400
  });
401
+ } else if (options === 'preview') {
402
+ var imgIndex = _this.getImgIndex(index);
273
403
 
274
- localFileData.splice(_removeIndex, 1);
275
- setLocalFileData(_toConsumableArray(localFileData));
404
+ _this.refs.imgViewerRef.show(imgIndex);
405
+ } else if (options === 'reupload') {
406
+ var _reUploadFileInfo = _this.state.uploadSuccessFiles[index];
407
+ var reUploadFile = _this.state.selectFiles[_reUploadFileInfo.FileName];
408
+
409
+ _this.dealSelectFiles([reUploadFile]);
276
410
  }
411
+ };
277
412
 
278
- allFileData.splice(index, 1);
279
- setAllFileData(_toConsumableArray(allFileData));
280
- } else if (options === 'preview') {
281
- if (currentFile.type === 'qq') {
282
- var file = qqFileData[index];
283
- (0, _tools.openUrl)(file.url);
413
+ _this.isSameFile = function (item, element) {
414
+ return item.FileName === element.FileName && item.FileSize === element.FileSize && item.FileLastModified === element.FileLastModified;
415
+ };
416
+
417
+ _this.renderUploadList = function (list) {
418
+ var attachmentPreviewBox = _this.props.attachmentPreviewBox;
419
+ var attachmentPreviewUrl = _this.state.attachmentPreviewUrl;
420
+ if (!list.length) return;
421
+ return /*#__PURE__*/_react["default"].createElement(_Portals["default"], {
422
+ domNode: attachmentPreviewBox,
423
+ className: "uploadFile__preview__list"
424
+ }, /*#__PURE__*/_react["default"].createElement(_imgViewer["default"], {
425
+ data: attachmentPreviewUrl,
426
+ ref: "imgViewerRef",
427
+ showDownload: false
428
+ }), list.map(function (item, index) {
429
+ return /*#__PURE__*/_react["default"].createElement(_uploadedPreview["default"], {
430
+ uploadResultItem: item,
431
+ index: index,
432
+ key: item.uid,
433
+ className: "uploaded__preview",
434
+ onSubmit: function onSubmit(index, options) {
435
+ _this.handlerUploadPreviewOptions(index, options);
436
+ }
437
+ });
438
+ }));
439
+ };
440
+
441
+ _this.handleButtonClick = function (e) {
442
+ e.nativeEvent.stopImmediatePropagation();
443
+
444
+ if (_this.refs.fileInput) {
445
+ // @ts-ignore
446
+ _this.refs.fileInput.click();
284
447
  }
285
- }
286
- }, [allFileData, qqFileData, localFileData]);
287
-
288
- function renderUploadList(list) {
289
- var attachmentPreviewBox = restProps.attachmentPreviewBox;
290
- if (!list.length) return '';
291
- return /*#__PURE__*/_react["default"].createElement(_Portals["default"], {
292
- domNode: attachmentPreviewBox,
293
- className: "uploadFile__preview__list"
294
- }, list.map(function (item, index) {
295
- return /*#__PURE__*/_react["default"].createElement(_uploadedPreview["default"], {
296
- uploadResultItem: item.type === 'qq' ? {
297
- FileName: item.fileData.title,
298
- FileType: item.fileData.type,
299
- ClientUrl: item.fileData.url,
300
- uid: item.fileData.id,
301
- uploadStatus: 3,
302
- Deleteable: true,
303
- SmallImageUrl: item.fileData.url
304
- } : item.fileData,
305
- index: index,
306
- key: item.key,
307
- className: "uploaded__preview",
308
- onSubmit: onClickFileHandler
309
- });
310
- }));
448
+ };
449
+
450
+ _this.state = {
451
+ uploadSuccessFiles: props.attachments || [],
452
+ attachmentPreviewUrl: props.attachments ? (0, _util.getPreviewImgs)(props.attachments) : [],
453
+ selectFiles: {}
454
+ };
455
+ return _this;
311
456
  }
312
457
 
313
- var uploadProps = (0, _react.useMemo)(function () {
314
- return _objectSpread(_objectSpread({}, restProps), {}, {
315
- filesTotal: undefined,
316
- // 禁止
317
- onSubmit: onDefaultSubmit,
318
- onUploadSuccess: onLocalUploadSuccessHandler
319
- });
320
- }, [restProps, onLocalUploadSuccessHandler]);
321
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_dialogUploadType["default"], {
322
- uploadProps: uploadProps,
323
- onSelectQQDocs: onShowDialogQQDocs,
324
- visible: dialogUploadTypeVidible,
325
- onClose: onHideDialogUploadType
326
- }), /*#__PURE__*/_react["default"].createElement(_dialogQqDocs["default"], {
327
- fileNumLimit: uploadProps.fileNumLimit,
328
- defaultQQDocsData: defaultQQDocsData,
329
- visible: dialogQQDocsVidible,
330
- onClose: onHideDialogQQDocs,
331
- onSubmit: onSelectQQDocsFileHandler
332
- }), /*#__PURE__*/_react["default"].createElement(_titaUi.Tooltip, {
333
- container: document.body,
334
- content: /*#__PURE__*/_react["default"].createElement("p", {
335
- dangerouslySetInnerHTML: {
336
- __html: attachmentTipText
458
+ _createClass(Upload, [{
459
+ key: "componentDidMount",
460
+ value: function componentDidMount() {
461
+ var attachments = this.props.attachments;
462
+ this.setState({
463
+ uploadSuccessFiles: attachments || [],
464
+ attachmentPreviewUrl: attachments ? (0, _util.getPreviewImgs)(attachments) : []
465
+ });
466
+ }
467
+ }, {
468
+ key: "componentWillReceiveProps",
469
+ value: function componentWillReceiveProps(nextProps) {
470
+ if (this.props.submitStatus === 2 && nextProps.submitStatus == 1) {
471
+ this.setState({
472
+ uploadSuccessFiles: [],
473
+ attachmentPreviewUrl: []
474
+ });
475
+ } else {
476
+ this.setState({
477
+ // uploadSuccessFiles: nextProps.attachments || [],
478
+ attachmentPreviewUrl: nextProps.attachments ? (0, _util.getPreviewImgs)(nextProps.attachments) : []
479
+ });
480
+ }
481
+
482
+ if (nextProps.dragFilesList && nextProps.dragFilesList.length) {
483
+ this.dealSelectFiles(nextProps.dragFilesList);
337
484
  }
338
- })
339
- }, /*#__PURE__*/_react["default"].createElement("div", {
340
- onClick: onShowDialogUploadType
341
- }, children)), renderUploadList(allFileData));
485
+ }
486
+ }, {
487
+ key: "render",
488
+ value: function render() {
489
+ var _this2 = this;
490
+
491
+ var _this$props3 = this.props,
492
+ children = _this$props3.children,
493
+ className = _this$props3.className,
494
+ style = _this$props3.style,
495
+ _this$props3$attachme = _this$props3.attachmentTipText,
496
+ attachmentTipText = _this$props3$attachme === void 0 ? (0, _getLocale.getLocale)('OKR_MyO_KRP_Draganddropu') : _this$props3$attachme;
497
+ var uploadSuccessFiles = this.state.uploadSuccessFiles;
498
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_titaUi.Tooltip, {
499
+ container: document.body,
500
+ content: /*#__PURE__*/_react["default"].createElement("p", {
501
+ dangerouslySetInnerHTML: {
502
+ __html: attachmentTipText
503
+ }
504
+ })
505
+ }, /*#__PURE__*/_react["default"].createElement(_style.UploadFormContainer, {
506
+ className: className,
507
+ style: style,
508
+ onMouseUp: function onMouseUp(e) {
509
+ return _this2.handleButtonClick(e);
510
+ }
511
+ }, /*#__PURE__*/_react["default"].createElement("div", {
512
+ ref: "uploader-trigger",
513
+ style: {
514
+ cursor: 'pointer'
515
+ }
516
+ }, children), /*#__PURE__*/_react["default"].createElement("input", {
517
+ type: "file",
518
+ ref: "fileInput",
519
+ className: "upload_file_input",
520
+ multiple: this.props.multiple,
521
+ style: {
522
+ display: 'none'
523
+ },
524
+ onChange: this.onFileInputChange
525
+ }))), this.renderUploadList(uploadSuccessFiles));
526
+ }
527
+ }]);
528
+
529
+ return Upload;
530
+ }(_react.PureComponent);
531
+
532
+ Upload.Preview = _uploadedPreview["default"];
533
+ Upload.defaultProps = {
534
+ fileNumLimit: 20,
535
+ fileSizeLimit: 50,
536
+ filesTotal: 50,
537
+ multiple: true,
538
+ attachmentPreviewBox: 'MBlog__attachmentViewBox'
342
539
  };
343
-
344
- var _default = UploadMode;
540
+ var _default = Upload;
345
541
  exports["default"] = _default;