From bc25f5dfdf9b81db11800e77efc320d9f33e1d1f Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 13 Mar 2024 10:58:46 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Module/Base.php | 19 +++-- .../pages/manage/components/DialogUpload.vue | 70 +++++++++++++++++++ .../js/pages/manage/components/DialogView.vue | 9 +++ .../pages/manage/components/DialogWrapper.vue | 6 +- 4 files changed, 94 insertions(+), 10 deletions(-) diff --git a/app/Module/Base.php b/app/Module/Base.php index 03055c645..8bb3520e1 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2473,13 +2473,18 @@ class Base */ public static function extIcon($ext) { - return match ($ext) { - "docx" => 'images/ext/doc.png', - "xlsx" => 'images/ext/xls.png', - "pptx" => 'images/ext/ppt.png', - "ai", "avi", "bmp", "cdr", "doc", "eps", "gif", "mov", "mp3", "mp4", "pdf", "ppt", "pr", "psd", "rar", "svg", "tif", "txt", "xls", "zip" => 'images/ext/' . $ext . '.png', - default => 'images/ext/file.png', - }; + if ($ext == "docx") { + $ext = 'doc'; + } elseif ($ext == "xlsx") { + $ext = 'xls'; + } elseif ($ext == "pptx") { + $ext = 'ppt'; + } + if (in_array($ext, ["ai", "avi", "bmp", "cdr", "doc", "eps", "gif", "mov", "mp3", "mp4", "pdf", "ppt", "pr", "psd", "rar", "svg", "tif", "txt", "xls", "zip"])) { + return 'images/ext/' . $ext . '.png'; + } else { + return 'images/ext/file.png'; + } } /** diff --git a/resources/assets/js/pages/manage/components/DialogUpload.vue b/resources/assets/js/pages/manage/components/DialogUpload.vue index bef066a71..cf935f3e3 100644 --- a/resources/assets/js/pages/manage/components/DialogUpload.vue +++ b/resources/assets/js/pages/manage/components/DialogUpload.vue @@ -9,6 +9,7 @@ :format="uploadFormat" :show-upload-list="false" :max-size="maxSize" + :before-upload="handleBeforeUpload" :on-progress="handleProgress" :on-success="handleSuccess" :on-format-error="handleFormatError" @@ -34,6 +35,7 @@ export default { data() { return { + fileMsgCaches: {}, // 文件信息缓存 uploadFormat: [], // 不限制上传文件类型 actionUrl: $A.apiUrl('dialog/msg/sendfile'), } @@ -62,6 +64,67 @@ export default { }, methods: { + fileMsgName(file) { + return `${file.name}::${file.size}` + }, + + fileMsgData(file, data = undefined) { + const cacheName = this.fileMsgName(file) + if ($A.isJson(data)) { + this.fileMsgCaches[cacheName] = Object.assign(this.fileMsgCaches[cacheName] || {}, data) + return + } + data = { + type: 'file', + thumb: null, + width: -1, + height: -1, + name: file.name, + size: file.size, + ext: file.name.split('.').pop(), + } + let {ext} = data + if (ext === 'docx') { + ext = 'doc' + } else if (ext === 'xlsx') { + ext = 'xls' + } else if (ext === 'pptx') { + ext = 'ppt' + } + if (["ai", "avi", "bmp", "cdr", "doc", "eps", "gif", "mov", "mp3", "mp4", "pdf", "ppt", "pr", "psd", "rar", "svg", "tif", "txt", "xls", "zip"].includes(ext)) { + data.thumb = $A.apiUrl(`../images/ext/${ext}.png`) + } else { + data.thumb = $A.apiUrl(`../images/ext/file.png`) + } + this.fileMsgCaches[cacheName] = data + }, + + handleBeforeUpload(file) { + //上传前 + return new Promise((resolve) => { + this.fileMsgData(file) + if (/\.(jpe?g|webp|png|gif)$/i.test(file.name)) { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = ({target}) => { + const image = new Image(); + image.onload = () => { + this.fileMsgData(file, { + type: 'img', + thumb: target.result, + width: image.width, + height: image.height, + }) + resolve(); + }; + image.src = target.result; + } + return + } + resolve(); + }); + }, + handleProgress(event, file) { //上传时 if (file.tempId === undefined) { @@ -70,6 +133,13 @@ export default { } else { file.tempId = $A.randNum(1000000000, 9999999999) } + // + file.msg = {} + const msgName = this.fileMsgName(file) + if (this.fileMsgCaches[msgName]) { + file.msg = this.fileMsgCaches[msgName] + delete this.fileMsgCaches[msgName] + } this.$emit('on-progress', file) } }, diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index 2ac26eff8..91b9482f3 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -536,6 +536,9 @@ export default { if (this.operateVisible) { return } + if (!this.msgData.created_at) { + return; + } this.$store.dispatch("audioPlay", this.msgData.msg.path) }, @@ -571,10 +574,16 @@ export default { }, viewFile() { + if (!this.msgData.created_at) { + return; + } this.$emit("on-view-file", this.msgData) }, downFile() { + if (!this.msgData.created_at) { + return; + } this.$emit("on-down-file", this.msgData) }, diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 6b3fff5c6..c8b53d78f 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -1524,7 +1524,7 @@ export default { dialog_id: this.dialogData.id, reply_id: this.quoteId, reply_data: this.quoteData, - type: 'loading', + type: 'record', userid: this.userId, msg, } @@ -1987,9 +1987,9 @@ export default { id: file.tempId, dialog_id: this.dialogData.id, reply_id: this.quoteId, - type: 'loading', + type: 'file', userid: this.userId, - msg: { }, + msg: file.msg || {}, } this.tempMsgs.push(tempMsg) this.msgType = ''