mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-13 01:28:11 +00:00
perf: 文字发送太长转成文件发送
This commit is contained in:
parent
07a4196ed5
commit
c63fdb04c2
@ -286,26 +286,38 @@ class DialogController extends AbstractController
|
||||
WebSocketDialog::checkDialog($dialog_id);
|
||||
//
|
||||
$text = WebSocketDialogMsg::formatMsg($text, $dialog_id);
|
||||
if (mb_strlen($text) < 1) {
|
||||
$strlen = mb_strlen($text);
|
||||
if ($strlen < 1) {
|
||||
return Base::retError('消息内容不能为空');
|
||||
} elseif (mb_strlen($text) > 20000) {
|
||||
return Base::retError('消息内容最大不能超过20000字');
|
||||
} elseif ($strlen > 200000) {
|
||||
return Base::retError('消息内容最大不能超过200000字');
|
||||
}
|
||||
if (mb_strlen($text) > 2000) {
|
||||
$array = mb_str_split($text, 2000);
|
||||
} else {
|
||||
$array = [$text];
|
||||
}
|
||||
//
|
||||
$list = [];
|
||||
foreach ($array as $item) {
|
||||
$res = WebSocketDialogMsg::sendMsg($dialog_id, 'text', ['text' => $item], $user->userid);
|
||||
if (Base::isSuccess($res)) {
|
||||
$list[] = $res['data'];
|
||||
if ($strlen > 2000) {
|
||||
// 内容过长转成文件发送
|
||||
$path = "uploads/chat/" . date("Ym") . "/" . $dialog_id . "/";
|
||||
Base::makeDir(public_path($path));
|
||||
$path = $path . md5($text) . ".txt";
|
||||
$file = public_path($path);
|
||||
file_put_contents($file, $text);
|
||||
$size = filesize(public_path($path));
|
||||
if (empty($size)) {
|
||||
return Base::retError('消息发送保存失败');
|
||||
}
|
||||
$fileData = [
|
||||
'name' => "LongText-{$strlen}.txt",
|
||||
'size' => $size,
|
||||
'file' => $file,
|
||||
'path' => $path,
|
||||
'url' => Base::fillUrl($path),
|
||||
'thumb' => '',
|
||||
'width' => -1,
|
||||
'height' => -1,
|
||||
'ext' => 'txt',
|
||||
];
|
||||
return WebSocketDialogMsg::sendMsg($dialog_id, 'file', $fileData, $user->userid);
|
||||
}
|
||||
//
|
||||
return Base::retSuccess('发送成功', $list);
|
||||
return WebSocketDialogMsg::sendMsg($dialog_id, 'text', ['text' => $text], $user->userid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -128,7 +128,7 @@
|
||||
v-model="msgText"
|
||||
:dialog-id="dialogId"
|
||||
:emoji-bottom="windowSmall"
|
||||
:maxlength="20000"
|
||||
:maxlength="200000"
|
||||
@on-focus="onEventFocus"
|
||||
@on-blur="onEventBlur"
|
||||
@on-more="onEventMore"
|
||||
@ -368,9 +368,9 @@ export default {
|
||||
if (!this.isReady) {
|
||||
return [];
|
||||
}
|
||||
return $A.cloneJSON(this.dialogMsgs.filter(({dialog_id}) => {
|
||||
return this.dialogMsgs.filter(({dialog_id}) => {
|
||||
return dialog_id == this.dialogId;
|
||||
})).sort((a, b) => {
|
||||
}).sort((a, b) => {
|
||||
return a.id - b.id;
|
||||
});
|
||||
},
|
||||
@ -379,15 +379,18 @@ export default {
|
||||
if (!this.isReady) {
|
||||
return [];
|
||||
}
|
||||
return $A.cloneJSON(this.tempMsgs.filter(({dialog_id}) => {
|
||||
return this.tempMsgs.filter(({dialog_id}) => {
|
||||
return dialog_id == this.dialogId;
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
allMsgList() {
|
||||
const {dialogMsgList, tempMsgList} = this;
|
||||
if (tempMsgList.length > 0) {
|
||||
dialogMsgList.push(...tempMsgList);
|
||||
const array = [];
|
||||
array.push(...dialogMsgList);
|
||||
array.push(...tempMsgList)
|
||||
return array;
|
||||
}
|
||||
return dialogMsgList;
|
||||
},
|
||||
|
||||
@ -404,7 +404,7 @@
|
||||
:task-id="taskId"
|
||||
v-model="msgText"
|
||||
:loading="sendLoad > 0"
|
||||
:maxlength="20000"
|
||||
:maxlength="200000"
|
||||
:placeholder="$L('输入消息...')"
|
||||
@on-more="onEventMore"
|
||||
@on-file="onSelectFile"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user