Commit 33fbe43ff685a364f9f96870372b2ea6e159519e

Authored by xingyu4j
1 parent dfb24dda

fix: 修复Search组件无法默认值

yudao-ui-admin-vue3/package.json
1 { 1 {
2 "name": "ruoyi-vue-pro-vue3", 2 "name": "ruoyi-vue-pro-vue3",
3 - "version": "1.6.4.1851", 3 + "version": "1.6.4.1861",
4 "description": "基于vue3、vite3、element-plus、typesScript", 4 "description": "基于vue3、vite3、element-plus、typesScript",
5 "author": "xingyu", 5 "author": "xingyu",
6 "private": false, 6 "private": false,
yudao-ui-admin-vue3/src/components/Search/src/Search.vue
@@ -33,7 +33,11 @@ const props = defineProps({ @@ -33,7 +33,11 @@ const props = defineProps({
33 expand: propTypes.bool.def(false), 33 expand: propTypes.bool.def(false),
34 // 伸缩的界限字段 34 // 伸缩的界限字段
35 expandField: propTypes.string.def(''), 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 const emit = defineEmits(['search', 'reset']) 43 const emit = defineEmits(['search', 'reset'])
@@ -62,7 +66,9 @@ const newSchema = computed(() =&gt; { @@ -62,7 +66,9 @@ const newSchema = computed(() =&gt; {
62 return schema 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 const search = async () => { 73 const search = async () => {
68 await unref(elFormRef)?.validate(async (isValid) => { 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) =&gt; { @@ -41,6 +41,9 @@ export const useForm = (props?: FormProps) =&gt; {
41 setProps: async (props: FormProps = {}) => { 41 setProps: async (props: FormProps = {}) => {
42 const form = await getForm() 42 const form = await getForm()
43 form?.setProps(props) 43 form?.setProps(props)
  44 + if (props.model) {
  45 + form?.setValues(props.model)
  46 + }
44 }, 47 },
45 48
46 setValues: async (data: Recordable) => { 49 setValues: async (data: Recordable) => {
yudao-ui-admin-vue3/src/hooks/web/useTable.ts
@@ -18,6 +18,8 @@ interface UseTableConfig&lt;T = any&gt; { @@ -18,6 +18,8 @@ interface UseTableConfig&lt;T = any&gt; {
18 exportListApi?: (option: any) => Promise<T> 18 exportListApi?: (option: any) => Promise<T>
19 // 返回数据格式配置 19 // 返回数据格式配置
20 response?: ResponseType 20 response?: ResponseType
  21 + // 默认传递的参数
  22 + defaultParams?: Recordable
21 props?: TableProps 23 props?: TableProps
22 } 24 }
23 25
@@ -43,7 +45,9 @@ export const useTable = &lt;T = any&gt;(config?: UseTableConfig&lt;T&gt;) =&gt; { @@ -43,7 +45,9 @@ export const useTable = &lt;T = any&gt;(config?: UseTableConfig&lt;T&gt;) =&gt; {
43 // 表格数据 45 // 表格数据
44 tableList: [], 46 tableList: [],
45 // AxiosConfig 配置 47 // AxiosConfig 配置
46 - params: {}, 48 + params: {
  49 + ...(config?.defaultParams || {})
  50 + },
47 // 加载中 51 // 加载中
48 loading: true, 52 loading: true,
49 // 导出加载中 53 // 导出加载中
yudao-ui-admin-vue3/src/views/system/menu/index.vue
@@ -53,7 +53,6 @@ @@ -53,7 +53,6 @@
53 :print-config="{}" 53 :print-config="{}"
54 :export-config="{}" 54 :export-config="{}"
55 :data="tableData" 55 :data="tableData"
56 - class="xtable"  
57 > 56 >
58 <vxe-column title="菜单名称" field="name" width="200" tree-node> 57 <vxe-column title="菜单名称" field="name" width="200" tree-node>
59 <template #default="{ row }"> 58 <template #default="{ row }">