From 7a191e2c405125b9f5d53e51b71688829de13c5a Mon Sep 17 00:00:00 2001 From: "xinxin.wu" Date: Thu, 28 Sep 2023 12:30:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=85=AC=E5=85=B1):=20=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E7=BB=84=E4=BB=B6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/ms-filter-panel/caseUtils.ts | 15 ++- .../ms-filter-panel/query-form-item.vue | 108 +++++++++++------- .../business/ms-filter-panel/searchForm.vue | 35 +++++- .../business/ms-filter-panel/time-select.vue | 15 ++- .../business/ms-filter-panel/type.ts | 24 +++- .../featureCase/components/caseTable.vue | 6 +- 6 files changed, 143 insertions(+), 60 deletions(-) diff --git a/frontend/src/components/business/ms-filter-panel/caseUtils.ts b/frontend/src/components/business/ms-filter-panel/caseUtils.ts index c42ac22c00..315377dea0 100644 --- a/frontend/src/components/business/ms-filter-panel/caseUtils.ts +++ b/frontend/src/components/business/ms-filter-panel/caseUtils.ts @@ -1,4 +1,5 @@ import { OPERATORS } from './operator'; +import type { SearchKeyType } from './type'; // eslint-disable-next-line no-shadow export enum CaseKeyEnum { @@ -17,7 +18,7 @@ export enum CaseKeyEnum { } // 名称 -export const NAME = { +export const NAME: SearchKeyType = { key: CaseKeyEnum.NAME, // 对应字段key type: 'a-input', // Vue控件名称 label: '显示名称', // 显示名称 @@ -28,7 +29,7 @@ export const NAME = { }; // 标签 -export const TAGS = { +export const TAGS: SearchKeyType = { key: CaseKeyEnum.TAGS, type: 'a-input', label: '标签', @@ -39,7 +40,7 @@ export const TAGS = { }; // 所属模块 -export const MODULE = { +export const MODULE: SearchKeyType = { key: 'module', type: 'a-tree-select', label: '所属模块', @@ -50,23 +51,27 @@ export const MODULE = { }; // 创建时间 -export const CREATE_TIME = { +export const CREATE_TIME: SearchKeyType = { key: CaseKeyEnum.CREATE_TIME, type: 'time-select', // 时间选择器 label: '创建时间', + rules: [{ required: true, message: '请选择创建时间!' }], props: {}, operator: { + value: '', options: [OPERATORS.BETWEEN, OPERATORS.GT, OPERATORS.LT], }, }; // 更新时间 -export const UPDATE_TIME = { +export const UPDATE_TIME: SearchKeyType = { key: CaseKeyEnum.UPDATE_TIME, type: 'time-select', label: '更新时间', + rules: [{ required: true, message: '请选择更新时间!' }], props: {}, operator: { + value: '', options: [OPERATORS.BETWEEN, OPERATORS.GT, OPERATORS.LT], }, }; diff --git a/frontend/src/components/business/ms-filter-panel/query-form-item.vue b/frontend/src/components/business/ms-filter-panel/query-form-item.vue index bdcf6cc543..398ff7660b 100644 --- a/frontend/src/components/business/ms-filter-panel/query-form-item.vue +++ b/frontend/src/components/business/ms-filter-panel/query-form-item.vue @@ -6,11 +6,11 @@ :is="form.searchKey.type" v-bind="form.searchKey.props" v-model="form.searchKey.value" - @change="cate1ChangeHandler" + @change="searchKeyChange" >
- - - - + + + +
@@ -78,6 +89,8 @@ import { TEST_PLAN_TEST_CASE } from './caseUtils'; import TimerSelect from './time-select.vue'; import { SelectOptionData } from '@arco-design/web-vue'; + import type { FormInstance } from '@arco-design/web-vue'; + import type { SearchKeyType } from './type'; const { t } = useI18n(); @@ -93,20 +106,24 @@ const form = ref({ ...cloneDeep(props.formItem) }); watchEffect(() => { - form.value.queryContent.value = props.formItem.queryContent.value; + form.value = { ...cloneDeep(props.formItem) }; }); // 一级属性变化回调 - const cate1ChangeHandler = (value: string) => { + const searchKeyChange = (value: string) => { const { operatorCondition, queryContent } = form.value; operatorCondition.value = ''; operatorCondition.options = []; + queryContent.value = ''; // 获取当前选中查询Key属性的配置项 - const currentKeysConfig = TEST_PLAN_TEST_CASE.find((item) => item.key === value); + const currentKeysConfig = TEST_PLAN_TEST_CASE.find((item: any) => item.key === value); if (currentKeysConfig) { operatorCondition.options = currentKeysConfig.operator.options; operatorCondition.value = currentKeysConfig.operator.options[0].value; queryContent.type = currentKeysConfig.type; + if (currentKeysConfig.rules) { + queryContent.rules = currentKeysConfig.rules; + } } emits('dataUpdated', form.value, props.index); }; @@ -132,17 +149,22 @@ form.value.queryContent.value = time; emits('dataUpdated', form.value, props.index); }; + const queryContentFormRef = ref(); - // 判断当前情况 - const getQueryContentType = (type: string) => { - switch (type) { - // 时间选择面板 - case 'time-select': - return true; - default: - return false; - } + // 校验表单 + const validateQueryContent = (callBack: (isSuccess: string) => void) => { + queryContentFormRef.value?.validate((errors) => { + if (!errors) { + callBack('ok'); + } else { + callBack('no'); + } + }); }; + + defineExpose({ + validateQueryContent, + }); diff --git a/frontend/src/components/business/ms-filter-panel/searchForm.vue b/frontend/src/components/business/ms-filter-panel/searchForm.vue index 891038ec19..7c5382d309 100644 --- a/frontend/src/components/business/ms-filter-panel/searchForm.vue +++ b/frontend/src/components/business/ms-filter-panel/searchForm.vue @@ -15,6 +15,7 @@
{ + debugger; formModels.value.splice(index, 1); }; + // 校验结果列表 + const allValidateResult = ref([]); + + const queryFromRef = ref(); + // 添加查询条件项 - const addField = () => { + const addField = async () => { + allValidateResult.value = []; + // 全部校验通过可进行添加 + await Promise.all( + queryFromRef.value.map((item: any) => { + return new Promise((resolve) => { + item.validateQueryContent(async (isValidated: string) => { + allValidateResult.value.push(isValidated); + resolve(); + }); + }); + }) + ); + const isValidateSuccess = allValidateResult.value.every((item: string) => item === 'ok'); const ishasCondition = formModels.value.some((item) => !item.searchKey.value); if (ishasCondition) { Message.warning(t('searchPanel.selectTip')); - return; } - formModels.value.push(deaultTemplate); + if (isValidateSuccess && !ishasCondition) { + formModels.value.push(deaultTemplate); + } }; // 处理更新后的数据 @@ -223,4 +249,7 @@ background: rgb(var(--primary-9)); } } + :deep(.arco-scrollbar-track-direction-vertical .arco-scrollbar-thumb-bar) { + margin: 7px; + } diff --git a/frontend/src/components/business/ms-filter-panel/time-select.vue b/frontend/src/components/business/ms-filter-panel/time-select.vue index f437164b5d..6bfc50100d 100644 --- a/frontend/src/components/business/ms-filter-panel/time-select.vue +++ b/frontend/src/components/business/ms-filter-panel/time-select.vue @@ -4,7 +4,6 @@ v-model:model-value="timeValue" class="w-[100%]" show-time - allow-clear :time-picker-props="{ defaultValue: '00:00:00' }" format="YYYY-MM-DD HH:mm:ss" position="br" @@ -15,6 +14,7 @@ v-model:model-value="timeRangeValue" position="br" show-time + :allow-clear="false" class="w-[100%]" format="YYYY-MM-DD HH:mm" :time-picker-props="{ @@ -26,12 +26,12 @@