From 99dca06d44cc2d4e426e3455cd44e7efd305936d Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 19 Mar 2024 15:57:07 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=94=AF=E6=8C=81=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=8F=91=E9=80=81=E4=B8=AD=E7=9A=84=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- resources/assets/js/functions/common.js | 65 +++++-- .../pages/manage/components/DialogUpload.vue | 5 + .../js/pages/manage/components/DialogView.vue | 5 +- .../pages/manage/components/DialogWrapper.vue | 184 +++++++++++------- resources/assets/js/store/actions.js | 16 ++ 6 files changed, 187 insertions(+), 90 deletions(-) diff --git a/package.json b/package.json index 4d75a1f34..b238ac955 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "stylus-loader": "^7.1.0", "tinymce": "^5.10.3", "tui-calendar-hi": "^1.15.1-5", - "view-design-hi": "^4.7.0-49", + "view-design-hi": "^4.7.0-50", "vite": "^2.9.15", "vite-plugin-file-copy": "^1.0.0", "vite-plugin-require": "^1.1.10", diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index c50f30c14..972f26f13 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -1970,30 +1970,57 @@ const localforage = require("localforage"); if (typeof params.success === 'undefined') params.success = () => { }; if (typeof params.error === 'undefined') params.error = () => { }; if (typeof params.header == 'undefined') params.header = {}; + const key = $A.randomString(16); // params.before(); - $A.ihttp({ + $A.__ajaxList.push({ + key, + id: params.requestId || null, url: params.url, - data: params.data, - cache: params.cache, - headers: params.header, - method: params.method.toUpperCase(), - contentType: "OPTIONS", - crossDomain: true, - dataType: params.dataType, - timeout: params.timeout, - success: function (data, status, xhr) { - params.complete(); - params.success(data, status, xhr); - params.after(true); - }, - error: function (xhr, status) { - params.complete(); - params.error(xhr, status); - params.after(false); + request: $A.ihttp({ + url: params.url, + data: params.data, + cache: params.cache, + headers: params.header, + method: params.method.toUpperCase(), + contentType: "OPTIONS", + crossDomain: true, + dataType: params.dataType, + timeout: params.timeout, + success: function (data, status, xhr) { + $A.__ajaxList = $A.__ajaxList.filter(val => val.key !== key); + params.complete(); + params.success(data, status, xhr); + params.after(true); + }, + error: function (xhr, status) { + $A.__ajaxList = $A.__ajaxList.filter(val => val.key !== key); + params.complete(); + params.error(xhr, status); + params.after(false); + } + }) + }); + }, + ajaxcCancel(requestId) { + if (!requestId) { + return 0; + } + let num = 0; + $A.__ajaxList.forEach((val, index) => { + if (val.id === requestId) { + num++; + if (val.request) { + val.request.abort(); + } } }); - } + if (num > 0) { + $A.__ajaxList = $A.__ajaxList.filter(val => val.id !== requestId); + } + return num; + }, + __ajaxList: [], }); window.$A = $; diff --git a/resources/assets/js/pages/manage/components/DialogUpload.vue b/resources/assets/js/pages/manage/components/DialogUpload.vue index 61c7a414c..9de894b81 100644 --- a/resources/assets/js/pages/manage/components/DialogUpload.vue +++ b/resources/assets/js/pages/manage/components/DialogUpload.vue @@ -187,6 +187,11 @@ export default { //手动传file this.$refs.upload.upload(file); }, + + cancel(uid) { + //取消上传 + return this.$refs.upload.cancel(uid); + } } } diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index f2f3e2c71..18145453d 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -437,9 +437,6 @@ export default { methods: { handleLongpress(event, el) { - if (!this.msgData.created_at) { - return; - } this.$emit("on-longpress", {event, el, msgData: this.msgData}) }, @@ -515,7 +512,7 @@ export default { fileStyle(percentage) { if (percentage) { return { - width: (100 - percentage) + '%' + width: `${percentage}%` }; } return {}; diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 1c5be3ce8..8fb6a7856 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -273,74 +273,86 @@ transfer>
- -
    -
  • - - {{ $L('回复') }} -
  • -
  • - - {{ $L('编辑') }} -
  • -
  • - - {{ $L(item.label) }} -
  • -
  • - - {{ $L('转发') }} -
  • -
  • - - {{ $L('撤回') }} -
  • - @@ -1493,6 +1505,7 @@ export default { this.$nextTick(this.onToBottom) // this.$store.dispatch("call", { + requestId: tempMsg.id, url: 'dialog/msg/sendtext', data: { dialog_id: tempMsg.dialog_id, @@ -1536,6 +1549,7 @@ export default { this.$nextTick(this.onToBottom) // this.$store.dispatch("call", { + requestId: tempMsg.id, url: 'dialog/msg/sendrecord', data: Object.assign(msg, { dialog_id: this.dialogId, @@ -1992,6 +2006,7 @@ export default { } const tempMsg = { id: file.tempId, + file_uid: file.uid, dialog_id: this.dialogData.id, reply_id: this.quoteId, type: 'file', @@ -2772,6 +2787,10 @@ export default { this.operateVisible = false; this.$nextTick(_ => { switch (action) { + case "cancel": + this.onCancelSend() + break; + case "reply": this.onReply() break; @@ -2833,6 +2852,39 @@ export default { }) }, + onCancelSend() { + $A.modalConfirm({ + title: '取消发送', + content: '你确定要取消发送吗?', + loading: true, + onOk: () => { + return new Promise((resolve, reject) => { + if (this.operateItem.created_at) { + reject("消息已发送,不可取消"); + return + } + if (this.operateItem.type === 'file') { + // 取消文件上传 + if (this.$refs.chatUpload.cancel(this.operateItem.file_uid)) { + this.forgetTempMsg(this.operateItem.id) + resolve(); + } else { + reject("取消失败"); + } + } else { + // 取消消息发送 + this.$store.dispatch('callCancel', this.operateItem.id).then(() => { + this.forgetTempMsg(this.operateItem.id) + resolve(); + }).catch(() => { + reject("取消失败"); + }); + } + }) + } + }); + }, + onReply(type) { this.setQuote(this.operateItem.id, type) this.inputFocus() diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 1134e6185..0b215589b 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -325,6 +325,22 @@ export default { }) }, + /** + * 取消请求 + * @param state + * @param requestId + * @returns {Promise} + */ + callCancel({state}, requestId) { + return new Promise((resolve, reject) => { + if ($A.ajaxcCancel(requestId)) { + resolve() + } else { + reject() + } + }) + }, + /** * 获取系统设置 * @param dispatch