Commit 33fbe43ff685a364f9f96870372b2ea6e159519e
1 parent
dfb24dda
fix: 修复Search组件无法默认值
Showing
5 changed files
with
17 additions
and
5 deletions
yudao-ui-admin-vue3/package.json
yudao-ui-admin-vue3/src/components/Search/src/Search.vue
| ... | ... | @@ -33,7 +33,11 @@ const props = defineProps({ |
| 33 | 33 | expand: propTypes.bool.def(false), |
| 34 | 34 | // 伸缩的界限字段 |
| 35 | 35 | expandField: propTypes.string.def(''), |
| 36 | - inline: propTypes.bool.def(true) | |
| 36 | + inline: propTypes.bool.def(true), | |
| 37 | + model: { | |
| 38 | + type: Object as PropType<Recordable>, | |
| 39 | + default: () => ({}) | |
| 40 | + } | |
| 37 | 41 | }) |
| 38 | 42 | |
| 39 | 43 | const emit = defineEmits(['search', 'reset']) |
| ... | ... | @@ -62,7 +66,9 @@ const newSchema = computed(() => { |
| 62 | 66 | return schema |
| 63 | 67 | }) |
| 64 | 68 | |
| 65 | -const { register, elFormRef, methods } = useForm() | |
| 69 | +const { register, elFormRef, methods } = useForm({ | |
| 70 | + model: props.model || {} | |
| 71 | +}) | |
| 66 | 72 | |
| 67 | 73 | const search = async () => { |
| 68 | 74 | await unref(elFormRef)?.validate(async (isValid) => { | ... | ... |
yudao-ui-admin-vue3/src/hooks/web/useForm.ts
| ... | ... | @@ -41,6 +41,9 @@ export const useForm = (props?: FormProps) => { |
| 41 | 41 | setProps: async (props: FormProps = {}) => { |
| 42 | 42 | const form = await getForm() |
| 43 | 43 | form?.setProps(props) |
| 44 | + if (props.model) { | |
| 45 | + form?.setValues(props.model) | |
| 46 | + } | |
| 44 | 47 | }, |
| 45 | 48 | |
| 46 | 49 | setValues: async (data: Recordable) => { | ... | ... |
yudao-ui-admin-vue3/src/hooks/web/useTable.ts
| ... | ... | @@ -18,6 +18,8 @@ interface UseTableConfig<T = any> { |
| 18 | 18 | exportListApi?: (option: any) => Promise<T> |
| 19 | 19 | // 返回数据格式配置 |
| 20 | 20 | response?: ResponseType |
| 21 | + // 默认传递的参数 | |
| 22 | + defaultParams?: Recordable | |
| 21 | 23 | props?: TableProps |
| 22 | 24 | } |
| 23 | 25 | |
| ... | ... | @@ -43,7 +45,9 @@ export const useTable = <T = any>(config?: UseTableConfig<T>) => { |
| 43 | 45 | // 表格数据 |
| 44 | 46 | tableList: [], |
| 45 | 47 | // AxiosConfig 配置 |
| 46 | - params: {}, | |
| 48 | + params: { | |
| 49 | + ...(config?.defaultParams || {}) | |
| 50 | + }, | |
| 47 | 51 | // 加载中 |
| 48 | 52 | loading: true, |
| 49 | 53 | // 导出加载中 | ... | ... |
yudao-ui-admin-vue3/src/views/system/menu/index.vue