From 69142425dfca38704a79a752b626b32631213865 Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Tue, 17 Jan 2023 14:08:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0Search=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Search/Item.vue | 3 +- src/components/Search/search.md | 107 ++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/components/Search/search.md diff --git a/src/components/Search/Item.vue b/src/components/Search/Item.vue index 476ddf6e..3a22536d 100644 --- a/src/components/Search/Item.vue +++ b/src/components/Search/Item.vue @@ -142,7 +142,7 @@ const emit = defineEmits() const termsModel = reactive({ type: 'or', value: '', - termType: 'eq', + termType: 'like', column: '' }) @@ -166,6 +166,7 @@ const getTermType = (type?: ItemType) => { switch (type) { case 'select': case 'treeSelect': + case 'number': return 'eq' case 'date': case 'time': diff --git a/src/components/Search/search.md b/src/components/Search/search.md new file mode 100644 index 00000000..6248739f --- /dev/null +++ b/src/components/Search/search.md @@ -0,0 +1,107 @@ +# Search组件 + +- 需要结合Table使用 + +## 属性 + +| 名称 | 说明 | 类型 | 默认值 | +| --- | --- | --- | --- | +| columns | 查询下拉列表 | JColumnsProps[] | [] | +| type | 查询模式 | 'advanced', 'simple' | 'advanced' | +| target | 查询组件唯一key | String | | +| search | 查询回调事件 | Function | | + +> JColumnsProps[*].search + +| 名称 | 说明 | 类型 | 默认值 | +| --- | --- | --- | --- | +| rename | 用来重命名查询字段值 | String | | +| type | 查询值组件类型 | 'select', 'number', 'string', 'treeSelect', 'date', 'time' | | +| options | Select和TreeSelect组件下拉值 | Array, Promise | | +| first | 控制查询字段下拉默认值,默认为name即名称 | Boolean | | +| defaultTermType | 查询条件 | String | | +| handleValue | 处理单个查询value值 | Function | | + +## 基础用法 + +> columns中包含search属性才会出现在查询下拉中 + +```vue + const columns = [ + { + title: '名称', + dataIndex: 'name', + key: 'name', + search: { + type: 'string', + } + } + ] + const search = (params) => { +} + +``` + +> rename的作用在于search抛出params会根据rename修改数据中column的值 + +```vue + const columns = [ + { + title: '名称', + dataIndex: 'name', + key: 'name', + search: { + type: 'string', + rename: 'TestName' + } + } + ] + const search = (params) => { + terms: [ + { + column: 'TestName', + value: '', + termType: 'like' + } + ] + } + +``` + +> defaultTermType的作用在于设置查询条件,相关条件参考util中的termType + +```vue + const columns = [ + { + title: '名称', + dataIndex: 'name', + key: 'name', + search: { + type: 'string', + defaultTermType: 'gt' + } + } + ] + const search = (params) => { + terms: [ + { + column: 'TestName', + value: '', + termType: 'gt' + } + ] + } + +``` From 5779115050e918197528cc1f3039b9ecb360323a Mon Sep 17 00:00:00 2001 From: 100011797 <2642441182@qq.com> Date: Tue, 17 Jan 2023 14:32:47 +0800 Subject: [PATCH 2/3] feat: FILE_UPLOAD --- src/api/comm.ts | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/api/comm.ts diff --git a/src/api/comm.ts b/src/api/comm.ts new file mode 100644 index 00000000..8e987884 --- /dev/null +++ b/src/api/comm.ts @@ -0,0 +1,3 @@ +import { BASE_API_PATH } from "@/utils/variable"; + +export const FILE_UPLOAD = `${BASE_API_PATH}/file/static`; 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 3/3] =?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' /** * 静态图片资源处理