index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <script lang="ts" setup>
  2. import { message } from 'ant-design-vue';
  3. import { useVbenForm } from '#/adapter/form';
  4. const [QueryForm] = useVbenForm({
  5. // 默认展开
  6. collapsed: false,
  7. // 所有表单项共用,可单独在表单内覆盖
  8. commonConfig: {
  9. // 所有表单项
  10. componentProps: {
  11. class: 'w-full',
  12. },
  13. },
  14. // 提交函数
  15. handleSubmit: onSubmit,
  16. // 垂直布局,label和input在不同行,值为vertical
  17. // 水平布局,label和input在同一行
  18. layout: 'horizontal',
  19. schema: [
  20. {
  21. // 组件需要在 #/adapter.ts内注册,并加上类型
  22. component: 'Input',
  23. // 对应组件的参数
  24. componentProps: {
  25. placeholder: '请输入用户名',
  26. },
  27. // 字段名
  28. fieldName: 'username',
  29. // 界面显示的label
  30. label: '字符串',
  31. },
  32. {
  33. component: 'InputPassword',
  34. componentProps: {
  35. placeholder: '请输入密码',
  36. },
  37. fieldName: 'password',
  38. label: '密码',
  39. },
  40. {
  41. component: 'InputNumber',
  42. componentProps: {
  43. placeholder: '请输入',
  44. },
  45. fieldName: 'number',
  46. label: '数字(带后缀)',
  47. suffix: () => '¥',
  48. },
  49. {
  50. component: 'Select',
  51. componentProps: {
  52. allowClear: true,
  53. filterOption: true,
  54. options: [
  55. {
  56. label: '选项1',
  57. value: '1',
  58. },
  59. {
  60. label: '选项2',
  61. value: '2',
  62. },
  63. ],
  64. placeholder: '请选择',
  65. showSearch: true,
  66. },
  67. fieldName: 'options',
  68. label: '下拉选',
  69. },
  70. {
  71. component: 'DatePicker',
  72. fieldName: 'datePicker',
  73. label: '日期选择框',
  74. },
  75. ],
  76. // 是否可展开
  77. showCollapseButton: true,
  78. submitButtonOptions: {
  79. content: '查询',
  80. },
  81. wrapperClass: 'grid-cols-1 md:grid-cols-2',
  82. });
  83. function onSubmit(values: Record<string, any>) {
  84. message.success({
  85. content: `form values: ${JSON.stringify(values)}`,
  86. });
  87. }
  88. </script>
  89. <template>
  90. <QueryForm />
  91. </template>