Skip to content

Commit

Permalink
perf: search校验失败后,refresh保持原来的formData
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Jun 7, 2023
1 parent 1931489 commit 632a0df
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
20 changes: 20 additions & 0 deletions docs/zh/api/crud-options/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,25 @@ const crudOptions = {
}
```

## validate
* 说明:是否启用表单验证
* 类型:Boolean
* 默认:`false`


## onValidateError
* 说明:监听校验错误事件
* 类型:async Function(context)
* 默认值: `()=>{ui.notification.error({message:'查询表单校验失败'})}` 弹出查询表单校验失败通知
```js
const crudOptions = {
search:{
onValidateError(context:any){
console.log('validate error',context.error)
}
}
}
```

## 更多参数
* 说明:更多参数见:[FsSearch](/api/components/crud/search/index.md)组件文档
12 changes: 10 additions & 2 deletions packages/fast-crud/src/components/fs-crud.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@
<script lang="ts">
import { computed, defineComponent, nextTick, onMounted, provide, ref, SetupContext, toRef } from "vue";
import _ from "lodash-es";
import traceUtil from "../utils/util.trace";
import { uiContext } from "../ui";
import { useMerge } from "../use/use-merge";
import utilLog from "../utils/util.log";
import { SetSearchFormDataProps } from "../d";
import { useUi } from "../use";
import { utils } from "../utils";
const { merge } = useMerge();
function useProviders(props: any, ctx: SetupContext) {
Expand Down Expand Up @@ -164,6 +164,13 @@ function useSearch(props: any, ctx: SetupContext) {
return searchFormData.value;
};

const getSearchValidatedFormData = () => {
if (searchRef.value) {
searchFormData.value = searchRef.value.getValidatedForm();
}
return searchFormData.value;
};

/**
* 设置form值
* @param form form对象
Expand Down Expand Up @@ -191,7 +198,8 @@ function useSearch(props: any, ctx: SetupContext) {
onSearchReset,
getSearchRef,
getSearchFormData,
setSearchFormData
setSearchFormData,
getSearchValidatedFormData
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/fast-crud/src/components/search/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ export default defineComponent({
getComponentRenderRef,
getComponentRef,
getForm,
getValidatedForm,
setForm,
searchFormRef,
onInput,
Expand Down
5 changes: 4 additions & 1 deletion packages/fast-crud/src/d/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ export type CrudExpose = {
getSearchRef: () => any;
/**
* 获取查询表单数据
* @param context
*/
getSearchFormData: () => any;
/**
* 获取查询表单校验成功的数据
*/
getSearchValidatedFormData: () => any;
/**
* 重新设置查询表单数据
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/fast-crud/src/use/default-crud-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default {
// n-form 是否显示校验反馈
showFeedback: false
},
onValidateError() {
ui.notification.error({ message: t("fs.search.error.message") });
},
collapse: true,
show: true,
buttons: {
Expand Down
11 changes: 10 additions & 1 deletion packages/fast-crud/src/use/use-expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ export function useExpose(props: UseExposeProps): UseExposeRet {
}
return {};
},
getSearchValidatedFormData() {
if (!crudRef.value) {
return {};
}
if (crudRef.value.getSearchValidatedFormData) {
return crudRef.value.getSearchValidatedFormData();
}
return {};
},
/**
* {form,mergeForm}
*/
Expand Down Expand Up @@ -312,7 +321,7 @@ export function useExpose(props: UseExposeProps): UseExposeRet {
};
}

const searchFormData = _.cloneDeep(crudExpose.getSearchFormData());
const searchFormData = _.cloneDeep(crudExpose.getSearchValidatedFormData());
//配置searchValueResolve
if (crudBinding.value?.search?.columns) {
crudExpose.doValueResolve({ form: searchFormData }, toRaw(crudBinding.value.search.columns));
Expand Down

0 comments on commit 632a0df

Please sign in to comment.