From e548668ccef8c41d9ac7d9fe39ffe66471d160d2 Mon Sep 17 00:00:00 2001 From: kailong321200875 <321200875@qq.com> Date: Sun, 25 Jun 2023 09:20:32 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96Search=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Search/index.ts | 5 + src/components/Search/src/Search.vue | 104 +++++++----------- .../Search/src/components/ActiconButton.vue | 52 +++++++++ src/views/Components/Search.vue | 2 +- 4 files changed, 100 insertions(+), 63 deletions(-) create mode 100644 src/components/Search/src/components/ActiconButton.vue diff --git a/src/components/Search/index.ts b/src/components/Search/index.ts index fcc6f16..6346ffa 100644 --- a/src/components/Search/index.ts +++ b/src/components/Search/index.ts @@ -1,3 +1,8 @@ import Search from './src/Search.vue' +import { ElForm } from 'element-plus' + +export interface SearchExpose { + getElFormExpose: () => Promise> +} export { Search } diff --git a/src/components/Search/src/Search.vue b/src/components/Search/src/Search.vue index 8d1d77d..c05eab5 100644 --- a/src/components/Search/src/Search.vue +++ b/src/components/Search/src/Search.vue @@ -2,17 +2,14 @@ import { Form, FormSchema } from '@/components/Form' import { PropType, computed, unref, ref, watch, onMounted } from 'vue' import { propTypes } from '@/utils/propTypes' -import { ElButton } from 'element-plus' -import { useI18n } from '@/hooks/web/useI18n' import { useForm } from '@/hooks/web/useForm' -import { useIcon } from '@/hooks/web/useIcon' import { findIndex } from '@/utils' import { cloneDeep } from 'lodash-es' import { initModel } from '@/components/Form/src/helper' - -const { t } = useI18n() +import ActionButton from './components/ActiconButton.vue' const formExpose = ref>() +const searchRef = ref() const props = defineProps({ // 生成Form的布局结构数组 @@ -33,7 +30,7 @@ const props = defineProps({ showSearch: propTypes.bool.def(true), showReset: propTypes.bool.def(true), // 是否显示伸缩 - expand: propTypes.bool.def(false), + showExpand: propTypes.bool.def(false), // 伸缩的界限字段 expandField: propTypes.string.def(''), inline: propTypes.bool.def(true), @@ -54,7 +51,7 @@ const formModel = ref({}) const newSchema = computed(() => { let schema: FormSchema[] = cloneDeep(props.schema) - if (props.expand && props.expandField && !unref(visible)) { + if (props.showExpand && props.expandField && !unref(visible)) { const index = findIndex(schema, (v: FormSchema) => v.field === props.expandField) schema.map((v, i) => { if (i >= index) { @@ -75,27 +72,15 @@ const newSchema = computed(() => { default: () => { return (
- {props.showSearch ? ( - - {t('common.query')} - - ) : null} - {props.showReset ? ( - - {t('common.reset')} - - ) : null} - {props.expand ? ( - - {t(visible.value ? 'common.shrink' : 'common.expand')} - - ) : null} +
) } @@ -164,42 +149,37 @@ onMounted(async () => { const elFormExpose = await getElFormExpose() emit('register', formExpose, elFormExpose) }) + +defineExpose({ + getElFormExpose +}) diff --git a/src/components/Search/src/components/ActiconButton.vue b/src/components/Search/src/components/ActiconButton.vue new file mode 100644 index 0000000..d03bfad --- /dev/null +++ b/src/components/Search/src/components/ActiconButton.vue @@ -0,0 +1,52 @@ + + + diff --git a/src/views/Components/Search.vue b/src/views/Components/Search.vue index 55e3265..4f1f40d 100644 --- a/src/views/Components/Search.vue +++ b/src/views/Components/Search.vue @@ -199,7 +199,7 @@ const handleSearch = (data: any) => { :is-col="isGrid" :layout="layout" :button-position="buttonPosition" - expand + show-expand expand-field="field6" @search="handleSearch" @reset="handleSearch"