perf: 对话支持拼音搜索

This commit is contained in:
kuaifan 2022-07-19 16:14:44 +08:00
parent 5f50fc7b3b
commit 67e2ec4093
3 changed files with 10 additions and 7 deletions

View File

@ -136,6 +136,7 @@ class WebSocketDialog extends AbstractModel
$this->has_file = $msgBuilder->clone()->whereMtype('file')->exists(); $this->has_file = $msgBuilder->clone()->whereMtype('file')->exists();
$this->has_link = $msgBuilder->clone()->whereLink(1)->exists(); $this->has_link = $msgBuilder->clone()->whereLink(1)->exists();
} }
$this->name_py = Base::cn2pinyin($this->name);
return $this; return $this;
} }

View File

@ -2860,8 +2860,10 @@ class Base
return ''; return '';
} }
if (!preg_match("/^[a-zA-Z0-9_.]+$/", $str)) { if (!preg_match("/^[a-zA-Z0-9_.]+$/", $str)) {
$pinyin = new Pinyin(); $str = Cache::rememberForever("cn2pinyin:" . md5($str), function() use ($str) {
$str = $pinyin->permalink($str, ''); $pinyin = new Pinyin();
return $pinyin->permalink($str, '');
});
} }
return $str; return $str;
} }

View File

@ -227,20 +227,20 @@ export default {
return false; return false;
} }
if (dialogKey) { if (dialogKey) {
const {name, last_msg} = dialog; const {name, name_py, last_msg} = dialog;
let msgKey = ""; let searchString = `${name} ${name_py}`
if (last_msg) { if (last_msg) {
switch (last_msg.type) { switch (last_msg.type) {
case 'text': case 'text':
msgKey = last_msg.msg.text.replace(/<[^>]+>/g,"") searchString += ` ${last_msg.msg.text.replace(/<[^>]+>/g,"")}`
break break
case 'meeting': case 'meeting':
case 'file': case 'file':
msgKey = last_msg.msg.name searchString += ` ${last_msg.msg.name}`
break break
} }
} }
if (!$A.strExists(name, dialogKey) && !$A.strExists(msgKey, dialogKey)) { if (!$A.strExists(searchString, dialogKey)) {
return false; return false;
} }
} else if (dialogActive) { } else if (dialogActive) {