no message

This commit is contained in:
kuaifan 2021-06-14 16:07:13 +08:00
parent 7dfacd93a6
commit 72970eab2d
8 changed files with 100 additions and 24 deletions

View File

@ -2,6 +2,8 @@
namespace App\Http\Controllers\Api;
use App\Models\ProjectTask;
use App\Models\ProjectTaskFile;
use App\Models\User;
use App\Models\WebSocketDialog;
use App\Models\WebSocketDialogMsg;
@ -247,11 +249,36 @@ class DialogController extends AbstractController
if (Base::isError($data)) {
return Base::retError($data['msg']);
} else {
$msg = $data['data'];
$msg['thumb'] = Base::unFillUrl($msg['thumb']);
$msg['size'] *= 1024;
$fileData = $data['data'];
$fileData['thumb'] = Base::unFillUrl($fileData['thumb']);
$fileData['size'] *= 1024;
//
return WebSocketDialogMsg::sendMsg($dialog_id, 'file', $msg, $user->userid, $extra_int, $extra_str);
if ($dialog->type === 'group') {
if ($dialog->group_type === 'task') {
$task = ProjectTask::whereDialogId($dialog->id)->first();
if ($task) {
$file = ProjectTaskFile::createInstance([
'project_id' => $task->project_id,
'task_id' => $task->id,
'name' => $fileData['name'],
'size' => $fileData['size'],
'ext' => $fileData['ext'],
'path' => $fileData['path'],
'thumb' => $fileData['thumb'],
'userid' => $user->userid,
]);
$file->save();
}
}
}
//
$result = WebSocketDialogMsg::sendMsg($dialog_id, 'file', $fileData, $user->userid, $extra_int, $extra_str);
if (Base::isSuccess($result)) {
if (isset($task)) {
$result['data']['task_id'] = $task->id;
}
}
return $result;
}
}

View File

@ -163,7 +163,7 @@ class WebSocketDialogMsg extends AbstractModel
$task = new WebSocketDialogMsgTask($userids, $dialogMsg->toArray());
Task::deliver($task);
//
return Base::retSuccess('发送成功', $dialogMsg);
return Base::retSuccess('发送成功', $dialogMsg->toArray());
});
}

View File

