From 51efb07c17150d367ff0622661850543d8ffab10 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 21 Nov 2024 18:40:01 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96websocket=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Module/Base.php | 36 +++++++++++++++++++++++++--- resources/assets/js/store/actions.js | 3 --- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/Module/Base.php b/app/Module/Base.php index ba12f6060..057d42862 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -960,21 +960,51 @@ class Base /** * 判断是否二维数组 * @param $array - * @param bool $strict 严格模式,是否每个元素都是数组 + * @param bool $strict 严格模式:要求每个元素都是数组 且 索引连续 * @return bool + * + * // 严格模式测试 + * $arr1 = [[1], [2]]; // true + * $arr2 = ['a' => [1], 'b' => [2]]; // false(非连续数字索引) + * $arr3 = [[1], 2]; // false(含非数组元素) + * $arr4 = [1, 2]; // false(全部非数组元素) + * $arr5 = []; // false(空数组) + * + * // 非严格模式测试 ($strict = false) + * $arr6 = [[1], 2, [3]]; // true(包含数组元素即可) + * $arr7 = ['a' => [1], 'b' => 2]; // true(包含数组元素即可) */ public static function isTwoArray($array, bool $strict = true) { - if (!is_array($array)) { + if (!is_array($array) || empty($array)) { return false; } $count = count(array_filter($array, 'is_array')); if ($strict) { - return $count === count($array); + return $count === count($array) && Base::arrayIsList($array); } return $count > 0; } + /** + * 判断数组是否为 list + * @param array $array + * @return bool + */ + public static function arrayIsList(array $array): bool + { + if ([] === $array || $array === array_values($array)) { + return true; + } + $nextKey = -1; + foreach ($array as $k => $v) { + if ($k !== ++$nextKey) { + return false; + } + } + return true; + } + /** * 检测手机号码格式 * @param string $str 需要检测的字符串 diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 609e3f97a..83465918d 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -3439,9 +3439,6 @@ export default { break; case 'done': - if (data.text) { - Store.set('dialogMsgChange', data); - } const index = state.dialogSseList.findIndex(item => sse === item.sse) if (index > -1) { state.dialogSseList.splice(index, 1)