@myun/gimi-chat 0.9.22 → 0.9.24
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.
- package/dist/apis/useApi.js +1 -1
- package/dist/components/ai-chat-dialogue/index copy.d.ts +16 -0
- package/dist/components/ai-chat-dialogue/index copy.js +1062 -0
- package/dist/components/ai-chat-dialogue/index.js +54 -49
- package/dist/components/ai-chat-dialogue/index.module copy.css +230 -0
- package/dist/components/ai-chat-dialogue/index.module.css +78 -136
- package/dist/components/chat-input/index.d.ts +5 -0
- package/dist/components/chat-input/index.js +181 -68
- package/dist/components/chat-input/index.module.css +70 -2
- package/dist/components/file-upload/index.js +120 -34
- package/dist/components/iconfont-com/index.js +1 -1
- package/dist/components/message-list/index.js +3 -2
- package/dist/components/templates/CommonChat.js +27 -5
- package/dist/components/templates/GimiChatComponent.js +4 -0
- package/dist/components/upload-list/CustomFile.d.ts +15 -0
- package/dist/components/upload-list/CustomFile.js +105 -0
- package/dist/components/upload-list/ImageFile.d.ts +18 -0
- package/dist/components/upload-list/ImageFile.js +68 -0
- package/dist/components/upload-list/customFile.module.css +122 -0
- package/dist/components/upload-list/imageFile.module.css +95 -0
- package/dist/components/upload-list/index.d.ts +4 -3
- package/dist/components/upload-list/index.js +101 -84
- package/dist/components/upload-list/index.module.css +68 -99
- package/dist/components/voice-bars/index.js +10 -9
- package/dist/components/voice-check-dialog/index.js +2 -1
- package/dist/components/voice-recording/index.d.ts +1 -1
- package/dist/components/voice-recording/index.js +2 -28
- package/dist/hooks/useChatMessage.d.ts +1 -1
- package/dist/hooks/useChatMessage.js +1 -1
- package/dist/hooks/useCommonChatAPI.js +13 -9
- package/dist/hooks/useFile.js +99 -7
- package/dist/i18n/locales/en-US.d.ts +9 -0
- package/dist/i18n/locales/en-US.js +11 -2
- package/dist/i18n/locales/zh-CN.d.ts +9 -0
- package/dist/i18n/locales/zh-CN.js +11 -2
- package/dist/types/chat.d.ts +3 -0
- package/dist/types/file.d.ts +9 -0
- package/dist/umd/index.min.js +1 -1
- package/dist/utils/tools.d.ts +1 -0
- package/dist/utils/tools.js +25 -1
- package/package.json +1 -1
|
@@ -2,6 +2,12 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
2
2
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
3
|
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); } }
|
|
4
4
|
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); }); }; }
|
|
5
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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); }
|
|
8
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
+
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; }
|
|
5
11
|
import React from 'react';
|
|
6
12
|
import { useTranslation } from 'react-i18next';
|
|
7
13
|
import { Upload, Toast, Button } from '@douyinfe/semi-ui';
|
|
@@ -10,8 +16,14 @@ import { useAppDispatch, useAppSelector } from "../../store/hooks";
|
|
|
10
16
|
import { setFileList } from "../../store/slices/gimiMenuSlice";
|
|
11
17
|
import { FileStatus } from "../../interfaces/fileInterface";
|
|
12
18
|
import { useGimiFileUpload } from "../../hooks/useFile";
|
|
13
|
-
var DEFAULT_ACCEPT = '.xlsx,.txt';
|
|
19
|
+
var DEFAULT_ACCEPT = '.xlsx,.txt,.png,.jpg,.jpeg,.gif,.webp';
|
|
14
20
|
var MAX_RETRY_COUNT = 3;
|
|
21
|
+
var IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif', 'image/webp'];
|
|
22
|
+
var MAX_IMAGE_COUNT = 10;
|
|
23
|
+
var MAX_FILE_COUNT = 1;
|
|
24
|
+
var MAX_TOTAL_COUNT = 10;
|
|
25
|
+
var MAX_IMAGE_SIZE = 20; // MB
|
|
26
|
+
|
|
15
27
|
/** Redux FileItem → Semi Upload FileItem */
|
|
16
28
|
var transformFileItem = function transformFileItem(list) {
|
|
17
29
|
return list.map(function (item) {
|
|
@@ -23,13 +35,16 @@ var transformFileItem = function transformFileItem(list) {
|
|
|
23
35
|
};
|
|
24
36
|
});
|
|
25
37
|
};
|
|
38
|
+
|
|
39
|
+
/** 判断是否为图片 */
|
|
40
|
+
var isImageFile = function isImageFile(file) {
|
|
41
|
+
return IMAGE_TYPES.includes(file.type);
|
|
42
|
+
};
|
|
26
43
|
var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
27
44
|
var _useTranslation = useTranslation(),
|
|
28
45
|
t = _useTranslation.t;
|
|
29
46
|
var _props$maxSize = props.maxSize,
|
|
30
47
|
maxSize = _props$maxSize === void 0 ? 10 : _props$maxSize,
|
|
31
|
-
_props$limit = props.limit,
|
|
32
|
-
limit = _props$limit === void 0 ? 1 : _props$limit,
|
|
33
48
|
accept = props.accept,
|
|
34
49
|
disabled = props.disabled,
|
|
35
50
|
children = props.children;
|
|
@@ -54,11 +69,71 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
54
69
|
/** 重试次数:uid -> count */
|
|
55
70
|
var retryCountMapRef = React.useRef(new Map());
|
|
56
71
|
|
|
57
|
-
/**
|
|
72
|
+
/** 验证文件数量和大小限制 */
|
|
73
|
+
var validateFileCount = function validateFileCount(newFile) {
|
|
74
|
+
var currentList = fileList || [];
|
|
75
|
+
var imageCount = currentList.filter(function (f) {
|
|
76
|
+
return f.isImage;
|
|
77
|
+
}).length;
|
|
78
|
+
var fileCount = currentList.filter(function (f) {
|
|
79
|
+
return !f.isImage;
|
|
80
|
+
}).length;
|
|
81
|
+
var totalCount = currentList.length;
|
|
82
|
+
var isImage = isImageFile(newFile);
|
|
83
|
+
|
|
84
|
+
// 图片大小检查:单个图片不超过20MB
|
|
85
|
+
if (isImage && newFile.size > MAX_IMAGE_SIZE * 1024 * 1024) {
|
|
86
|
+
Toast.warning(t('upload.imageSizeExceeded', {
|
|
87
|
+
size: MAX_IMAGE_SIZE
|
|
88
|
+
}));
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 总数不能超过10个
|
|
93
|
+
if (totalCount >= MAX_TOTAL_COUNT) {
|
|
94
|
+
Toast.warning(t('upload.maxTotalCount', {
|
|
95
|
+
count: MAX_TOTAL_COUNT
|
|
96
|
+
}));
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 图片最多10个
|
|
101
|
+
if (isImage && imageCount >= MAX_IMAGE_COUNT) {
|
|
102
|
+
Toast.warning(t('upload.maxImageCount', {
|
|
103
|
+
count: MAX_IMAGE_COUNT
|
|
104
|
+
}));
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 非图片文件最多1个
|
|
109
|
+
if (!isImage && fileCount >= MAX_FILE_COUNT) {
|
|
110
|
+
Toast.warning(t('upload.maxFileCount', {
|
|
111
|
+
count: MAX_FILE_COUNT
|
|
112
|
+
}));
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** 更新 Redux 中的文件状态 */
|
|
58
119
|
var updateFile = function updateFile(file) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
120
|
+
var currentList = fileList || [];
|
|
121
|
+
var existingIndex = currentList.findIndex(function (f) {
|
|
122
|
+
return f.uid === file.uid;
|
|
123
|
+
});
|
|
124
|
+
if (existingIndex >= 0) {
|
|
125
|
+
// 更新现有文件
|
|
126
|
+
var newList = _toConsumableArray(currentList);
|
|
127
|
+
newList[existingIndex] = file;
|
|
128
|
+
dispatch(setFileList({
|
|
129
|
+
fileList: newList
|
|
130
|
+
}));
|
|
131
|
+
} else {
|
|
132
|
+
// 添加新文件
|
|
133
|
+
dispatch(setFileList({
|
|
134
|
+
fileList: [].concat(_toConsumableArray(currentList), [file])
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
62
137
|
};
|
|
63
138
|
|
|
64
139
|
/** 失败后重新上传 */
|
|
@@ -78,7 +153,7 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
78
153
|
};
|
|
79
154
|
var customRequest = /*#__PURE__*/function () {
|
|
80
155
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
81
|
-
var file, onSuccess, onError, rawFile, controller, formData, _response$result, fullResponse, response, result, successFile, _retryCountMapRef$cur, currentRetry, retryWhenOnline;
|
|
156
|
+
var file, onSuccess, onError, rawFile, controller, isImage, formData, _response$result, fullResponse, response, result, successFile, _retryCountMapRef$cur, currentRetry, retryWhenOnline;
|
|
82
157
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
83
158
|
while (1) switch (_context.prev = _context.next) {
|
|
84
159
|
case 0:
|
|
@@ -91,6 +166,12 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
91
166
|
Toast.error(t('upload.readFailed'));
|
|
92
167
|
return _context.abrupt("return");
|
|
93
168
|
case 5:
|
|
169
|
+
if (validateFileCount(rawFile)) {
|
|
170
|
+
_context.next = 7;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return _context.abrupt("return");
|
|
174
|
+
case 7:
|
|
94
175
|
// 缓存原始 File
|
|
95
176
|
rawFileMapRef.current.set(file.uid, rawFile);
|
|
96
177
|
|
|
@@ -100,16 +181,18 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
100
181
|
}
|
|
101
182
|
controller = new AbortController();
|
|
102
183
|
fileUploadAbortRef.current = controller;
|
|
184
|
+
isImage = isImageFile(rawFile);
|
|
103
185
|
updateFile({
|
|
104
186
|
uid: file.uid,
|
|
105
187
|
name: file.name,
|
|
106
188
|
size: file.size,
|
|
107
|
-
status: FileStatus.UPLOADING
|
|
189
|
+
status: FileStatus.UPLOADING,
|
|
190
|
+
isImage: isImage
|
|
108
191
|
});
|
|
109
192
|
formData = new FormData();
|
|
110
193
|
formData.append('file', rawFile);
|
|
111
|
-
_context.prev =
|
|
112
|
-
_context.next =
|
|
194
|
+
_context.prev = 15;
|
|
195
|
+
_context.next = 18;
|
|
113
196
|
return fetch(uploadUrl, {
|
|
114
197
|
method: 'POST',
|
|
115
198
|
headers: {
|
|
@@ -120,11 +203,11 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
120
203
|
}).then(function (res) {
|
|
121
204
|
return res.json();
|
|
122
205
|
});
|
|
123
|
-
case
|
|
206
|
+
case 18:
|
|
124
207
|
fullResponse = _context.sent;
|
|
125
208
|
response = fullResponse[0];
|
|
126
209
|
if (!((response === null || response === void 0 ? void 0 : response.status) === 0 && response !== null && response !== void 0 && (_response$result = response.result) !== null && _response$result !== void 0 && _response$result.fileToken)) {
|
|
127
|
-
_context.next =
|
|
210
|
+
_context.next = 29;
|
|
128
211
|
break;
|
|
129
212
|
}
|
|
130
213
|
result = response.result;
|
|
@@ -137,7 +220,8 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
137
220
|
fileName: result.fileName,
|
|
138
221
|
fileSize: result.fileSize,
|
|
139
222
|
fileToken: result.fileToken,
|
|
140
|
-
fileType: result.fileName.split('.').pop()
|
|
223
|
+
fileType: result.fileName.split('.').pop(),
|
|
224
|
+
isImage: isImage
|
|
141
225
|
};
|
|
142
226
|
updateFile(successFile);
|
|
143
227
|
handleSSEFileAnalyize(successFile, true);
|
|
@@ -145,26 +229,26 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
145
229
|
// 成功后清理 retry 计数
|
|
146
230
|
retryCountMapRef.current.delete(file.uid);
|
|
147
231
|
onSuccess === null || onSuccess === void 0 || onSuccess(response);
|
|
148
|
-
_context.next =
|
|
232
|
+
_context.next = 30;
|
|
149
233
|
break;
|
|
150
|
-
case
|
|
234
|
+
case 29:
|
|
151
235
|
throw new Error('upload failed');
|
|
152
|
-
case
|
|
153
|
-
_context.next =
|
|
236
|
+
case 30:
|
|
237
|
+
_context.next = 52;
|
|
154
238
|
break;
|
|
155
|
-
case
|
|
156
|
-
_context.prev =
|
|
157
|
-
_context.t0 = _context["catch"](
|
|
239
|
+
case 32:
|
|
240
|
+
_context.prev = 32;
|
|
241
|
+
_context.t0 = _context["catch"](15);
|
|
158
242
|
if (!(_context.t0.name === 'AbortError')) {
|
|
159
|
-
_context.next =
|
|
243
|
+
_context.next = 36;
|
|
160
244
|
break;
|
|
161
245
|
}
|
|
162
246
|
return _context.abrupt("return");
|
|
163
|
-
case
|
|
247
|
+
case 36:
|
|
164
248
|
currentRetry = (_retryCountMapRef$cur = retryCountMapRef.current.get(file.uid)) !== null && _retryCountMapRef$cur !== void 0 ? _retryCountMapRef$cur : 0;
|
|
165
249
|
/** 网络异常:不计入重试次数 */
|
|
166
250
|
if (navigator.onLine) {
|
|
167
|
-
_context.next =
|
|
251
|
+
_context.next = 43;
|
|
168
252
|
break;
|
|
169
253
|
}
|
|
170
254
|
Toast.error(t('upload.networkRetry'));
|
|
@@ -172,7 +256,8 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
172
256
|
uid: file.uid,
|
|
173
257
|
name: file.name,
|
|
174
258
|
size: file.size,
|
|
175
|
-
status: FileStatus.NETWORK_ERROR
|
|
259
|
+
status: FileStatus.NETWORK_ERROR,
|
|
260
|
+
isImage: isImage
|
|
176
261
|
});
|
|
177
262
|
retryWhenOnline = function retryWhenOnline() {
|
|
178
263
|
window.removeEventListener('online', retryWhenOnline);
|
|
@@ -180,9 +265,9 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
180
265
|
};
|
|
181
266
|
window.addEventListener('online', retryWhenOnline);
|
|
182
267
|
return _context.abrupt("return");
|
|
183
|
-
case
|
|
268
|
+
case 43:
|
|
184
269
|
if (!(currentRetry >= MAX_RETRY_COUNT)) {
|
|
185
|
-
_context.next =
|
|
270
|
+
_context.next = 49;
|
|
186
271
|
break;
|
|
187
272
|
}
|
|
188
273
|
Toast.error(t('upload.failedMaxRetry'));
|
|
@@ -190,12 +275,13 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
190
275
|
uid: file.uid,
|
|
191
276
|
name: file.name,
|
|
192
277
|
size: file.size,
|
|
193
|
-
status: FileStatus.UPLOAD_FAILED
|
|
278
|
+
status: FileStatus.UPLOAD_FAILED,
|
|
279
|
+
isImage: isImage
|
|
194
280
|
});
|
|
195
281
|
retryCountMapRef.current.delete(file.uid);
|
|
196
282
|
onError === null || onError === void 0 || onError(_context.t0);
|
|
197
283
|
return _context.abrupt("return");
|
|
198
|
-
case
|
|
284
|
+
case 49:
|
|
199
285
|
/** ⏱️ 未达上限,继续重试 */
|
|
200
286
|
retryCountMapRef.current.set(file.uid, currentRetry + 1);
|
|
201
287
|
Toast.warning(t('upload.retrying', {
|
|
@@ -205,11 +291,11 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
205
291
|
setTimeout(function () {
|
|
206
292
|
retryUpload(file.uid);
|
|
207
293
|
}, 1000);
|
|
208
|
-
case
|
|
294
|
+
case 52:
|
|
209
295
|
case "end":
|
|
210
296
|
return _context.stop();
|
|
211
297
|
}
|
|
212
|
-
}, _callee, null, [[
|
|
298
|
+
}, _callee, null, [[15, 32]]);
|
|
213
299
|
}));
|
|
214
300
|
return function customRequest(_x) {
|
|
215
301
|
return _ref.apply(this, arguments);
|
|
@@ -232,13 +318,13 @@ var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
232
318
|
return /*#__PURE__*/React.createElement(Upload, {
|
|
233
319
|
customRequest: customRequest,
|
|
234
320
|
action: "",
|
|
235
|
-
limit:
|
|
321
|
+
limit: MAX_TOTAL_COUNT,
|
|
236
322
|
onExceed: function onExceed() {
|
|
237
323
|
Toast.warning(t('upload.limitExceeded', {
|
|
238
|
-
limit:
|
|
324
|
+
limit: MAX_TOTAL_COUNT
|
|
239
325
|
}));
|
|
240
326
|
},
|
|
241
|
-
multiple:
|
|
327
|
+
multiple: true,
|
|
242
328
|
accept: (accept === null || accept === void 0 ? void 0 : accept.join(',')) || DEFAULT_ACCEPT,
|
|
243
329
|
maxSize: maxSize * 1024,
|
|
244
330
|
onSizeError: function onSizeError() {
|
|
@@ -12,7 +12,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
12
12
|
*/
|
|
13
13
|
import React from 'react';
|
|
14
14
|
import Icon from '@douyinfe/semi-icons';
|
|
15
|
-
var scriptUrl = '//at.alicdn.com/t/c/
|
|
15
|
+
var scriptUrl = '//at.alicdn.com/t/c/font_3429456_9nyoop1pm2t.js';
|
|
16
16
|
|
|
17
17
|
// Load iconfont script
|
|
18
18
|
if (typeof document !== 'undefined' && scriptUrl) {
|
|
@@ -25,7 +25,7 @@ import useChatActions from "../../hooks/useChatActions";
|
|
|
25
25
|
import CopyButton from "../message-actions/CopyButton";
|
|
26
26
|
import { Virtuoso } from 'react-virtuoso';
|
|
27
27
|
var MessageItem = /*#__PURE__*/React.memo(function (props) {
|
|
28
|
-
var _v$quoteTeachModelLis, _v$quoteProductList;
|
|
28
|
+
var _v$quoteTeachModelLis, _v$quoteProductList, _v$messageFilesList;
|
|
29
29
|
var v = props.v,
|
|
30
30
|
chatUI = props.chatUI,
|
|
31
31
|
hideUserMessage = props.hideUserMessage,
|
|
@@ -75,7 +75,8 @@ var MessageItem = /*#__PURE__*/React.memo(function (props) {
|
|
|
75
75
|
}, replaceBraces(v.content)), v.messageFiles && /*#__PURE__*/React.createElement("div", {
|
|
76
76
|
className: styles.listBox
|
|
77
77
|
}, /*#__PURE__*/React.createElement(UploadList, {
|
|
78
|
-
|
|
78
|
+
isMessage: true,
|
|
79
|
+
fileList: v !== null && v !== void 0 && (_v$messageFilesList = v.messageFilesList) !== null && _v$messageFilesList !== void 0 && _v$messageFilesList.length ? v.messageFilesList : Array.isArray(v.messageFiles) ? v.messageFiles : [v.messageFiles],
|
|
79
80
|
showDel: false,
|
|
80
81
|
handleDelFile: function handleDelFile() {},
|
|
81
82
|
handleReTry: handleReTry
|
|
@@ -5,10 +5,16 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
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."); }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
14
|
import React from 'react';
|
|
9
15
|
import { useStore } from 'react-redux';
|
|
10
16
|
import { useAppDispatch, useAppSelector } from "../../store/hooks";
|
|
11
|
-
import { setBaseUrl, setToken, setPlatform, setConversationId, setAgentDetail, setBusinessParams, setQuoteTeachModelList, openSidebar, closeSidebar } from "../../store/slices/gimiMenuSlice";
|
|
17
|
+
import { setBaseUrl, setToken, setPlatform, setConversationId, setAgentDetail, setBusinessParams, setQuoteTeachModelList, openSidebar, closeSidebar, setFileList as _setFileList } from "../../store/slices/gimiMenuSlice";
|
|
12
18
|
import useCommonChatAPI from "../../hooks/useCommonChatAPI";
|
|
13
19
|
import { replaceBraces } from "../../utils/tools";
|
|
14
20
|
import styles from "./index.module.css";
|
|
@@ -45,11 +51,19 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
45
51
|
conversationId = props.conversationId,
|
|
46
52
|
businessParams = props.businessParams,
|
|
47
53
|
_props$enableSearchCo = props.enableSearchCourse,
|
|
48
|
-
enableSearchCourse = _props$enableSearchCo === void 0 ? true : _props$enableSearchCo
|
|
54
|
+
enableSearchCourse = _props$enableSearchCo === void 0 ? true : _props$enableSearchCo,
|
|
55
|
+
_props$agentList = props.agentList,
|
|
56
|
+
agentList = _props$agentList === void 0 ? [] : _props$agentList,
|
|
57
|
+
_props$hiddenDeepThin = props.hiddenDeepThink,
|
|
58
|
+
hiddenDeepThink = _props$hiddenDeepThin === void 0 ? false : _props$hiddenDeepThin;
|
|
49
59
|
var store = useStore();
|
|
50
60
|
var dispatch = useAppDispatch();
|
|
51
61
|
var containerRef = React.useRef(null);
|
|
52
62
|
var chatInputRef = React.useRef(null);
|
|
63
|
+
var _React$useState = React.useState(agentId),
|
|
64
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
65
|
+
currentAgentId = _React$useState2[0],
|
|
66
|
+
setCurrentAgentId = _React$useState2[1];
|
|
53
67
|
var messageList = useAppSelector(function (state) {
|
|
54
68
|
return state.gimiMenu.messageList;
|
|
55
69
|
});
|
|
@@ -100,7 +114,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
100
114
|
platform: platform,
|
|
101
115
|
stopTTSByText: stopTTSByText,
|
|
102
116
|
isPlaying: isPlaying,
|
|
103
|
-
agentId:
|
|
117
|
+
agentId: currentAgentId,
|
|
104
118
|
reloadAgentKey: props.reloadAgentKey,
|
|
105
119
|
resetKey: props.resetKey,
|
|
106
120
|
interruptKey: props.interruptKey,
|
|
@@ -140,7 +154,12 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
140
154
|
agentDetail: agentObj,
|
|
141
155
|
conversationId: store.getState().gimiMenu.conversationId,
|
|
142
156
|
inputEditor: chatInputRef.current,
|
|
143
|
-
uploadFileList: fileList
|
|
157
|
+
uploadFileList: fileList,
|
|
158
|
+
setFileList: function setFileList(fileList) {
|
|
159
|
+
return dispatch(_setFileList({
|
|
160
|
+
fileList: fileList
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
144
163
|
};
|
|
145
164
|
});
|
|
146
165
|
React.useEffect(function () {
|
|
@@ -283,7 +302,10 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
283
302
|
disableVoiceCommunication: disableVoiceCommunication,
|
|
284
303
|
onHistoryReload: onHistoryReload,
|
|
285
304
|
platform: platform,
|
|
286
|
-
initQuoteSource: props.initQuoteSource
|
|
305
|
+
initQuoteSource: props.initQuoteSource,
|
|
306
|
+
agentList: agentList,
|
|
307
|
+
hiddenDeepThink: hiddenDeepThink,
|
|
308
|
+
onAgentChange: setCurrentAgentId
|
|
287
309
|
}, props.chatInputConfig)), showPrologue && messageList.length === 0 && !isMoreLoading && quickQuestionListPosition === 'bottom' && /*#__PURE__*/React.createElement(PresetAgentContent, {
|
|
288
310
|
prologue: '',
|
|
289
311
|
questionList: (agentObj === null || agentObj === void 0 ? void 0 : agentObj.questionList) || [],
|
|
@@ -32,6 +32,10 @@ var GimiChatComponent = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
32
32
|
get uploadFileList() {
|
|
33
33
|
var _commonChatRef$curren5;
|
|
34
34
|
return ((_commonChatRef$curren5 = commonChatRef.current) === null || _commonChatRef$curren5 === void 0 ? void 0 : _commonChatRef$curren5.uploadFileList) || [];
|
|
35
|
+
},
|
|
36
|
+
setFileList: function setFileList(fileList) {
|
|
37
|
+
var _commonChatRef$curren6;
|
|
38
|
+
(_commonChatRef$curren6 = commonChatRef.current) === null || _commonChatRef$curren6 === void 0 || _commonChatRef$curren6.setFileList(fileList);
|
|
35
39
|
}
|
|
36
40
|
};
|
|
37
41
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FileStatus } from '../../interfaces/fileInterface';
|
|
3
|
+
interface UploadFileProps {
|
|
4
|
+
file: {
|
|
5
|
+
fileType?: string;
|
|
6
|
+
fileName?: string;
|
|
7
|
+
status: FileStatus;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
handleDelFile?: () => void;
|
|
11
|
+
handleReTry?: (file: any) => void;
|
|
12
|
+
showDel?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const CustomFile: React.FC<UploadFileProps>;
|
|
15
|
+
export default CustomFile;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import styles from "./customFile.module.css";
|
|
4
|
+
import reTry from "../../assets/image/retry.png";
|
|
5
|
+
import { FileStatus } from "../../interfaces/fileInterface";
|
|
6
|
+
import { formatSizeToKB } from "../../utils/tools";
|
|
7
|
+
var CustomFile = function CustomFile(_ref) {
|
|
8
|
+
var file = _ref.file,
|
|
9
|
+
handleDelFile = _ref.handleDelFile,
|
|
10
|
+
handleReTry = _ref.handleReTry,
|
|
11
|
+
_ref$showDel = _ref.showDel,
|
|
12
|
+
showDel = _ref$showDel === void 0 ? true : _ref$showDel;
|
|
13
|
+
var _useTranslation = useTranslation(),
|
|
14
|
+
t = _useTranslation.t;
|
|
15
|
+
// 使用useMemo缓存icon,避免每次渲染重新计算
|
|
16
|
+
var _React$useMemo = React.useMemo(function () {
|
|
17
|
+
var _file$fileName, _file$name;
|
|
18
|
+
if (!file) return {};
|
|
19
|
+
var fileType = file.fileName ? ((_file$fileName = file.fileName) === null || _file$fileName === void 0 ? void 0 : _file$fileName.split('.').pop()) || '' : ((_file$name = file.name) === null || _file$name === void 0 ? void 0 : _file$name.split('.').pop()) || '';
|
|
20
|
+
var fileName = file.fileName ? file.fileName : file.name;
|
|
21
|
+
var fileSize = formatSizeToKB(file.fileSize || file.size);
|
|
22
|
+
var iconMap = {
|
|
23
|
+
txt: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202509/17/b46c7_20250917144926.png',
|
|
24
|
+
xlsx: 'https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202509/17/0094f_20250917144837.png'
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
fileIcon: iconMap[fileType.toLowerCase()] || '',
|
|
28
|
+
fileName: fileName,
|
|
29
|
+
fileSize: fileSize,
|
|
30
|
+
isImage: file.isImage
|
|
31
|
+
};
|
|
32
|
+
}, [file]),
|
|
33
|
+
fileIcon = _React$useMemo.fileIcon,
|
|
34
|
+
fileName = _React$useMemo.fileName,
|
|
35
|
+
fileSize = _React$useMemo.fileSize,
|
|
36
|
+
isImage = _React$useMemo.isImage; // 更精确的依赖
|
|
37
|
+
|
|
38
|
+
// 缓存事件处理函数
|
|
39
|
+
var handleRetryClick = React.useCallback(function () {
|
|
40
|
+
if (handleReTry && file) {
|
|
41
|
+
handleReTry(file);
|
|
42
|
+
}
|
|
43
|
+
}, [handleReTry, file]);
|
|
44
|
+
var handleDeleteClick = React.useCallback(function () {
|
|
45
|
+
if (handleDelFile) {
|
|
46
|
+
handleDelFile();
|
|
47
|
+
}
|
|
48
|
+
}, [handleDelFile]);
|
|
49
|
+
if (!file) return null; // 空状态处理
|
|
50
|
+
|
|
51
|
+
var isError = file.status === FileStatus.UPLOAD_FAILED || file.status === FileStatus.ANALYSE_FAILED || file.status === FileStatus.NETWORK_ERROR;
|
|
52
|
+
var isLoading = [FileStatus.PADDING, FileStatus.RETRING, FileStatus.UPLOADING].includes(file.status);
|
|
53
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
54
|
+
className: styles.uploadBox
|
|
55
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
56
|
+
className: styles.uploadIcon
|
|
57
|
+
}, isImage ? /*#__PURE__*/React.createElement("img", {
|
|
58
|
+
src: file.fileUrl,
|
|
59
|
+
alt: "file-icon",
|
|
60
|
+
style: {
|
|
61
|
+
width: '36px',
|
|
62
|
+
height: '36px',
|
|
63
|
+
objectFit: 'cover',
|
|
64
|
+
borderRadius: 8,
|
|
65
|
+
background: "#D9DCE5"
|
|
66
|
+
}
|
|
67
|
+
}) : /*#__PURE__*/React.createElement("img", {
|
|
68
|
+
src: fileIcon,
|
|
69
|
+
alt: "file-icon"
|
|
70
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
71
|
+
className: styles.uploadName
|
|
72
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
73
|
+
className: styles.uploadfileName
|
|
74
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
75
|
+
className: styles.fileName
|
|
76
|
+
}, fileName)), (fileSize || isError) && /*#__PURE__*/React.createElement("div", {
|
|
77
|
+
className: styles.sizeText
|
|
78
|
+
}, fileSize && !isError && /*#__PURE__*/React.createElement("span", {
|
|
79
|
+
className: styles.size
|
|
80
|
+
}, fileSize), isError && /*#__PURE__*/React.createElement("span", {
|
|
81
|
+
className: styles.errorText
|
|
82
|
+
}, file.status === FileStatus.UPLOAD_FAILED ? t('upload.status.uploadFailed') : file.status === FileStatus.NETWORK_ERROR ? t('upload.status.networkError') : t('upload.status.parseFailed')))), isLoading && /*#__PURE__*/React.createElement("div", {
|
|
83
|
+
className: styles.uploadLoading
|
|
84
|
+
}, /*#__PURE__*/React.createElement("span", null, file.status === FileStatus.PADDING ? t('upload.status.parsing') : file.status === FileStatus.UPLOADING ? t('upload.status.uploading') : t('upload.status.retrying')), /*#__PURE__*/React.createElement("img", {
|
|
85
|
+
src: "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202509/07/0a0fa_20250907093927.gif",
|
|
86
|
+
alt: "loading"
|
|
87
|
+
})), isError && /*#__PURE__*/React.createElement("div", {
|
|
88
|
+
className: styles.uploadError,
|
|
89
|
+
onClick: handleRetryClick
|
|
90
|
+
}, t('common.retry'), /*#__PURE__*/React.createElement("img", {
|
|
91
|
+
src: reTry,
|
|
92
|
+
alt: "",
|
|
93
|
+
style: {
|
|
94
|
+
width: 16,
|
|
95
|
+
height: 16
|
|
96
|
+
}
|
|
97
|
+
})), showDel && /*#__PURE__*/React.createElement("div", {
|
|
98
|
+
className: styles.delIcon,
|
|
99
|
+
onClick: handleDeleteClick
|
|
100
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
101
|
+
src: "https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202509/12/6fa3e_20250912145501.png",
|
|
102
|
+
alt: "delete"
|
|
103
|
+
})));
|
|
104
|
+
};
|
|
105
|
+
export default CustomFile;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FileStatus } from '../../interfaces/fileInterface';
|
|
3
|
+
interface UploadFileProps {
|
|
4
|
+
file: {
|
|
5
|
+
fileType?: string;
|
|
6
|
+
fileName?: string;
|
|
7
|
+
status: FileStatus;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
handleDelFile?: () => void;
|
|
11
|
+
handleReTry?: (file: any) => void;
|
|
12
|
+
showDel?: boolean;
|
|
13
|
+
isSingle?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const ImageFile: React.FC<UploadFileProps & {
|
|
16
|
+
isMessage?: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
export default ImageFile;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import styles from "./imageFile.module.css";
|
|
4
|
+
import reTry from "../../assets/image/retry.png";
|
|
5
|
+
import { FileStatus } from "../../interfaces/fileInterface";
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
var ImageFile = function ImageFile(_ref) {
|
|
8
|
+
var file = _ref.file,
|
|
9
|
+
handleDelFile = _ref.handleDelFile,
|
|
10
|
+
handleReTry = _ref.handleReTry,
|
|
11
|
+
_ref$showDel = _ref.showDel,
|
|
12
|
+
showDel = _ref$showDel === void 0 ? true : _ref$showDel,
|
|
13
|
+
isMessage = _ref.isMessage,
|
|
14
|
+
isSingle = _ref.isSingle;
|
|
15
|
+
var _useTranslation = useTranslation(),
|
|
16
|
+
t = _useTranslation.t;
|
|
17
|
+
|
|
18
|
+
// 缓存事件处理函数
|
|
19
|
+
var handleRetryClick = React.useCallback(function () {
|
|
20
|
+
if (handleReTry && file) {
|
|
21
|
+
handleReTry(file);
|
|
22
|
+
}
|
|
23
|
+
}, [handleReTry, file]);
|
|
24
|
+
var handleDeleteClick = React.useCallback(function () {
|
|
25
|
+
if (handleDelFile) {
|
|
26
|
+
handleDelFile();
|
|
27
|
+
}
|
|
28
|
+
}, [handleDelFile]);
|
|
29
|
+
if (!file) return null; // 空状态处理
|
|
30
|
+
|
|
31
|
+
var isError = file.status === FileStatus.UPLOAD_FAILED || file.status === FileStatus.ANALYSE_FAILED || file.status === FileStatus.NETWORK_ERROR;
|
|
32
|
+
var isLoading = [FileStatus.PADDING, FileStatus.RETRING, FileStatus.UPLOADING].includes(file.status);
|
|
33
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
34
|
+
className: classNames(styles.uploadBox, isMessage ? styles.messageImg : '', isSingle ? styles.singleImg : '')
|
|
35
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
36
|
+
src: file.fileUrl,
|
|
37
|
+
alt: "file-icon",
|
|
38
|
+
className: classNames(styles.uploadImg)
|
|
39
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
40
|
+
className: styles.uploadName
|
|
41
|
+
}, isError && /*#__PURE__*/React.createElement("div", {
|
|
42
|
+
className: styles.sizeText
|
|
43
|
+
}, isError && /*#__PURE__*/React.createElement("span", {
|
|
44
|
+
className: styles.errorText
|
|
45
|
+
}, file.status === FileStatus.UPLOAD_FAILED ? t('upload.status.uploadFailed') : file.status === FileStatus.NETWORK_ERROR ? t('upload.status.networkError') : t('upload.status.parseFailed')))), isLoading && /*#__PURE__*/React.createElement("div", {
|
|
46
|
+
className: styles.uploadLoading
|
|
47
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
48
|
+
src: "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202509/07/0a0fa_20250907093927.gif",
|
|
49
|
+
alt: "loading"
|
|
50
|
+
})), isError && /*#__PURE__*/React.createElement("div", {
|
|
51
|
+
className: styles.uploadError,
|
|
52
|
+
onClick: handleRetryClick
|
|
53
|
+
}, t('common.retry'), /*#__PURE__*/React.createElement("img", {
|
|
54
|
+
src: reTry,
|
|
55
|
+
alt: "",
|
|
56
|
+
style: {
|
|
57
|
+
width: 16,
|
|
58
|
+
height: 16
|
|
59
|
+
}
|
|
60
|
+
})), showDel && /*#__PURE__*/React.createElement("div", {
|
|
61
|
+
className: styles.delIcon,
|
|
62
|
+
onClick: handleDeleteClick
|
|
63
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
64
|
+
src: "https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202509/12/6fa3e_20250912145501.png",
|
|
65
|
+
alt: "delete"
|
|
66
|
+
})));
|
|
67
|
+
};
|
|
68
|
+
export default ImageFile;
|