@ -59,6 +59,9 @@ export default {
if (res.ret === 1) {
file.data = res.data;
this.$emit('on-success', file);
if (res.data.task_id) {
this.$store.dispatch("getTaskFiles", res.data.task_id)
}
} else {
$A.modalWarning({
title: '发送失败',

View File

@ -39,6 +39,8 @@
:rows="1"
:autosize="{ minRows: 1, maxRows: 3 }"
:maxlength="255"
@on-focus="onEventFocus"
@on-blur="onEventblur"
@on-keydown="chatKeydown"
@on-input-paste="pasteDrag"
:placeholder="$L('输入消息...')" />
@ -141,13 +143,10 @@ export default {
text: this.msgText,
},
}).then(({data}) => {
this.$store.dispatch("dialogMsgSplice", {id: tempId, data});
this.$store.dispatch("dialogMsgUpdate", {id: tempId, data});
}).catch(({msg}) => {
$A.modalWarning({
title: '发送失败',
content: msg
});
this.$store.dispatch("dialogMsgSplice", {id: tempId});
$A.modalError(msg);
this.$store.dispatch("dialogMsgUpdate", {id: tempId});
});
//
this.msgText = '';
@ -214,11 +213,11 @@ export default {
break;
case 'error':
this.$store.dispatch("dialogMsgSplice", {id: file.tempId});
this.$store.dispatch("dialogMsgUpdate", {id: file.tempId});
break;
case 'success':
this.$store.dispatch("dialogMsgSplice", {id: file.tempId, data: file.data});
this.$store.dispatch("dialogMsgUpdate", {id: file.tempId, data: file.data});
break;
}
},
@ -248,6 +247,14 @@ export default {
this.goBottom();
},
onEventFocus(e) {
this.$emit("on-focus", e)
},
onEventblur(e) {
this.$emit("on-blur", e)
},
formatTime(date) {
let time = Math.round(new Date(date).getTime() / 1000),
string = '';

View File

@ -8,7 +8,7 @@
<Input prefix="ios-search" v-model="dialogKey" :placeholder="$L('搜索...')" clearable />
</div>
</div>
<div class="messenger-list overlay-y">
<div ref="list" class="messenger-list overlay-y">
<ul v-if="tabActive==='dialog'" class="dialog">
<li
v-for="(dialog, key) in dialogLists"
@ -50,7 +50,7 @@
</div>
<div class="messenger-msg">
<DialogWrapper v-if="dialogId > 0"/>
<DialogWrapper v-if="dialogId > 0" @on-focus="scrollIntoActive"/>
<div v-else class="dialog-no">
<div class="dialog-no-icon"><Icon type="ios-chatbubbles" /></div>
<div class="dialog-no-text">{{$L('选择一个会话开始聊天')}}</div>
@ -126,6 +126,7 @@ export default {
openDialog(dialog) {
this.$store.state.method.setStorage("messengerDialogId", dialog.id)
this.$store.dispatch("getDialogMsgList", dialog.id);
this.scrollIntoActive();
},
openDialogStorage() {
@ -211,6 +212,20 @@ export default {
}
return null;
},
scrollIntoActive() {
this.$nextTick(() => {
if (this.$refs.list) {
let active = this.$refs.list.querySelector(".active")
if (active) {
scrollIntoView(active, {
behavior: 'smooth',
scrollMode: 'if-needed',
});
}
}
})
}
}
}
</script>

View File

@ -740,7 +740,7 @@ export default {
dialog_id,
},
}).then(result => {
dispatch("dialogUpdate", result.data);
dispatch("saveDialog", result.data);
});
},
@ -864,12 +864,16 @@ export default {
* @param state
* @param params {id, data}
*/
dialogMsgSplice({state}, params) {
dialogMsgUpdate({state}, params) {
let {id, data} = params;
if (!id) {
return;
}
if (state.method.isJson(data)) {
state.projectDetail.project_column.some(({project_task}) => {
const task = project_task.find(({dialog_id}) => dialog_id === data.dialog_id);
if (task) task.msg_num++;
});
if (data.id && state.dialogMsgList.find(m => m.id == data.id)) {
data = null;
}
@ -998,10 +1002,11 @@ export default {
}
});
if (type === "dialog") {
// 更新消息
// 更新会话
(function (msg) {
const {data} = msg;
const {mode, data} = msg;
const {dialog_id} = data;
// 更新消息列表
if (dialog_id == state.dialogId) {
let index = state.dialogMsgList.findIndex(({id}) => id == data.id);
if (index === -1) {
@ -1010,11 +1015,6 @@ export default {
state.dialogMsgList.splice(index, 1, data);
}
}
})(msgDetail);
// 更新会话
(function (msg) {
const {mode, data} = msg;
const {dialog_id} = data;
// 更新最后消息
let dialog = state.dialogList.find(({id}) => id == dialog_id);
if (dialog) {
@ -1023,6 +1023,7 @@ export default {
dispatch("getDialogOne", dialog_id);
}
if (mode === "add") {
// 更新对话列表
if (dialog) {
// 新增未读数
if (data.userid !== state.userId) dialog.unread++;
@ -1034,6 +1035,11 @@ export default {
state.dialogList.unshift(tmp);
}
}
// 新增任务消息数量
state.projectDetail.project_column.some(({project_task}) => {
const task = project_task.find(({dialog_id}) => dialog_id === data.dialog_id);
if (task) task.msg_num++;
});
// 新增总未读数
if (data.userid !== state.userId) state.dialogMsgUnread++;
}

View File

@ -32,6 +32,23 @@ const method = {
return params;
},
zeroFill(str, length, after) {
str+= "";
if (str.length >= length) {
return str;
}
let _str = '', _ret = '';
for (let i = 0; i < length; i++) {
_str += '0';
}
if (after || typeof after === 'undefined') {
_ret = (_str + "" + str).substr(length * -1);
} else {
_ret = (str + "" + _str).substr(0, length);
}
return _ret;
},
formatDate(format, v) {
if (typeof format === 'undefined' || format === '') {
format = 'Y-m-d H:i:s';

View File

@ -14,6 +14,7 @@
<link rel="stylesheet" type="text/css" href="{{ asset_main('css/iview.css') }}">
<script src="{{ asset_main('js/jquery.min.js') }}"></script>
<script src="{{ asset_main('js/bootstrap.min.js') }}"></script>
<script src="{{ asset_main('js/scroll-into-view.min.js') }}"></script>
<script>
window.csrfToken = { csrfToken : "{{ csrf_token() }}" };
window.webSocketConfig = { URL: "{{ env('LARAVELS_PROXY_URL') }}", DEBUG: {{ env('APP_DEBUG') ? "true" : "false" }}, LISTENER: {} };