index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <script lang="ts" setup>
  2. import { message } from 'ant-design-vue';
  3. import { useVbenForm } from '#/adapter/form';
  4. const [BaseForm] = useVbenForm({
  5. // 所有表单项共用,可单独在表单内覆盖
  6. commonConfig: {
  7. // 所有表单项
  8. componentProps: {
  9. class: 'w-full',
  10. },
  11. },
  12. // 提交函数
  13. handleSubmit: onSubmit,
  14. // 垂直布局,label和input在不同行,值为vertical
  15. // 水平布局,label和input在同一行
  16. layout: 'horizontal',
  17. schema: [
  18. {
  19. // 组件需要在 #/adapter.ts内注册,并加上类型
  20. component: 'Input',
  21. // 对应组件的参数
  22. componentProps: {
  23. placeholder: '请输入用户名',
  24. },
  25. // 字段名
  26. fieldName: 'username',
  27. // 界面显示的label
  28. label: '字符串',
  29. },
  30. {
  31. component: 'InputPassword',
  32. componentProps: {
  33. placeholder: '请输入密码',
  34. },
  35. fieldName: 'password',
  36. label: '密码',
  37. },
  38. {
  39. component: 'InputNumber',
  40. componentProps: {
  41. placeholder: '请输入',
  42. },
  43. fieldName: 'number',
  44. label: '数字(带后缀)',
  45. suffix: () => '¥',
  46. },
  47. {
  48. component: 'Select',
  49. componentProps: {
  50. allowClear: true,
  51. filterOption: true,
  52. options: [
  53. {
  54. label: '选项1',
  55. value: '1',
  56. },
  57. {
  58. label: '选项2',
  59. value: '2',
  60. },
  61. ],
  62. placeholder: '请选择',
  63. showSearch: true,
  64. },
  65. fieldName: 'options',
  66. label: '下拉选',
  67. },
  68. {
  69. component: 'RadioGroup',
  70. componentProps: {
  71. options: [
  72. {
  73. label: '选项1',
  74. value: '1',
  75. },
  76. {
  77. label: '选项2',
  78. value: '2',
  79. },
  80. ],
  81. },
  82. fieldName: 'radioGroup',
  83. label: '单选组',
  84. },
  85. {
  86. component: 'Radio',
  87. fieldName: 'radio',
  88. label: '',
  89. renderComponentContent: () => {
  90. return {
  91. default: () => ['Radio'],
  92. };
  93. },
  94. },
  95. {
  96. component: 'CheckboxGroup',
  97. componentProps: {
  98. name: 'cname',
  99. options: [
  100. {
  101. label: '选项1',
  102. value: '1',
  103. },
  104. {
  105. label: '选项2',
  106. value: '2',
  107. },
  108. ],
  109. },
  110. fieldName: 'checkboxGroup',
  111. label: '多选组',
  112. },
  113. {
  114. component: 'Checkbox',
  115. fieldName: 'checkbox',
  116. label: '',
  117. renderComponentContent: () => {
  118. return {
  119. default: () => ['我已阅读并同意'],
  120. };
  121. },
  122. },
  123. {
  124. component: 'Mentions',
  125. componentProps: {
  126. options: [
  127. {
  128. label: 'afc163',
  129. value: 'afc163',
  130. },
  131. {
  132. label: 'zombieJ',
  133. value: 'zombieJ',
  134. },
  135. ],
  136. placeholder: '请输入',
  137. },
  138. fieldName: 'mentions',
  139. label: '提及',
  140. },
  141. {
  142. component: 'Rate',
  143. fieldName: 'rate',
  144. label: '评分',
  145. },
  146. {
  147. component: 'Switch',
  148. componentProps: {
  149. class: 'w-auto',
  150. },
  151. fieldName: 'switch',
  152. label: '开关',
  153. },
  154. {
  155. component: 'DatePicker',
  156. fieldName: 'datePicker',
  157. label: '日期选择框',
  158. },
  159. {
  160. component: 'RangePicker',
  161. fieldName: 'rangePicker',
  162. label: '范围选择器',
  163. },
  164. {
  165. component: 'TimePicker',
  166. fieldName: 'timePicker',
  167. label: '时间选择框',
  168. },
  169. {
  170. component: 'TreeSelect',
  171. componentProps: {
  172. allowClear: true,
  173. placeholder: '请选择',
  174. showSearch: true,
  175. treeData: [
  176. {
  177. label: 'root 1',
  178. value: 'root 1',
  179. children: [
  180. {
  181. label: 'parent 1',
  182. value: 'parent 1',
  183. children: [
  184. {
  185. label: 'parent 1-0',
  186. value: 'parent 1-0',
  187. children: [
  188. {
  189. label: 'my leaf',
  190. value: 'leaf1',
  191. },
  192. {
  193. label: 'your leaf',
  194. value: 'leaf2',
  195. },
  196. ],
  197. },
  198. {
  199. label: 'parent 1-1',
  200. value: 'parent 1-1',
  201. },
  202. ],
  203. },
  204. {
  205. label: 'parent 2',
  206. value: 'parent 2',
  207. },
  208. ],
  209. },
  210. ],
  211. treeNodeFilterProp: 'label',
  212. },
  213. fieldName: 'treeSelect',
  214. label: '树选择',
  215. },
  216. ],
  217. wrapperClass: 'grid-cols-1',
  218. });
  219. function onSubmit(values: Record<string, any>) {
  220. message.success({
  221. content: `form values: ${JSON.stringify(values)}`,
  222. });
  223. }
  224. </script>
  225. <template>
  226. <BaseForm />
  227. </template>