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