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_link = $msgBuilder->clone()->whereLink(1)->exists();
}
$this->name_py = Base::cn2pinyin($this->name);
return $this;
}

View File

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

View File

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