query.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <script lang="ts" setup>
  2. import { Page } from '@vben/common-ui';
  3. import { Card, message } from 'ant-design-vue';
  4. import { useVbenForm } from '#/adapter';
  5. const [QueryForm] = useVbenForm({
  6. // 默认展开
  7. collapsed: false,
  8. // 所有表单项共用,可单独在表单内覆盖
  9. commonConfig: {
  10. // 所有表单项
  11. componentProps: {
  12. class: 'w-full',
  13. },
  14. },
  15. // 提交函数
  16. handleSubmit: onSubmit,
  17. // 垂直布局,label和input在不同行,值为vertical
  18. // 水平布局,label和input在同一行
  19. layout: 'horizontal',
  20. schema: [
  21. {
  22. // 组件需要在 #/adapter.ts内注册,并加上类型
  23. component: 'Input',
  24. // 对应组件的参数
  25. componentProps: {
  26. placeholder: '请输入用户名',
  27. },
  28. // 字段名
  29. fieldName: 'username',
  30. // 界面显示的label
  31. label: '字符串',
  32. },
  33. {
  34. component: 'InputPassword',
  35. componentProps: {
  36. placeholder: '请输入密码',
  37. },
  38. fieldName: 'password',
  39. label: '密码',
  40. },
  41. {
  42. component: 'InputNumber',
  43. componentProps: {
  44. placeholder: '请输入',
  45. },
  46. fieldName: 'number',
  47. label: '数字(带后缀)',
  48. suffix: () => '¥',
  49. },
  50. {
  51. component: 'Select',
  52. componentProps: {
  53. allowClear: true,
  54. filterOption: true,
  55. options: [
  56. {
  57. label: '选项1',
  58. value: '1',
  59. },
  60. {
  61. label: '选项2',
  62. value: '2',
  63. },
  64. ],
  65. placeholder: '请选择',
  66. showSearch: true,
  67. },
  68. fieldName: 'options',
  69. label: '下拉选',
  70. },
  71. {
  72. component: 'DatePicker',
  73. fieldName: 'datePicker',
  74. label: '日期选择框',
  75. },
  76. ],
  77. // 是否可展开
  78. showCollapseButton: true,
  79. submitButtonOptions: {
  80. text: '查询',
  81. },
  82. // 大屏一行显示3个,中屏一行显示2个,小屏一行显示1个
  83. wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
  84. });
  85. const [QueryForm1] = useVbenForm({
  86. // 默认展开
  87. collapsed: true,
  88. collapsedRows: 2,
  89. // 所有表单项共用,可单独在表单内覆盖
  90. commonConfig: {
  91. // 所有表单项
  92. componentProps: {
  93. class: 'w-full',
  94. },
  95. },
  96. // 提交函数
  97. handleSubmit: onSubmit,
  98. // 垂直布局,label和input在不同行,值为vertical
  99. // 水平布局,label和input在同一行
  100. layout: 'horizontal',
  101. schema: (() => {
  102. const schema = [];
  103. for (let index = 0; index < 14; index++) {
  104. schema.push({
  105. // 组件需要在 #/adapter.ts内注册,并加上类型
  106. component: 'Input',
  107. // 字段名
  108. fieldName: `field${index}`,
  109. // 界面显示的label
  110. label: `字段${index}`,
  111. });
  112. }
  113. return schema;
  114. })(),
  115. // 是否可展开
  116. showCollapseButton: true,
  117. submitButtonOptions: {
  118. text: '查询',
  119. },
  120. // 大屏一行显示3个,中屏一行显示2个,小屏一行显示1个
  121. wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
  122. });
  123. function onSubmit(values: Record<string, any>) {
  124. message.success({
  125. content: `form values: ${JSON.stringify(values)}`,
  126. });
  127. }
  128. </script>
  129. <template>
  130. <Page
  131. description="查询表单,常用语和表格组合使用,可进行收缩展开。"
  132. title="表单组件"
  133. >
  134. <Card class="mb-5" title="查询表单,默认展开">
  135. <QueryForm />
  136. </Card>
  137. <Card title="查询表单,默认折叠,折叠时保留2行">
  138. <QueryForm1 />
  139. </Card>
  140. </Page>
  141. </template>