basic.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <PageWrapper
  3. title="基础表单"
  4. content="基础表单,用于向用户收集表单信息,并展示 Password 组件使用示例"
  5. >
  6. <el-card shadow="never" class="mt-3 proCard">
  7. <el-row :gutter="20" justify="center" class="py-4">
  8. <el-col :xs="24" :sm="20" :md="14" :lg="12" :xl="8">
  9. <BasicForm
  10. submitButtonText="提交预约"
  11. :gridProps="{ cols: 1 }"
  12. :schemas="schemas"
  13. @submit="handleSubmit"
  14. @reset="handleReset"
  15. >
  16. <template #statusSlot="{ model, field }">
  17. <el-input v-model="model[field]" placeholder="请输入您今天的状态" />
  18. </template>
  19. </BasicForm>
  20. </el-col>
  21. </el-row>
  22. </el-card>
  23. </PageWrapper>
  24. </template>
  25. <script lang="ts" setup>
  26. import { BasicForm, FormSchema } from '@/components/Form/index';
  27. import { ElMessage } from 'element-plus';
  28. import { getProvinceList } from '@/api/select/select';
  29. const params = {
  30. type: 1,
  31. };
  32. async function loadSelectData(res) {
  33. //这里可以进行数据转换处理
  34. return (await getProvinceList({ ...res, ...params })).map((item, index) => {
  35. return {
  36. ...item,
  37. index,
  38. };
  39. });
  40. }
  41. const schemas: FormSchema[] = [
  42. {
  43. field: 'id',
  44. defaultValue: 128,
  45. hidden: true,
  46. },
  47. {
  48. field: 'identity',
  49. defaultValue: '我是一个隐藏字段内容',
  50. hidden: true,
  51. },
  52. {
  53. field: 'name',
  54. component: 'Input',
  55. label: '姓名',
  56. labelMessage: '这是一个提示',
  57. componentProps: {
  58. placeholder: '请输入姓名',
  59. onInput: (e: any) => {
  60. console.log(e);
  61. },
  62. },
  63. rules: [{ required: true, message: '请输入姓名', trigger: ['blur'] }],
  64. },
  65. {
  66. field: 'user.basic.age',
  67. component: 'InputNumber',
  68. label: '年龄',
  69. labelMessage: '这是一个field对象演示',
  70. componentProps: {
  71. placeholder: '请输入年龄',
  72. controlsPosition: 'right',
  73. },
  74. rules: [{ required: true, type: 'number', message: '请输入年龄', trigger: ['blur'] }],
  75. },
  76. {
  77. field: 'mobile',
  78. component: 'Input',
  79. label: '手机',
  80. componentProps: {
  81. placeholder: '请输入手机号码',
  82. onInput: (e: any) => {
  83. console.log(e);
  84. },
  85. },
  86. },
  87. {
  88. field: 'type',
  89. component: 'Select',
  90. label: '类型',
  91. labelMessage: '选择类型会出现预约时间表单',
  92. componentProps: {
  93. placeholder: '请选择类型',
  94. clearable: true,
  95. options: [
  96. {
  97. label: '舒适性',
  98. value: 1,
  99. },
  100. {
  101. label: '经济性',
  102. value: 2,
  103. },
  104. ],
  105. onChange: (e: any) => {
  106. console.log(e);
  107. },
  108. },
  109. },
  110. {
  111. field: 'classify',
  112. component: 'BasicSelect',
  113. label: '动态分类',
  114. componentProps: {
  115. placeholder: '请选择分类',
  116. request: loadSelectData,
  117. onChange: (e: any) => {
  118. console.log(e);
  119. },
  120. },
  121. rules: [{ required: true, message: '请选择分类', trigger: ['change'] }],
  122. },
  123. {
  124. field: 'makeDate',
  125. component: 'DatePicker',
  126. label: '预约时间',
  127. defaultValue: 1183135260000,
  128. componentProps: {
  129. type: 'date',
  130. onChange: (e: any) => {
  131. console.log(e);
  132. },
  133. },
  134. // 根据 上面选择的类型,获取页面其他逻辑字段 处理显示表单
  135. // 可用字段 schema, values, model, field
  136. hidden: ({ model }) => {
  137. return !model.type;
  138. },
  139. rules: [{ required: true, type: 'number', message: '请选择预约时间', trigger: ['change'] }],
  140. },
  141. {
  142. field: 'makeTime',
  143. component: 'TimePicker',
  144. label: '停留时间',
  145. componentProps: {
  146. onChange: (e: any) => {
  147. console.log(e);
  148. },
  149. },
  150. },
  151. {
  152. field: 'status',
  153. label: '状态',
  154. //插槽
  155. slot: 'statusSlot',
  156. },
  157. {
  158. field: 'makeProject',
  159. component: 'Checkbox',
  160. label: '预约项目',
  161. componentProps: {
  162. placeholder: '请选择预约项目',
  163. options: [
  164. {
  165. label: '种牙',
  166. value: 1,
  167. },
  168. {
  169. label: '补牙',
  170. value: 2,
  171. },
  172. {
  173. label: '根管',
  174. value: 3,
  175. },
  176. ],
  177. onChange: (e: any) => {
  178. console.log(e);
  179. },
  180. },
  181. },
  182. {
  183. field: 'makeSource',
  184. component: 'RadioGroup',
  185. label: '来源',
  186. componentProps: {
  187. options: [
  188. {
  189. label: '网上',
  190. value: 1,
  191. },
  192. {
  193. label: '门店',
  194. value: 2,
  195. },
  196. ],
  197. onChange: (e: any) => {
  198. console.log(e);
  199. },
  200. },
  201. },
  202. // {
  203. // field: 'password',
  204. // label: '密码',
  205. // slot: 'passwordSlot',
  206. // },
  207. ];
  208. function handleSubmit(values: Recordable) {
  209. if (!values) return;
  210. ElMessage.success(JSON.stringify(values));
  211. }
  212. function handleReset(values: Recordable) {
  213. ElMessage.success(JSON.stringify(values));
  214. }
  215. </script>
  216. <style lang="scss" scoped></style>