@myun/gimi-chat 0.0.3 → 0.0.5
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/fetch.d.ts +64 -0
- package/dist/apis/fetch.js +512 -0
- package/dist/apis/useApi.d.ts +57 -0
- package/dist/apis/useApi.js +378 -0
- package/dist/assets/image/Subtract.png +0 -0
- package/dist/assets/image/ai-logo.png +0 -0
- package/dist/assets/image/copyIcon.png +0 -0
- package/dist/assets/image/deepthinkActive.png +0 -0
- package/dist/assets/image/empty-img-dark.png +0 -0
- package/dist/assets/image/empty-img.png +0 -0
- package/dist/assets/image/like_active.png +0 -0
- package/dist/assets/image/love.png +0 -0
- package/dist/assets/image/retry.png +0 -0
- package/dist/assets/image/soundOut.png +0 -0
- package/dist/assets/image/unlike_active.png +0 -0
- package/dist/assets/image/unlove.png +0 -0
- package/dist/assets/lottie/ai-bg.json +1704 -0
- package/dist/assets/lottie/ai-loading.json +192 -0
- package/dist/assets/lottie/ai-output-loading.json +272 -0
- package/dist/assets/lottie/ai-output-normal.json +17694 -0
- package/dist/assets/lottie/ai-output-strengthen.json +17321 -0
- package/dist/assets/lottie/ai-voice-play.json +1 -0
- package/dist/assets/lottie/living.json +705 -0
- package/dist/assets/lottie/myun-living.json +726 -0
- package/dist/assets/lottie/myun-loading.json +530 -0
- package/dist/components/ai-chat-dialogue/index.d.ts +16 -0
- package/dist/components/ai-chat-dialogue/index.js +1056 -0
- package/dist/components/ai-chat-dialogue/index.module.css +230 -0
- package/dist/components/ai-chat-dialogue/message-parser.d.ts +36 -0
- package/dist/components/ai-chat-dialogue/message-parser.js +52 -0
- package/dist/components/ai-chat-dialogue/tlv.d.ts +7 -0
- package/dist/components/ai-chat-dialogue/tlv.js +32 -0
- package/dist/components/ai-chat-dialogue/volc-voice-call-client.d.ts +47 -0
- package/dist/components/ai-chat-dialogue/volc-voice-call-client.js +246 -0
- package/dist/components/ai-correction/index.d.ts +5 -0
- package/dist/components/ai-correction/index.js +45 -0
- package/dist/components/ai-loading/index.d.ts +3 -0
- package/dist/components/ai-loading/index.js +14 -0
- package/dist/components/ai-loading/index.module.css +11 -0
- package/dist/components/answer-item/index.d.ts +27 -0
- package/dist/components/answer-item/index.js +194 -0
- package/dist/components/answer-item/index.module.css +266 -0
- package/dist/components/ask-card/index.d.ts +10 -0
- package/dist/components/ask-card/index.js +76 -0
- package/dist/components/ask-card/index.module.css +122 -0
- package/dist/components/chat-input/index.d.ts +31 -0
- package/dist/components/chat-input/index.js +433 -0
- package/dist/components/chat-input/index.module.css +42 -0
- package/dist/components/chat-voice/VoiceCommunication.d.ts +7 -0
- package/dist/components/chat-voice/VoiceCommunication.js +69 -0
- package/dist/components/chat-voice/VoiceRecord.d.ts +7 -0
- package/dist/components/chat-voice/VoiceRecord.js +34 -0
- package/dist/components/conversation-delete/index.d.ts +5 -0
- package/dist/components/conversation-delete/index.js +24 -0
- package/dist/components/dots-loading/index.d.ts +2 -0
- package/dist/components/dots-loading/index.js +11 -0
- package/dist/components/dots-loading/index.module.css +41 -0
- package/dist/components/empty/index.d.ts +9 -0
- package/dist/components/empty/index.js +32 -0
- package/dist/components/empty/index.module.css +24 -0
- package/dist/components/excel-components/ExcelCard.d.ts +11 -0
- package/dist/components/excel-components/ExcelCard.js +35 -0
- package/dist/components/excel-components/ExcelExcuting.d.ts +10 -0
- package/dist/components/excel-components/ExcelExcuting.js +263 -0
- package/dist/components/excel-components/ExcelFailCard.d.ts +9 -0
- package/dist/components/excel-components/ExcelFailCard.js +20 -0
- package/dist/components/excel-components/ExcelSuccessCard.d.ts +5 -0
- package/dist/components/excel-components/ExcelSuccessCard.js +50 -0
- package/dist/components/excel-components/index.module.css +212 -0
- package/dist/components/excel-components/styles.module.css +178 -0
- package/dist/components/file-card/fileCardSidebar.d.ts +8 -0
- package/dist/components/file-card/fileCardSidebar.js +56 -0
- package/dist/components/file-card/index.d.ts +15 -0
- package/dist/components/file-card/index.js +97 -0
- package/dist/components/file-card/index.module.css +139 -0
- package/dist/components/file-preview/index.d.ts +3 -0
- package/dist/components/file-preview/index.js +227 -0
- package/dist/components/file-preview/index.module.css +83 -0
- package/dist/components/file-upload/index.d.ts +16 -0
- package/dist/components/file-upload/index.js +238 -0
- package/dist/components/file-upload/uploadV1.d.ts +16 -0
- package/dist/components/file-upload/uploadV1.js +267 -0
- package/dist/components/gimi-sidebar/index.d.ts +17 -0
- package/dist/components/gimi-sidebar/index.js +41 -0
- package/dist/components/gimi-sidebar/index.module.css +118 -0
- package/dist/components/header/index.d.ts +5 -0
- package/dist/components/header/index.js +20 -0
- package/dist/components/header/index.module.css +19 -0
- package/dist/components/iconfont-com/index.d.ts +11 -0
- package/dist/components/iconfont-com/index.js +29 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/knowledge-trace/KnowledgeIconComponent.d.ts +7 -0
- package/dist/components/knowledge-trace/KnowledgeIconComponent.js +101 -0
- package/dist/components/knowledge-trace/classList.d.ts +6 -0
- package/dist/components/knowledge-trace/classList.js +72 -0
- package/dist/components/knowledge-trace/documentList.d.ts +6 -0
- package/dist/components/knowledge-trace/documentList.js +75 -0
- package/dist/components/knowledge-trace/index.d.ts +18 -0
- package/dist/components/knowledge-trace/index.js +155 -0
- package/dist/components/knowledge-trace/index.module.css +254 -0
- package/dist/components/knowledge-trace/interfaces.d.ts +166 -0
- package/dist/components/knowledge-trace/interfaces.js +1 -0
- package/dist/components/knowledge-trace/videoList.d.ts +6 -0
- package/dist/components/knowledge-trace/videoList.js +91 -0
- package/dist/components/lottie-img/index.d.ts +8 -0
- package/dist/components/lottie-img/index.js +99 -0
- package/dist/components/message-actions/CopyButton.d.ts +7 -0
- package/dist/components/message-actions/CopyButton.js +33 -0
- package/dist/components/message-actions/LikeButton.d.ts +7 -0
- package/dist/components/message-actions/LikeButton.js +34 -0
- package/dist/components/message-actions/RegenerateButton.d.ts +5 -0
- package/dist/components/message-actions/RegenerateButton.js +27 -0
- package/dist/components/message-actions/UnLikeButton.d.ts +7 -0
- package/dist/components/message-actions/UnLikeButton.js +34 -0
- package/dist/components/message-actions/VoicePlay.d.ts +10 -0
- package/dist/components/message-actions/VoicePlay.js +74 -0
- package/dist/components/message-list/index.d.ts +19 -0
- package/dist/components/message-list/index.js +164 -0
- package/dist/components/message-list/index.module.css +261 -0
- package/dist/components/no-microphone-root/index.d.ts +6 -0
- package/dist/components/no-microphone-root/index.js +36 -0
- package/dist/components/no-microphone-root/index.module.css +48 -0
- package/dist/components/preset-agent-content/index.d.ts +8 -0
- package/dist/components/preset-agent-content/index.js +24 -0
- package/dist/components/preset-agent-content/index.module.css +46 -0
- package/dist/components/quoted-content/index.d.ts +0 -0
- package/dist/components/quoted-content/index.js +171 -0
- package/dist/components/quoted-content/index.module.css +80 -0
- package/dist/components/reasoning-content/index.d.ts +6 -0
- package/dist/components/reasoning-content/index.js +116 -0
- package/dist/components/reasoning-content/index.module.css +169 -0
- package/dist/components/reference-content/index.d.ts +28 -0
- package/dist/components/reference-content/index.js +125 -0
- package/dist/components/reference-content/index.module.css +84 -0
- package/dist/components/templates/CommonChat.d.ts +5 -0
- package/dist/components/templates/CommonChat.js +218 -0
- package/dist/components/templates/GimiChatComponent.d.ts +4 -0
- package/dist/components/templates/GimiChatComponent.js +23 -0
- package/dist/components/templates/demo/demo.d.ts +2 -0
- package/dist/components/templates/demo/demo.js +109 -0
- package/dist/components/templates/index.module.css +109 -0
- package/dist/components/upload-list/index.d.ts +15 -0
- package/dist/components/upload-list/index.js +90 -0
- package/dist/components/upload-list/index.module.css +119 -0
- package/dist/components/voice-bars/index.d.ts +4 -0
- package/dist/components/voice-bars/index.js +174 -0
- package/dist/components/voice-check-dialog/index.d.ts +8 -0
- package/dist/components/voice-check-dialog/index.js +163 -0
- package/dist/components/voice-check-dialog/index.module.css +9 -0
- package/dist/components/voice-recording/index.d.ts +9 -0
- package/dist/components/voice-recording/index.js +54 -0
- package/dist/components/voice-recording/index.module.css +41 -0
- package/dist/components/work-flow-content/demo.d.ts +3 -0
- package/dist/components/work-flow-content/demo.js +11 -0
- package/dist/components/work-flow-content/index.d.ts +6 -0
- package/dist/components/work-flow-content/index.js +55 -0
- package/dist/components/work-flow-content/index.module.css +24 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.js +24 -0
- package/dist/hooks/useChatActions.d.ts +12 -0
- package/dist/hooks/useChatActions.js +207 -0
- package/dist/hooks/useChatHistory.d.ts +8 -0
- package/dist/hooks/useChatHistory.js +225 -0
- package/dist/hooks/useChatMessage.d.ts +49 -0
- package/dist/hooks/useChatMessage.js +87 -0
- package/dist/hooks/useChatRecommend.d.ts +8 -0
- package/dist/hooks/useChatRecommend.js +126 -0
- package/dist/hooks/useChatStream.d.ts +20 -0
- package/dist/hooks/useChatStream.js +244 -0
- package/dist/hooks/useChatUI.d.ts +32 -0
- package/dist/hooks/useChatUI.js +134 -0
- package/dist/hooks/useChatVoice.d.ts +11 -0
- package/dist/hooks/useChatVoice.js +379 -0
- package/dist/hooks/useCommonChatAPI.d.ts +27 -0
- package/dist/hooks/useCommonChatAPI.js +1276 -0
- package/dist/hooks/useFile.d.ts +13 -0
- package/dist/hooks/useFile.js +288 -0
- package/dist/hooks/useKnowledgeService.d.ts +17 -0
- package/dist/hooks/useKnowledgeService.js +210 -0
- package/dist/hooks/useLastEventId.d.ts +8 -0
- package/dist/hooks/useLastEventId.js +66 -0
- package/dist/hooks/useLongPoll.d.ts +3 -0
- package/dist/hooks/useLongPoll.js +111 -0
- package/dist/hooks/useScroll.d.ts +4 -0
- package/dist/hooks/useScroll.js +172 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/chatMessage.d.ts +139 -0
- package/dist/interfaces/fileInterface.d.ts +10 -0
- package/dist/interfaces/fileInterface.js +11 -0
- package/dist/interfaces/knowledgeTrace.d.ts +177 -0
- package/dist/store/hooks.d.ts +4 -0
- package/dist/store/hooks.js +3 -0
- package/dist/store/index.d.ts +7 -0
- package/dist/store/index.js +7 -0
- package/dist/store/slices/gimiMenuSlice.d.ts +95 -0
- package/dist/store/slices/gimiMenuSlice.js +251 -0
- package/dist/utils/chatInputUtil.d.ts +19 -0
- package/dist/utils/chatInputUtil.js +45 -0
- package/dist/utils/tools.d.ts +50 -0
- package/dist/utils/tools.js +474 -0
- package/dist/utils/voice-stream.d.ts +119 -0
- package/dist/utils/voice-stream.js +1162 -0
- package/package.json +5 -6
- package/LICENSE +0 -21
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
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
|
+
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
|
+
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
|
+
import React from 'react';
|
|
6
|
+
import { Upload, Toast, Button } from '@douyinfe/semi-ui';
|
|
7
|
+
import { IconPaperclip } from '@douyinfe/semi-icons';
|
|
8
|
+
import { useAppDispatch, useAppSelector } from "../../store/hooks";
|
|
9
|
+
import { setFileList } from "../../store/slices/gimiMenuSlice";
|
|
10
|
+
import { FileStatus } from "../../interfaces/fileInterface";
|
|
11
|
+
import { useGimiFileUpload } from "../../hooks/useFile";
|
|
12
|
+
var DEFAULT_ACCEPT = '.xlsx,.txt';
|
|
13
|
+
var MAX_RETRY_COUNT = 3;
|
|
14
|
+
/** Redux FileItem → Semi Upload FileItem */
|
|
15
|
+
var transformFileItem = function transformFileItem(list) {
|
|
16
|
+
return list.map(function (item) {
|
|
17
|
+
return {
|
|
18
|
+
uid: item.uid,
|
|
19
|
+
name: item.name,
|
|
20
|
+
size: item.size.toString(),
|
|
21
|
+
status: item.status
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
26
|
+
var _props$maxSize = props.maxSize,
|
|
27
|
+
maxSize = _props$maxSize === void 0 ? 10 : _props$maxSize,
|
|
28
|
+
_props$limit = props.limit,
|
|
29
|
+
limit = _props$limit === void 0 ? 1 : _props$limit,
|
|
30
|
+
accept = props.accept,
|
|
31
|
+
disabled = props.disabled,
|
|
32
|
+
children = props.children;
|
|
33
|
+
var dispatch = useAppDispatch();
|
|
34
|
+
var fileList = useAppSelector(function (s) {
|
|
35
|
+
return s.gimiMenu.fileList;
|
|
36
|
+
});
|
|
37
|
+
var baseUrl = useAppSelector(function (s) {
|
|
38
|
+
return s.gimiMenu.baseUrl;
|
|
39
|
+
});
|
|
40
|
+
var token = useAppSelector(function (s) {
|
|
41
|
+
return s.gimiMenu.token;
|
|
42
|
+
});
|
|
43
|
+
var uploadUrl = "https://".concat(baseUrl, "/mfilesvc/agentMessage/uploadFile");
|
|
44
|
+
var _useGimiFileUpload = useGimiFileUpload(),
|
|
45
|
+
handleSSEFileAnalyize = _useGimiFileUpload.handleSSEFileAnalyize,
|
|
46
|
+
fileUploadAbortRef = _useGimiFileUpload.fileUploadAbortRef;
|
|
47
|
+
|
|
48
|
+
/** 保存原始 File:uid -> File */
|
|
49
|
+
var rawFileMapRef = React.useRef(new Map());
|
|
50
|
+
|
|
51
|
+
/** 重试次数:uid -> count */
|
|
52
|
+
var retryCountMapRef = React.useRef(new Map());
|
|
53
|
+
|
|
54
|
+
/** 更新 Redux 中的文件状态(始终只维护一个文件) */
|
|
55
|
+
var updateFile = function updateFile(file) {
|
|
56
|
+
dispatch(setFileList({
|
|
57
|
+
fileList: [file]
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** 失败后重新上传 */
|
|
62
|
+
var retryUpload = function retryUpload(uid) {
|
|
63
|
+
var rawFile = rawFileMapRef.current.get(uid);
|
|
64
|
+
if (!rawFile) return;
|
|
65
|
+
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
67
|
+
customRequest({
|
|
68
|
+
file: {
|
|
69
|
+
uid: uid,
|
|
70
|
+
name: rawFile.name,
|
|
71
|
+
size: rawFile.size,
|
|
72
|
+
fileInstance: rawFile
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
var customRequest = /*#__PURE__*/function () {
|
|
77
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
78
|
+
var file, onSuccess, onError, rawFile, controller, formData, _response$result, fullResponse, response, result, successFile, _retryCountMapRef$cur, currentRetry, retryWhenOnline;
|
|
79
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
80
|
+
while (1) switch (_context.prev = _context.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
file = options.file, onSuccess = options.onSuccess, onError = options.onError;
|
|
83
|
+
rawFile = file.fileInstance || file.originFileObj;
|
|
84
|
+
if (rawFile) {
|
|
85
|
+
_context.next = 5;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
Toast.error('文件读取失败');
|
|
89
|
+
return _context.abrupt("return");
|
|
90
|
+
case 5:
|
|
91
|
+
// 缓存原始 File
|
|
92
|
+
rawFileMapRef.current.set(file.uid, rawFile);
|
|
93
|
+
|
|
94
|
+
// 首次上传才初始化重试次数
|
|
95
|
+
if (!retryCountMapRef.current.has(file.uid)) {
|
|
96
|
+
retryCountMapRef.current.set(file.uid, 0);
|
|
97
|
+
}
|
|
98
|
+
controller = new AbortController();
|
|
99
|
+
fileUploadAbortRef.current = controller;
|
|
100
|
+
updateFile({
|
|
101
|
+
uid: file.uid,
|
|
102
|
+
name: file.name,
|
|
103
|
+
size: file.size,
|
|
104
|
+
status: FileStatus.UPLOADING
|
|
105
|
+
});
|
|
106
|
+
formData = new FormData();
|
|
107
|
+
formData.append('file', rawFile);
|
|
108
|
+
_context.prev = 12;
|
|
109
|
+
_context.next = 15;
|
|
110
|
+
return fetch(uploadUrl, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: {
|
|
113
|
+
Authorization: 'Bearer ' + token
|
|
114
|
+
},
|
|
115
|
+
body: formData,
|
|
116
|
+
signal: controller.signal
|
|
117
|
+
}).then(function (res) {
|
|
118
|
+
return res.json();
|
|
119
|
+
});
|
|
120
|
+
case 15:
|
|
121
|
+
fullResponse = _context.sent;
|
|
122
|
+
response = fullResponse[0];
|
|
123
|
+
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)) {
|
|
124
|
+
_context.next = 26;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
result = response.result;
|
|
128
|
+
successFile = {
|
|
129
|
+
uid: file.uid,
|
|
130
|
+
name: file.name,
|
|
131
|
+
size: file.size,
|
|
132
|
+
status: FileStatus.UPLOAD_SUCCESS,
|
|
133
|
+
fileUrl: result.fileAddr,
|
|
134
|
+
fileName: result.fileName,
|
|
135
|
+
fileSize: result.fileSize,
|
|
136
|
+
fileToken: result.fileToken,
|
|
137
|
+
fileType: result.fileName.split('.').pop()
|
|
138
|
+
};
|
|
139
|
+
updateFile(successFile);
|
|
140
|
+
handleSSEFileAnalyize(successFile, true);
|
|
141
|
+
|
|
142
|
+
// 成功后清理 retry 计数
|
|
143
|
+
retryCountMapRef.current.delete(file.uid);
|
|
144
|
+
onSuccess === null || onSuccess === void 0 || onSuccess(response);
|
|
145
|
+
_context.next = 27;
|
|
146
|
+
break;
|
|
147
|
+
case 26:
|
|
148
|
+
throw new Error('upload failed');
|
|
149
|
+
case 27:
|
|
150
|
+
_context.next = 49;
|
|
151
|
+
break;
|
|
152
|
+
case 29:
|
|
153
|
+
_context.prev = 29;
|
|
154
|
+
_context.t0 = _context["catch"](12);
|
|
155
|
+
if (!(_context.t0.name === 'AbortError')) {
|
|
156
|
+
_context.next = 33;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
return _context.abrupt("return");
|
|
160
|
+
case 33:
|
|
161
|
+
currentRetry = (_retryCountMapRef$cur = retryCountMapRef.current.get(file.uid)) !== null && _retryCountMapRef$cur !== void 0 ? _retryCountMapRef$cur : 0;
|
|
162
|
+
/** 网络异常:不计入重试次数 */
|
|
163
|
+
if (navigator.onLine) {
|
|
164
|
+
_context.next = 40;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
Toast.error('网络异常,等待恢复后重试');
|
|
168
|
+
updateFile({
|
|
169
|
+
uid: file.uid,
|
|
170
|
+
name: file.name,
|
|
171
|
+
size: file.size,
|
|
172
|
+
status: FileStatus.NETWORK_ERROR
|
|
173
|
+
});
|
|
174
|
+
retryWhenOnline = function retryWhenOnline() {
|
|
175
|
+
window.removeEventListener('online', retryWhenOnline);
|
|
176
|
+
retryUpload(file.uid);
|
|
177
|
+
};
|
|
178
|
+
window.addEventListener('online', retryWhenOnline);
|
|
179
|
+
return _context.abrupt("return");
|
|
180
|
+
case 40:
|
|
181
|
+
if (!(currentRetry >= MAX_RETRY_COUNT)) {
|
|
182
|
+
_context.next = 46;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
Toast.error('文件上传失败,已达到最大重试次数');
|
|
186
|
+
updateFile({
|
|
187
|
+
uid: file.uid,
|
|
188
|
+
name: file.name,
|
|
189
|
+
size: file.size,
|
|
190
|
+
status: FileStatus.UPLOAD_FAILED
|
|
191
|
+
});
|
|
192
|
+
retryCountMapRef.current.delete(file.uid);
|
|
193
|
+
onError === null || onError === void 0 || onError(_context.t0);
|
|
194
|
+
return _context.abrupt("return");
|
|
195
|
+
case 46:
|
|
196
|
+
/** ⏱️ 未达上限,继续重试 */
|
|
197
|
+
retryCountMapRef.current.set(file.uid, currentRetry + 1);
|
|
198
|
+
Toast.warning("\u4E0A\u4F20\u5931\u8D25\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF08".concat(currentRetry + 1, "/").concat(MAX_RETRY_COUNT, "\uFF09"));
|
|
199
|
+
setTimeout(function () {
|
|
200
|
+
retryUpload(file.uid);
|
|
201
|
+
}, 1000);
|
|
202
|
+
case 49:
|
|
203
|
+
case "end":
|
|
204
|
+
return _context.stop();
|
|
205
|
+
}
|
|
206
|
+
}, _callee, null, [[12, 29]]);
|
|
207
|
+
}));
|
|
208
|
+
return function customRequest(_x) {
|
|
209
|
+
return _ref.apply(this, arguments);
|
|
210
|
+
};
|
|
211
|
+
}();
|
|
212
|
+
React.useImperativeHandle(ref, function () {
|
|
213
|
+
return {
|
|
214
|
+
abortUpload: function abortUpload() {
|
|
215
|
+
var _fileUploadAbortRef$c;
|
|
216
|
+
(_fileUploadAbortRef$c = fileUploadAbortRef.current) === null || _fileUploadAbortRef$c === void 0 || _fileUploadAbortRef$c.abort();
|
|
217
|
+
},
|
|
218
|
+
handleSSEFileAnalyize: handleSSEFileAnalyize,
|
|
219
|
+
retryUpload: retryUpload
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
var trigger = /*#__PURE__*/React.createElement(Button, {
|
|
223
|
+
icon: /*#__PURE__*/React.createElement(IconPaperclip, null),
|
|
224
|
+
type: "tertiary"
|
|
225
|
+
}, "\u70B9\u51FB\u4E0A\u4F20");
|
|
226
|
+
return /*#__PURE__*/React.createElement(Upload, {
|
|
227
|
+
customRequest: customRequest,
|
|
228
|
+
action: "",
|
|
229
|
+
limit: limit,
|
|
230
|
+
multiple: limit > 1,
|
|
231
|
+
accept: (accept === null || accept === void 0 ? void 0 : accept.join(',')) || DEFAULT_ACCEPT,
|
|
232
|
+
maxSize: maxSize * 1024,
|
|
233
|
+
disabled: disabled,
|
|
234
|
+
showUploadList: false,
|
|
235
|
+
fileList: transformFileItem(fileList || [])
|
|
236
|
+
}, children || trigger);
|
|
237
|
+
});
|
|
238
|
+
export default FileUpload;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IProps {
|
|
3
|
+
maxSize?: number;
|
|
4
|
+
limit?: number;
|
|
5
|
+
accept?: string[];
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export interface FileUploadRef {
|
|
10
|
+
handleSSEFileAnalyize: (file: any, autoRetry?: boolean) => void;
|
|
11
|
+
fileUpload: (file: any, autoRetry?: boolean) => void;
|
|
12
|
+
abortSSE: () => void;
|
|
13
|
+
fileUploadAbortRef: React.MutableRefObject<AbortController | null>;
|
|
14
|
+
}
|
|
15
|
+
declare const FileUpload: React.ForwardRefExoticComponent<IProps & React.RefAttributes<unknown>>;
|
|
16
|
+
export default FileUpload;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
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
|
+
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
|
+
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
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; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
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); }
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { Upload, Toast, Button } from '@douyinfe/semi-ui';
|
|
12
|
+
import { IconPaperclip } from '@douyinfe/semi-icons';
|
|
13
|
+
import { FileStatus } from "../../interfaces/fileInterface";
|
|
14
|
+
import { useAppDispatch, useAppSelector } from "../../store/hooks";
|
|
15
|
+
import { setFileList } from "../../store/slices/gimiMenuSlice";
|
|
16
|
+
import { useGimiFileUpload } from "../../hooks/useFile";
|
|
17
|
+
var defaultFileLimit = '.xlsx,.txt';
|
|
18
|
+
var transformFileItem = function transformFileItem(item) {
|
|
19
|
+
return item.map(function (file) {
|
|
20
|
+
return {
|
|
21
|
+
status: file.status,
|
|
22
|
+
name: file.name,
|
|
23
|
+
size: file.size.toString(),
|
|
24
|
+
uid: file.uid
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var FileUpload = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
29
|
+
var maxSize = props.maxSize,
|
|
30
|
+
limit = props.limit,
|
|
31
|
+
accept = props.accept,
|
|
32
|
+
disabled = props.disabled,
|
|
33
|
+
children = props.children;
|
|
34
|
+
var dispatch = useAppDispatch();
|
|
35
|
+
var fileList = useAppSelector(function (state) {
|
|
36
|
+
return state.gimiMenu.fileList;
|
|
37
|
+
});
|
|
38
|
+
var baseUrl = useAppSelector(function (state) {
|
|
39
|
+
return state.gimiMenu.baseUrl;
|
|
40
|
+
});
|
|
41
|
+
var token = useAppSelector(function (state) {
|
|
42
|
+
return state.gimiMenu.token;
|
|
43
|
+
});
|
|
44
|
+
var action = "https://".concat(baseUrl, "/mfilesvc/agentMessage/uploadFile");
|
|
45
|
+
var _useGimiFileUpload = useGimiFileUpload(),
|
|
46
|
+
handleSSEFileAnalyize = _useGimiFileUpload.handleSSEFileAnalyize,
|
|
47
|
+
fileUpload = _useGimiFileUpload.fileUpload,
|
|
48
|
+
fileUploadAbortRef = _useGimiFileUpload.fileUploadAbortRef;
|
|
49
|
+
var onChange = function onChange(object) {
|
|
50
|
+
var currentFile = object.fileList[0];
|
|
51
|
+
var newFile = {
|
|
52
|
+
name: currentFile.name,
|
|
53
|
+
size: currentFile.size,
|
|
54
|
+
uid: currentFile.uid,
|
|
55
|
+
status: FileStatus.UPLOADING
|
|
56
|
+
};
|
|
57
|
+
// 目前只拿最新上传的文件
|
|
58
|
+
dispatch(setFileList({
|
|
59
|
+
fileList: [newFile]
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
// 上传成功的判断应该基于info.file.status
|
|
63
|
+
if (currentFile.status === FileStatus.UPLOAD_SUCCESS) {
|
|
64
|
+
var _response$result;
|
|
65
|
+
var response = currentFile.response[0];
|
|
66
|
+
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) {
|
|
67
|
+
var responseObj = {
|
|
68
|
+
fileUrl: response.result.fileAddr,
|
|
69
|
+
fileName: response.result.fileName,
|
|
70
|
+
fileSize: response.result.fileSize,
|
|
71
|
+
fileToken: response.result.fileToken,
|
|
72
|
+
fileType: "".concat(response.result.fileName.split('.').pop())
|
|
73
|
+
};
|
|
74
|
+
// 更新文件列表,添加后端返回的信息
|
|
75
|
+
var newFileList = fileList.map(function (item) {
|
|
76
|
+
if (item.uid === currentFile.uid) {
|
|
77
|
+
return _objectSpread(_objectSpread({}, item), responseObj);
|
|
78
|
+
}
|
|
79
|
+
return item;
|
|
80
|
+
});
|
|
81
|
+
dispatch(setFileList({
|
|
82
|
+
fileList: newFileList
|
|
83
|
+
}));
|
|
84
|
+
var pendingFile = fileList.find(function (item) {
|
|
85
|
+
return item.uid === currentFile.uid;
|
|
86
|
+
});
|
|
87
|
+
handleSSEFileAnalyize(_objectSpread(_objectSpread({}, pendingFile), responseObj), true);
|
|
88
|
+
} else {
|
|
89
|
+
Toast.error("".concat(currentFile.name, " \u4E0A\u4F20\u5931\u8D25'}"));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (currentFile.status === 'uploadFail') {
|
|
93
|
+
if (!navigator.onLine) {
|
|
94
|
+
Toast.error('无法连接到网络');
|
|
95
|
+
// 新增:如果当前有正在处理的文件,标记为网络错误
|
|
96
|
+
var handleOnlineReUpload = function handleOnlineReUpload() {
|
|
97
|
+
window.removeEventListener('online', handleOnlineReUpload);
|
|
98
|
+
fileUpload(currentFile, true); // 网络恢复后重新尝试连接
|
|
99
|
+
};
|
|
100
|
+
window.addEventListener('online', handleOnlineReUpload);
|
|
101
|
+
if (currentFile) {
|
|
102
|
+
var _newFile = {
|
|
103
|
+
name: currentFile.name,
|
|
104
|
+
size: currentFile.size,
|
|
105
|
+
uid: currentFile.uid,
|
|
106
|
+
status: FileStatus.NETWORK_ERROR
|
|
107
|
+
};
|
|
108
|
+
dispatch(setFileList({
|
|
109
|
+
fileList: [_newFile]
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// 开始三次重试
|
|
115
|
+
setTimeout(function () {
|
|
116
|
+
fileUpload(currentFile, true);
|
|
117
|
+
}, 1000);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var abortSSE = React.useCallback(function () {
|
|
121
|
+
if (fileUploadAbortRef.current) {
|
|
122
|
+
fileUploadAbortRef.current.abort();
|
|
123
|
+
fileUploadAbortRef.current = null;
|
|
124
|
+
}
|
|
125
|
+
}, [fileUploadAbortRef]);
|
|
126
|
+
|
|
127
|
+
// 通过ref暴露方法
|
|
128
|
+
React.useImperativeHandle(ref, function () {
|
|
129
|
+
return {
|
|
130
|
+
handleSSE: handleSSEFileAnalyize,
|
|
131
|
+
upload: fileUpload,
|
|
132
|
+
abortSSE: abortSSE,
|
|
133
|
+
fileUploadAbortRef: fileUploadAbortRef
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
React.useEffect(function () {
|
|
137
|
+
return function () {
|
|
138
|
+
abortSSE();
|
|
139
|
+
};
|
|
140
|
+
}, [abortSSE]);
|
|
141
|
+
var defailtTrigger = /*#__PURE__*/React.createElement(Button, {
|
|
142
|
+
icon: /*#__PURE__*/React.createElement(IconPaperclip, null),
|
|
143
|
+
type: "tertiary"
|
|
144
|
+
}, "\u70B9\u51FB\u4E0A\u4F20");
|
|
145
|
+
var customRequest = /*#__PURE__*/function () {
|
|
146
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
147
|
+
var file, onSuccess, onError, controller, formData, rawFile, _response$result2, response, responseObj;
|
|
148
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
149
|
+
while (1) switch (_context.prev = _context.next) {
|
|
150
|
+
case 0:
|
|
151
|
+
file = options.file, onSuccess = options.onSuccess, onError = options.onError;
|
|
152
|
+
controller = new AbortController();
|
|
153
|
+
fileUploadAbortRef.current = controller;
|
|
154
|
+
formData = new FormData();
|
|
155
|
+
rawFile = file.fileInstance || file.originFileObj;
|
|
156
|
+
formData.append('file', rawFile);
|
|
157
|
+
dispatch(setFileList({
|
|
158
|
+
fileList: [{
|
|
159
|
+
uid: file.uid,
|
|
160
|
+
name: file.name,
|
|
161
|
+
size: file.size,
|
|
162
|
+
status: FileStatus.UPLOADING
|
|
163
|
+
}]
|
|
164
|
+
}));
|
|
165
|
+
_context.prev = 7;
|
|
166
|
+
_context.next = 10;
|
|
167
|
+
return fetch(action, {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers: {
|
|
170
|
+
Authorization: 'Bearer ' + token
|
|
171
|
+
// ⚠️ 不要手动写 Content-Type
|
|
172
|
+
},
|
|
173
|
+
body: formData,
|
|
174
|
+
signal: controller.signal
|
|
175
|
+
}).then(function (res) {
|
|
176
|
+
return res.json();
|
|
177
|
+
});
|
|
178
|
+
case 10:
|
|
179
|
+
response = _context.sent;
|
|
180
|
+
if (!((response === null || response === void 0 ? void 0 : response.status) === 0 && response !== null && response !== void 0 && (_response$result2 = response.result) !== null && _response$result2 !== void 0 && _response$result2.fileToken)) {
|
|
181
|
+
_context.next = 18;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
responseObj = {
|
|
185
|
+
uid: file.uid,
|
|
186
|
+
name: file.name,
|
|
187
|
+
size: file.size,
|
|
188
|
+
status: FileStatus.UPLOAD_SUCCESS,
|
|
189
|
+
fileUrl: response.result.fileAddr,
|
|
190
|
+
fileName: response.result.fileName,
|
|
191
|
+
fileSize: response.result.fileSize,
|
|
192
|
+
fileToken: response.result.fileToken,
|
|
193
|
+
fileType: response.result.fileName.split('.').pop()
|
|
194
|
+
};
|
|
195
|
+
dispatch(setFileList({
|
|
196
|
+
fileList: [responseObj]
|
|
197
|
+
}));
|
|
198
|
+
handleSSEFileAnalyize(responseObj, true);
|
|
199
|
+
onSuccess === null || onSuccess === void 0 || onSuccess(response);
|
|
200
|
+
_context.next = 19;
|
|
201
|
+
break;
|
|
202
|
+
case 18:
|
|
203
|
+
throw new Error('upload failed');
|
|
204
|
+
case 19:
|
|
205
|
+
_context.next = 31;
|
|
206
|
+
break;
|
|
207
|
+
case 21:
|
|
208
|
+
_context.prev = 21;
|
|
209
|
+
_context.t0 = _context["catch"](7);
|
|
210
|
+
if (!(_context.t0.name === 'AbortError')) {
|
|
211
|
+
_context.next = 25;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
return _context.abrupt("return");
|
|
215
|
+
case 25:
|
|
216
|
+
if (navigator.onLine) {
|
|
217
|
+
_context.next = 29;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
Toast.error('无法连接到网络');
|
|
221
|
+
dispatch(setFileList({
|
|
222
|
+
fileList: [{
|
|
223
|
+
uid: file.uid,
|
|
224
|
+
name: file.name,
|
|
225
|
+
size: file.size,
|
|
226
|
+
status: FileStatus.NETWORK_ERROR
|
|
227
|
+
}]
|
|
228
|
+
}));
|
|
229
|
+
return _context.abrupt("return");
|
|
230
|
+
case 29:
|
|
231
|
+
Toast.error('上传失败');
|
|
232
|
+
onError === null || onError === void 0 || onError(_context.t0);
|
|
233
|
+
case 31:
|
|
234
|
+
case "end":
|
|
235
|
+
return _context.stop();
|
|
236
|
+
}
|
|
237
|
+
}, _callee, null, [[7, 21]]);
|
|
238
|
+
}));
|
|
239
|
+
return function customRequest(_x) {
|
|
240
|
+
return _ref.apply(this, arguments);
|
|
241
|
+
};
|
|
242
|
+
}();
|
|
243
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Upload, {
|
|
244
|
+
customRequest: customRequest,
|
|
245
|
+
headers: {
|
|
246
|
+
'Authorization': 'Bearer ' + token
|
|
247
|
+
},
|
|
248
|
+
maxSize: maxSize || 10 * 1024,
|
|
249
|
+
limit: limit || 1,
|
|
250
|
+
multiple: (limit || 1) > 1,
|
|
251
|
+
onExceed: function onExceed() {
|
|
252
|
+
return Toast.warning("\u5355\u6B21\u4EC5\u652F\u6301\u4E0A\u4F20".concat(limit || 1, "\u4E2A\u6587\u4EF6"));
|
|
253
|
+
},
|
|
254
|
+
onSizeError: function onSizeError() {
|
|
255
|
+
return Toast.warning("\u6587\u4EF6\u5927\u5C0F\u8D85\u51FA\u9650\u5236");
|
|
256
|
+
},
|
|
257
|
+
onAcceptInvalid: function onAcceptInvalid() {
|
|
258
|
+
return Toast.warning("\u4E0D\u652F\u6301\u8BE5\u6587\u4EF6\u7C7B\u578B");
|
|
259
|
+
},
|
|
260
|
+
accept: (accept === null || accept === void 0 ? void 0 : accept.join(',')) || defaultFileLimit,
|
|
261
|
+
fileList: transformFileItem(fileList || []),
|
|
262
|
+
disabled: disabled,
|
|
263
|
+
showUploadList: false,
|
|
264
|
+
onChange: onChange
|
|
265
|
+
}, children || defailtTrigger));
|
|
266
|
+
});
|
|
267
|
+
export default FileUpload;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IProps {
|
|
3
|
+
show: boolean;
|
|
4
|
+
handleClose: () => void;
|
|
5
|
+
isOverFlow?: boolean;
|
|
6
|
+
render?: () => JSX.Element;
|
|
7
|
+
children?: JSX.Element;
|
|
8
|
+
title: string;
|
|
9
|
+
}
|
|
10
|
+
export interface GimiSideBarHandle {
|
|
11
|
+
sideBarRef: React.RefObject<HTMLDivElement | null>;
|
|
12
|
+
}
|
|
13
|
+
declare const GimiSideBar: React.ForwardRefExoticComponent<IProps & {
|
|
14
|
+
className?: string | undefined;
|
|
15
|
+
style?: React.CSSProperties | undefined;
|
|
16
|
+
} & React.RefAttributes<GimiSideBarHandle>>;
|
|
17
|
+
export default GimiSideBar;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import classNames from "classnames";
|
|
2
|
+
import styles from "./index.module.css";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { IconClose } from "@douyinfe/semi-icons";
|
|
5
|
+
import { Button } from "@douyinfe/semi-ui";
|
|
6
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
7
|
+
var GimiSideBar = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
8
|
+
var show = _ref.show,
|
|
9
|
+
handleClose = _ref.handleClose,
|
|
10
|
+
_ref$isOverFlow = _ref.isOverFlow,
|
|
11
|
+
isOverFlow = _ref$isOverFlow === void 0 ? false : _ref$isOverFlow,
|
|
12
|
+
render = _ref.render,
|
|
13
|
+
children = _ref.children,
|
|
14
|
+
title = _ref.title,
|
|
15
|
+
className = _ref.className,
|
|
16
|
+
style = _ref.style;
|
|
17
|
+
var sideBarRef = useRef(null);
|
|
18
|
+
var contentRef = useRef(null);
|
|
19
|
+
useImperativeHandle(ref, function () {
|
|
20
|
+
return {
|
|
21
|
+
sideBarRef: sideBarRef,
|
|
22
|
+
contentRef: contentRef
|
|
23
|
+
};
|
|
24
|
+
}, [sideBarRef]);
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
className: classNames(show ? isOverFlow ? styles.overflow_layout : styles.main : styles.closed, className),
|
|
27
|
+
ref: sideBarRef,
|
|
28
|
+
style: style
|
|
29
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
30
|
+
className: styles.header
|
|
31
|
+
}, /*#__PURE__*/React.createElement("span", null, title), /*#__PURE__*/React.createElement(Button, {
|
|
32
|
+
size: "small",
|
|
33
|
+
theme: "borderless",
|
|
34
|
+
icon: /*#__PURE__*/React.createElement(IconClose, null),
|
|
35
|
+
onClick: handleClose
|
|
36
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
37
|
+
className: styles.content,
|
|
38
|
+
ref: contentRef
|
|
39
|
+
}, render === null || render === void 0 ? void 0 : render(), children));
|
|
40
|
+
});
|
|
41
|
+
export default GimiSideBar;
|