perf: 支持取消发送中的消息

This commit is contained in:
kuaifan 2024-03-19 15:57:07 +09:00
parent 915a5ed7d5
commit 99dca06d44
6 changed files with 187 additions and 90 deletions

View File

@ -55,7 +55,7 @@
"stylus-loader": "^7.1.0", "stylus-loader": "^7.1.0",
"tinymce": "^5.10.3", "tinymce": "^5.10.3",
"tui-calendar-hi": "^1.15.1-5", "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": "^2.9.15",
"vite-plugin-file-copy": "^1.0.0", "vite-plugin-file-copy": "^1.0.0",
"vite-plugin-require": "^1.1.10", "vite-plugin-require": "^1.1.10",

View File

@ -1970,9 +1970,14 @@ const localforage = require("localforage");
if (typeof params.success === 'undefined') params.success = () => { }; if (typeof params.success === 'undefined') params.success = () => { };
if (typeof params.error === 'undefined') params.error = () => { }; if (typeof params.error === 'undefined') params.error = () => { };
if (typeof params.header == 'undefined') params.header = {}; if (typeof params.header == 'undefined') params.header = {};
const key = $A.randomString(16);
// //
params.before(); params.before();
$A.ihttp({ $A.__ajaxList.push({
key,
id: params.requestId || null,
url: params.url,
request: $A.ihttp({
url: params.url, url: params.url,
data: params.data, data: params.data,
cache: params.cache, cache: params.cache,
@ -1983,17 +1988,39 @@ const localforage = require("localforage");
dataType: params.dataType, dataType: params.dataType,
timeout: params.timeout, timeout: params.timeout,
success: function (data, status, xhr) { success: function (data, status, xhr) {
$A.__ajaxList = $A.__ajaxList.filter(val => val.key !== key);
params.complete(); params.complete();
params.success(data, status, xhr); params.success(data, status, xhr);
params.after(true); params.after(true);
}, },
error: function (xhr, status) { error: function (xhr, status) {
$A.__ajaxList = $A.__ajaxList.filter(val => val.key !== key);
params.complete(); params.complete();
params.error(xhr, status); params.error(xhr, status);
params.after(false); 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 = $; window.$A = $;

View File

@ -187,6 +187,11 @@ export default {
//file //file
this.$refs.upload.upload(file); this.$refs.upload.upload(file);
}, },
cancel(uid) {
//
return this.$refs.upload.cancel(uid);
}
} }
} }
</script> </script>

View File

@ -437,9 +437,6 @@ export default {
methods: { methods: {
handleLongpress(event, el) { handleLongpress(event, el) {
if (!this.msgData.created_at) {
return;
}
this.$emit("on-longpress", {event, el, msgData: this.msgData}) this.$emit("on-longpress", {event, el, msgData: this.msgData})
}, },
@ -515,7 +512,7 @@ export default {
fileStyle(percentage) { fileStyle(percentage) {
if (percentage) { if (percentage) {
return { return {
width: (100 - percentage) + '%' width: `${percentage}%`
}; };
} }
return {}; return {};

View File

@ -273,6 +273,17 @@
transfer> transfer>
<div :style="{userSelect:operateVisible ? 'none' : 'auto', height: operateStyles.height}"></div> <div :style="{userSelect:operateVisible ? 'none' : 'auto', height: operateStyles.height}"></div>
<DropdownMenu slot="list"> <DropdownMenu slot="list">
<template v-if="!operateItem.created_at">
<DropdownItem name="action">
<ul class="operate-action cancel">
<li @click="onOperate('cancel')">
<i class="taskfont">&#xe6eb;</i>
<span>{{ $L('取消发送') }}</span>
</li>
</ul>
</DropdownItem>
</template>
<template v-else>
<DropdownItem name="action"> <DropdownItem name="action">
<ul class="operate-action"> <ul class="operate-action">
<li v-if="msgId === 0" @click="onOperate('reply')"> <li v-if="msgId === 0" @click="onOperate('reply')">
@ -341,6 +352,7 @@
</li> </li>
</ul> </ul>
</DropdownItem> </DropdownItem>
</template>
</DropdownMenu> </DropdownMenu>
</Dropdown> </Dropdown>
</div> </div>
@ -1493,6 +1505,7 @@ export default {
this.$nextTick(this.onToBottom) this.$nextTick(this.onToBottom)
// //
this.$store.dispatch("call", { this.$store.dispatch("call", {
requestId: tempMsg.id,
url: 'dialog/msg/sendtext', url: 'dialog/msg/sendtext',
data: { data: {
dialog_id: tempMsg.dialog_id, dialog_id: tempMsg.dialog_id,
@ -1536,6 +1549,7 @@ export default {
this.$nextTick(this.onToBottom) this.$nextTick(this.onToBottom)
// //
this.$store.dispatch("call", { this.$store.dispatch("call", {
requestId: tempMsg.id,
url: 'dialog/msg/sendrecord', url: 'dialog/msg/sendrecord',
data: Object.assign(msg, { data: Object.assign(msg, {
dialog_id: this.dialogId, dialog_id: this.dialogId,
@ -1992,6 +2006,7 @@ export default {
} }
const tempMsg = { const tempMsg = {
id: file.tempId, id: file.tempId,
file_uid: file.uid,
dialog_id: this.dialogData.id, dialog_id: this.dialogData.id,
reply_id: this.quoteId, reply_id: this.quoteId,
type: 'file', type: 'file',
@ -2772,6 +2787,10 @@ export default {
this.operateVisible = false; this.operateVisible = false;
this.$nextTick(_ => { this.$nextTick(_ => {
switch (action) { switch (action) {
case "cancel":
this.onCancelSend()
break;
case "reply": case "reply":
this.onReply() this.onReply()
break; 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) { onReply(type) {
this.setQuote(this.operateItem.id, type) this.setQuote(this.operateItem.id, type)
this.inputFocus() this.inputFocus()

View File

@ -325,6 +325,22 @@ export default {
}) })
}, },
/**
* 取消请求
* @param state
* @param requestId
* @returns {Promise<unknown>}
*/
callCancel({state}, requestId) {
return new Promise((resolve, reject) => {
if ($A.ajaxcCancel(requestId)) {
resolve()
} else {
reject()
}
})
},
/** /**
* 获取系统设置 * 获取系统设置
* @param dispatch * @param dispatch