From d1b28b233370acd30f2d29dc13fb8d5c395639fb Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Tue, 17 Jan 2023 14:46:38 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=B7=BB=E5=8A=A0Search=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=A4=84=E7=90=86like=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Search/Item.vue | 1 + src/components/Search/Search.vue | 24 +++++++++++++++++++++++- src/utils/comm.ts | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/components/Search/Item.vue b/src/components/Search/Item.vue index 3a22536d..aa82e42f 100644 --- a/src/components/Search/Item.vue +++ b/src/components/Search/Item.vue @@ -222,6 +222,7 @@ const handleItemOptions = (option?: any[] | Function) => { const columnChange = (value: string, isChange: boolean) => { const item = columnOptionMap.get(value) + optionLoading.value = false // 设置value为undefined termsModel.column = value termsModel.termType = item.defaultTermType || getTermType(item.type) diff --git a/src/components/Search/Search.vue b/src/components/Search/Search.vue index ed01c76e..e51edc81 100644 --- a/src/components/Search/Search.vue +++ b/src/components/Search/Search.vue @@ -172,6 +172,23 @@ const addUrlParams = () => { urlParams.target = props.target } +/** + * 处理termType为like,nlike的值 + * @param v + */ +const handleLikeValue = (v: string) => { + let _v = v + return _v.split('').reduce((pre: string, next: string) => { + let _next = next + if (next === '\\') { + _next = '\\\\' + } else if (next === '%') { + _next = '\\%' + } + return pre + _next + }, '') +} + /** * 处理为外部使用 */ @@ -181,7 +198,8 @@ const handleParamsFormat = () => { return { terms: cloneParams.terms.map(item => { if (item.terms) { - item.terms = item.terms.filter(iItem => iItem && iItem.value).map(iItem => { + item.terms = item.terms.filter(iItem => iItem && iItem.value) + .map(iItem => { // 处理handleValue和rename const _item = columnOptionMap.get(iItem.column) if (_item.rename) { @@ -191,6 +209,10 @@ const handleParamsFormat = () => { if (_item.handleValue && isFunction(_item.handleValue)) { iItem.value = _item.handleValue(iItem.value, iItem) } + + if (['like','nlike'].includes(iItem.termType) && !!iItem.value) { + iItem.value = `%${handleLikeValue(iItem.value)}%` + } return iItem }) } diff --git a/src/utils/comm.ts b/src/utils/comm.ts index 310b4d72..a2bb3385 100644 --- a/src/utils/comm.ts +++ b/src/utils/comm.ts @@ -1,4 +1,5 @@ import { TOKEN_KEY } from '@/utils/variable' +import { Terms } from 'components/Search/types' /** * 静态图片资源处理