From c48ea979625ee3ecfd10a717e81726a53890fb7c Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Wed, 22 Feb 2023 16:44:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update:=20=E4=BC=98=E5=8C=96=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=BB=84=E4=BB=B6=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Search/Item.vue | 50 ++-- src/components/Search/Search.vue | 4 +- src/views/rule-engine/Scene/index.vue | 46 +++- src/views/rule-engine/Scene/typings.ts | 307 +++++++++++++++++++++++++ 4 files changed, 384 insertions(+), 23 deletions(-) create mode 100644 src/views/rule-engine/Scene/typings.ts diff --git a/src/components/Search/Item.vue b/src/components/Search/Item.vue index aa82e42f..f2c5b64f 100644 --- a/src/components/Search/Item.vue +++ b/src/components/Search/Item.vue @@ -110,12 +110,19 @@ import { PropType } from 'vue' import type { SearchItemData, SearchProps, Terms } from './types' import { cloneDeep, get, isArray, isFunction } from 'lodash-es' import { filterTreeSelectNode, filterSelectNode } from '@/utils/comm' +import { useUrlSearchParams } from '@vueuse/core' type ItemType = SearchProps['type'] interface Emit { (e: 'change', data: SearchItemData): void } +type UrlParam = { + q: string | null + target: string | null +} + +const urlParams = useUrlSearchParams('hash') const props = defineProps({ columns: { @@ -278,28 +285,31 @@ const valueChange = () => { }) } +const handleQuery = (_params: UrlParam) => { + if (_params.q) { + const path = props.index < 4 ? [0, 'terms', props.index - 1] : [1, 'terms', props.index - 4] + const itemData: SearchItemData = get(props.termsItem.terms, path) + if (itemData) { + termsModel.type = itemData.type + termsModel.column = itemData.column + termsModel.termType = itemData.termType + termsModel.value = itemData.value + const item = columnOptionMap.get(itemData.column) + getComponent(item.type) // 处理Item的组件类型 + + // 处理options 以及 request + if ('options' in item) { + handleItemOptions(item.options) + } + } + } +} + handleItem() -watch( props.termsItem, (newValue) => { - - const path = props.index < 4 ? [0, 'terms', props.index - 1] : [1, 'terms', props.index - 4] - const itemData: SearchItemData = get(newValue.terms, path) - if (itemData) { - termsModel.type = itemData.type - termsModel.column = itemData.column - termsModel.termType = itemData.termType - termsModel.value = itemData.value - const item = columnOptionMap.get(itemData.column) - getComponent(item.type) // 处理Item的组件类型 - - // 处理options 以及 request - if ('options' in item) { - handleItemOptions(item.options) - } - } else { - handleItem() - } -}, { immediate: true, deep: true }) +nextTick(() => { + handleQuery(urlParams) +}) diff --git a/src/components/Search/Search.vue b/src/components/Search/Search.vue index 4abeb789..d6dddadb 100644 --- a/src/components/Search/Search.vue +++ b/src/components/Search/Search.vue @@ -134,7 +134,8 @@ const searchParams = reactive({ const handleItems = () => { searchItems.value = [] columnOptionMap.clear() - props.columns!.forEach((item, index) => { + const cloneColumns = cloneDeep(props.columns) + cloneColumns!.forEach((item, index) => { if (item.search && Object.keys(item.search).length) { columnOptionMap.set(item.dataIndex, item.search) searchItems.value.push({ @@ -231,6 +232,7 @@ const reset = () => { urlParams.q = null urlParams.target = null } + emit('search', terms) } watch(width, (value) => { diff --git a/src/views/rule-engine/Scene/index.vue b/src/views/rule-engine/Scene/index.vue index 45cd28fb..71ae1f6c 100644 --- a/src/views/rule-engine/Scene/index.vue +++ b/src/views/rule-engine/Scene/index.vue @@ -1,15 +1,57 @@ -