优化回复消息

This commit is contained in:
kuaifan 2022-06-17 10:42:06 +08:00
parent 3728b1d3a0
commit 3cc6a3317e
7 changed files with 111 additions and 37 deletions

View File

@ -222,6 +222,36 @@ class DialogController extends AbstractController
return Base::retSuccess('success', $data);
}
/**
* @api {get} api/dialog/msg/one 05. 获取单个消息
*
* @apiDescription 主要用于获取回复消息的详情需要token身份
* @apiVersion 1.0.0
* @apiGroup dialog
* @apiName msg__one
*
* @apiParam {Number} msg_id 消息ID
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function msg__one()
{
User::auth();
//
$msg_id = intval(Request::input('msg_id'));
//
$dialogMsg = WebSocketDialogMsg::find($msg_id);
if (empty($dialogMsg)) {
return Base::retError('消息不存在或已被删除');
}
//
WebSocketDialog::checkDialog($dialogMsg->dialog_id);
//
return Base::retSuccess('success', $dialogMsg);
}
/**
* @api {get} api/dialog/msg/unread 06. 获取未读消息数量
*

View File

@ -2,9 +2,9 @@
<div class="chat-input-box" :class="boxClass" v-clickoutside="hidePopover">
<div class="chat-input-wrapper" @click.stop="focus">
<!-- 回复 -->
<div v-if="replyItem.id" class="chat-reply">
<UserAvatar :userid="replyItem.userid" :show-icon="false" :show-name="true" :tooltip-disabled="true"/>
<div class="reply-desc">{{formatMsgDesc(replyItem)}}</div>
<div v-if="replyData" class="chat-reply">
<UserAvatar :userid="replyData.userid" :show-icon="false" :show-name="true" :tooltip-disabled="true"/>
<div class="reply-desc">{{formatMsgDesc(replyData)}}</div>
<i class="taskfont" @click.stop="onCancelReply">&#xe6e5;</i>
</div>
@ -186,9 +186,9 @@ export default {
type: String,
default: "top"
},
replyItem: {
type: Object,
default: () => ({})
replyId: {
type: Number,
default: 0
},
},
data() {
@ -277,7 +277,7 @@ export default {
}
},
computed: {
...mapState(['dialogInputCache', 'cacheProjects', 'cacheTasks', 'cacheUserBasic']),
...mapState(['dialogInputCache', 'cacheProjects', 'cacheTasks', 'cacheUserBasic', 'dialogMsgs', 'dialogReplys']),
isEnterSend() {
if (typeof this.enterSend === "boolean") {
@ -346,6 +346,22 @@ export default {
if (minute < 10) minute = `0${minute}`
if (seconds < 10) seconds = `0${seconds}`
return `${minute}:${seconds}${millisecond}`
},
replyData() {
const {replyId} = this;
if (replyId > 0) {
let data = this.dialogMsgs.find(item => item.id === replyId)
if (data) {
return data;
}
data = this.dialogReplys.find(item => item.id === replyId)
if (data) {
return data;
}
this.$store.dispatch("getDialogReply", replyId)
}
return null;
}
},
watch: {

View File

@ -25,7 +25,7 @@ export default {
default: 0
},
replyId: {
type: [Number, String],
type: Number,
default: 0
},
maxSize: {

View File

@ -172,7 +172,7 @@ export default {
},
computed: {
...mapState(['dialogMsgs', 'audioPlaying', 'windowActive']),
...mapState(['dialogMsgs', 'dialogReplys', 'audioPlaying', 'windowActive']),
viewClass() {
const {msgData, replyData, operateAction, operateEnter} = this;
@ -234,7 +234,15 @@ export default {
replyData() {
const {reply_id} = this.msgData;
if (reply_id > 0) {
return this.dialogMsgs.find(item => item.id === reply_id) || null;
let data = this.dialogMsgs.find(item => item.id === reply_id)
if (data) {
return data;
}
data = this.dialogReplys.find(item => item.id === reply_id)
if (data) {
return data;
}
this.$store.dispatch("getDialogReply", reply_id)
}
return null;
}

View File

@ -100,7 +100,7 @@
ref="chatUpload"
class="chat-upload"
:dialog-id="dialogId"
:reply-id="replyItem.id"
:reply-id="replyId"
@on-progress="chatFile('progress', $event)"
@on-success="chatFile('success', $event)"
@on-error="chatFile('error', $event)"/>
@ -108,7 +108,7 @@
ref="input"
v-model="msgText"
:dialog-id="dialogId"
:reply-item="replyItem"
:reply-id="replyId"
:emoji-bottom="windowSmall"
:maxlength="200000"
@on-focus="onEventFocus"
@ -325,7 +325,7 @@ export default {
recordState: '',
wrapperStart: 0,
replyItem: {},
replyId: 0,
}
},
@ -539,7 +539,7 @@ export default {
let tempMsg = {
id: tempId,
dialog_id: this.dialogData.id,
reply_id: this.replyItem.id,
reply_id: this.replyId,
type: 'text',
userid: this.userId,
msg: {
@ -556,7 +556,7 @@ export default {
url: 'dialog/msg/sendtext',
data: {
dialog_id: this.dialogId,
reply_id: this.replyItem.id,
reply_id: this.replyId,
text: msgText,
},
method: 'post'
@ -581,7 +581,7 @@ export default {
this.tempMsgs.push({
id: tempId,
dialog_id: this.dialogData.id,
reply_id: this.replyItem.id,
reply_id: this.replyId,
type: 'loading',
userid: this.userId,
msg,
@ -591,7 +591,7 @@ export default {
url: 'dialog/msg/sendrecord',
data: Object.assign(msg, {
dialog_id: this.dialogId,
reply_id: this.replyItem.id,
reply_id: this.replyId,
}),
method: 'post'
}).then(({data}) => {
@ -707,7 +707,7 @@ export default {
this.tempMsgs.push({
id: file.tempId,
dialog_id: this.dialogData.id,
reply_id: this.replyItem.id,
reply_id: this.replyId,
type: 'loading',
userid: this.userId,
msg: { },
@ -983,12 +983,12 @@ export default {
},
onReply() {
this.replyItem = this.operateItem;
this.replyId = this.operateItem.id;
this.inputFocus()
},
onCancelReply() {
this.replyItem = {};
this.replyId = 0;
},
onWithdraw() {

View File

@ -403,7 +403,7 @@ export default {
saveUserBasic({state}, data) {
$A.execMainDispatch("saveUserBasic", data)
//
let index = state.cacheUserBasic.findIndex(({userid}) => userid == data.userid);
const index = state.cacheUserBasic.findIndex(({userid}) => userid == data.userid);
if (index > -1) {
data = Object.assign({}, state.cacheUserBasic[index], data)
state.cacheUserBasic.splice(index, 1, data);
@ -544,7 +544,7 @@ export default {
});
} else if ($A.isJson(data)) {
let base = {_load: false, _edit: false};
let index = state.files.findIndex(({id}) => id == data.id);
const index = state.files.findIndex(({id}) => id == data.id);
if (index > -1) {
state.files.splice(index, 1, Object.assign(base, state.files[index], data));
} else {
@ -646,7 +646,7 @@ export default {
dispatch("saveColumn", data.project_column)
delete data.project_column;
}
let index = state.cacheProjects.findIndex(({id}) => id == data.id);
const index = state.cacheProjects.findIndex(({id}) => id == data.id);
if (index > -1) {
state.cacheProjects.splice(index, 1, Object.assign({}, state.cacheProjects[index], data));
} else {
@ -684,7 +684,7 @@ export default {
//
let ids = $A.isArray(project_id) ? project_id : [project_id];
ids.some(id => {
let index = state.cacheProjects.findIndex(project => project.id == id);
const index = state.cacheProjects.findIndex(project => project.id == id);
if (index > -1) {
state.cacheProjects.splice(index, 1);
}
@ -874,7 +874,7 @@ export default {
dispatch("saveColumn", column)
});
} else if ($A.isJson(data)) {
let index = state.cacheColumns.findIndex(({id}) => id == data.id);
const index = state.cacheColumns.findIndex(({id}) => id == data.id);
if (index > -1) {
state.cacheColumns.splice(index, 1, Object.assign({}, state.cacheColumns[index], data));
} else {
@ -898,7 +898,7 @@ export default {
let ids = $A.isArray(column_id) ? column_id : [column_id];
let project_ids = [];
ids.some(id => {
let index = state.cacheColumns.findIndex(column => column.id == id);
const index = state.cacheColumns.findIndex(column => column.id == id);
if (index > -1) {
project_ids.push(state.cacheColumns[index].project_id)
dispatch('getProjectOne', state.cacheColumns[index].project_id).catch(() => {})
@ -1026,7 +1026,7 @@ export default {
delete data.update_marking;
}
//
let index = state.cacheTasks.findIndex(({id}) => id == data.id);
const index = state.cacheTasks.findIndex(({id}) => id == data.id);
if (index > -1) {
state.cacheTasks.splice(index, 1, Object.assign({}, state.cacheTasks[index], data));
} else {
@ -1077,7 +1077,7 @@ export default {
let parent_ids = [];
let project_ids = [];
ids.some(id => {
let index = state.cacheTasks.findIndex(task => task.id == id);
const index = state.cacheTasks.findIndex(task => task.id == id);
if (index > -1) {
if (state.cacheTasks[index].parent_id) {
parent_ids.push(state.cacheTasks[index].parent_id)
@ -1448,7 +1448,7 @@ export default {
dispatch("saveTaskContent", item)
});
} else if ($A.isJson(data)) {
let index = state.taskContents.findIndex(({task_id}) => task_id == data.task_id);
const index = state.taskContents.findIndex(({task_id}) => task_id == data.task_id);
if (index > -1) {
state.taskContents.splice(index, 1, Object.assign({}, state.taskContents[index], data));
} else {
@ -1474,7 +1474,7 @@ export default {
},
}).then(result => {
result.data.forEach((data) => {
let index = state.taskFiles.findIndex(({id}) => id == data.id)
const index = state.taskFiles.findIndex(({id}) => id == data.id)
if (index > -1) {
state.taskFiles.splice(index, 1, data)
} else {
@ -1499,7 +1499,7 @@ export default {
forgetTaskFile({state, dispatch}, file_id) {
let ids = $A.isArray(file_id) ? file_id : [file_id];
ids.some(id => {
let index = state.taskFiles.findIndex(file => file.id == id)
const index = state.taskFiles.findIndex(file => file.id == id)
if (index > -1) {
state.taskFiles.splice(index, 1)
}
@ -1789,7 +1789,7 @@ export default {
let task = state.cacheTasks.find(({id}) => id == task_id)
let {data} = result
data.turns.some(item => {
let index = state.taskFlowItems.findIndex(({id}) => id == item.id);
const index = state.taskFlowItems.findIndex(({id}) => id == item.id);
if (index > -1) {
state.taskFlowItems.splice(index, 1, item);
} else {
@ -1808,7 +1808,7 @@ export default {
})
//
delete data.turns;
let index = state.taskFlows.findIndex(({task_id}) => task_id == data.task_id);
const index = state.taskFlows.findIndex(({task_id}) => task_id == data.task_id);
if (index > -1) {
state.taskFlows.splice(index, 1, data);
} else {
@ -1892,7 +1892,7 @@ export default {
* @param task_id
*/
saveTaskBrowse({state}, task_id) {
let index = state.cacheTaskBrowse.findIndex(({id}) => id == task_id)
const index = state.cacheTaskBrowse.findIndex(({id}) => id == task_id)
if (index > -1) {
state.cacheTaskBrowse.splice(index, 1)
}
@ -2088,7 +2088,7 @@ export default {
//
let ids = $A.isArray(dialog_id) ? dialog_id : [dialog_id];
ids.some(id => {
let index = state.cacheDialogs.findIndex(dialog => dialog.id == id);
const index = state.cacheDialogs.findIndex(dialog => dialog.id == id);
if (index > -1) {
state.cacheDialogs.splice(index, 1);
}
@ -2152,7 +2152,7 @@ export default {
dispatch("saveDialogMsg", msg)
});
} else if ($A.isJson(data)) {
let index = state.dialogMsgs.findIndex(({id}) => id == data.id);
const index = state.dialogMsgs.findIndex(({id}) => id == data.id);
if (index > -1) {
state.dialogMsgs.splice(index, 1, Object.assign({}, state.dialogMsgs[index], data));
} else {
@ -2171,7 +2171,7 @@ export default {
//
let ids = $A.isArray(msg_id) ? msg_id : [msg_id];
ids.some(id => {
let index = state.dialogMsgs.findIndex(item => item.id == id);
const index = state.dialogMsgs.findIndex(item => item.id == id);
if (index > -1) {
Store.set('audioSubscribe', id);
state.dialogMsgs.splice(index, 1);
@ -2179,6 +2179,25 @@ export default {
})
},
/**
* 获取回复消息
* @param state
* @param dispatch
* @param msg_id
*/
getDialogReply({state, dispatch}, msg_id) {
dispatch("call", {
url: 'dialog/msg/one',
data: {
msg_id: msg_id,
},
}).then(({data}) => {
state.dialogReplys.push(data)
}).catch(e => {
console.warn(e);
});
},
/**
* 获取会话消息
* @param state

View File

@ -71,6 +71,7 @@ const stateData = {
dialogId: 0,
dialogIns: [],
dialogMsgs: [],
dialogReplys: [],
dialogInputCache: $A.getStorageArray("cacheDialogInput"),
dialogMsgTransfer: {time: 0},