From d12c0c42072452de4c99ef55c5915edb108dd2ef Mon Sep 17 00:00:00 2001
From: weifs <605403358@qq.com>
Date: Tue, 19 Mar 2024 14:38:15 +0800
Subject: [PATCH] =?UTF-8?q?perf:=201.=20=E5=BC=BA=E5=8C=96=E6=8E=A5?=
=?UTF-8?q?=E9=BE=99=E6=8E=A5=E5=8F=A3=E6=9C=AC=E5=9C=B0=E6=97=B6=E9=97=B4?=
=?UTF-8?q?=E6=88=B3=E9=97=AE=E9=A2=98=20=20=202.=20=E6=8E=A5=E9=BE=99?=
=?UTF-8?q?=E6=B6=88=E6=81=AF=E7=82=B9=E5=B1=95=E5=BC=80=E6=8C=89=E9=92=AE?=
=?UTF-8?q?=E5=90=8E=E5=81=9A=E7=BC=93=E5=AD=98=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Http/Controllers/Api/DialogController.php | 31 +++++++++++++------
.../js/pages/manage/components/DialogView.vue | 19 +++++++++---
.../pages/manage/components/DialogWrapper.vue | 1 +
3 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php
index b11c53daf..bceb061aa 100755
--- a/app/Http/Controllers/Api/DialogController.php
+++ b/app/Http/Controllers/Api/DialogController.php
@@ -2175,12 +2175,12 @@ class DialogController extends AbstractController
$dialog_id = intval(Request::input('dialog_id'));
$uuid = trim(Request::input('uuid'));
$text = trim(Request::input('text'));
- $list = Request::input('list');
+ $list = Request::input('list') ?? [];
//
WebSocketDialog::checkDialog($dialog_id);
$strlen = mb_strlen($text);
$noimglen = mb_strlen(preg_replace("/]*?>/i", "", $text));
- if ($strlen < 1) {
+ if ($strlen < 1 || empty($list)) {
return Base::retError('内容不能为空');
}
if ($noimglen > 200000) {
@@ -2195,17 +2195,28 @@ class DialogController extends AbstractController
->orderByDesc('created_at')
->where('msg', 'like', "%$uuid%")
->value('msg');
- $list = array_reverse(array_merge($dialogMsg['list'] ?? [], $list));
- $list = array_reduce($list, function ($result, $item) {
- $fieldValue = $item['id']; // 指定字段名
- if (!isset($result[$fieldValue])) {
- $result[$fieldValue] = $item;
+ // 新增
+ $msgList = $dialogMsg['list'] ?? [];
+ $addList = array_udiff($list, $msgList, function($a, $b) {
+ return ($a['id'] ?? 0) - $b['id'];
+ });
+ foreach ($addList as $key => $item) {
+ $item['id'] = intval(round(microtime(true) * 1000)) + $key;
+ $msgList[] = $item;
+ }
+ // 编辑更新
+ $lists = array_column($list,null,'id');
+ foreach ($msgList as $key => $item) {
+ if (isset($lists[$item['id']]) && $item['userid'] == $user->userid) {
+ $msgList[$key] = $lists[$item['id']];
}
- return $result;
- }, []);
- $list = array_reverse(array_values($list));
+ }
+ $list = $msgList;
} else {
$uuid = Base::generatePassword(36);
+ foreach ($list as $key => $item) {
+ $list[$key]['id'] = intval(round(microtime(true) * 1000)) + $key;
+ }
}
//
usort($list, function ($a, $b) {
diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue
index f2f3e2c71..37f5a1846 100644
--- a/resources/assets/js/pages/manage/components/DialogView.vue
+++ b/resources/assets/js/pages/manage/components/DialogView.vue
@@ -76,12 +76,12 @@