volunteer.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import CommonContent from "@/api/CommonContent";
  2. import VillageApi from "@/api/inhert/VillageApi";
  3. import { useAliOssUploadCo } from "@/common/components/upload/AliOssUploadCo";
  4. import type { IDynamicFormItemCallbackAdditionalProps, IDynamicFormOptions, IDynamicFormRef } from "@/components/dynamic";
  5. import type { CheckBoxTreeListProps } from "@/components/dynamic/wrappers/CheckBoxTreeList.vue";
  6. import type { PickerIdFieldProps } from "@/components/dynamic/wrappers/PickerIdField";
  7. import type { RadioValueProps } from "@/components/dynamic/wrappers/RadioValue";
  8. import type { FieldProps } from "@/components/form/Field.vue";
  9. import type { FormProps } from "@/components/form/Form.vue";
  10. import type { UploaderFieldProps } from "@/components/form/UploaderField.vue";
  11. import type { RuleItem } from "async-validator";
  12. import type { Ref } from "vue";
  13. export function getVolunteerForm(options: {
  14. canSetCatalog: boolean,
  15. villageId: number,
  16. onlyPassword?: boolean,
  17. noPassword?: boolean,
  18. isNew: Ref<boolean>,
  19. formRef: Ref<IDynamicFormRef|undefined>,
  20. }) : IDynamicFormOptions {
  21. return {
  22. formItems: [
  23. {
  24. name: 'groupBase',
  25. type: 'flat-simple',
  26. show: { callback: () => !options.noPassword },
  27. children: [
  28. {
  29. label: '登录账号', name: 'username', type: 'text',
  30. additionalProps: {
  31. placeholder: '请输入登录账号',
  32. },
  33. rules: [{ required: true, message: '请输入登录账号' }],
  34. show: { callback: () => options.isNew.value },
  35. },
  36. {
  37. label: '密码',
  38. name: 'password',
  39. type: 'text',
  40. additionalProps: {
  41. placeholder: '请输入密码',
  42. type: 'password',
  43. extraMessage: '密码建议:8-20位,包含字母和数字,\n不要使用过于简单的密码',
  44. } as FieldProps,
  45. rules: [{ required: true, message: '请输入密码' }],
  46. show: { callback: () => options.isNew.value || options.onlyPassword === true },
  47. },
  48. {
  49. label: '确认密码',
  50. name: 'passwordRepeat',
  51. type: 'text',
  52. additionalProps: {
  53. placeholder: '请再输入一次密码',
  54. type: 'password',
  55. } as FieldProps,
  56. rules: [
  57. { required: true, message: '请再输入一次密码' },
  58. {
  59. async validator(rule, value) {
  60. if (value != options.formRef.value?.getValueByPath('password'))
  61. throw '两次输入密码不一致,请检查';
  62. },
  63. }
  64. ] as RuleItem[],
  65. show: { callback: () => options.isNew.value || options.onlyPassword === true },
  66. },
  67. ]
  68. },
  69. {
  70. name: 'groupExtra',
  71. type: 'flat-simple',
  72. show: { callback: () => options.onlyPassword !== true },
  73. childrenColProps: {
  74. span: 24,
  75. },
  76. children: [
  77. {
  78. label: '真实名称', name: 'name', type: 'text',
  79. additionalProps: { placeholder: '请输入真实名称' },
  80. rules: [{ required: true, message: '请输入真实名称' }],
  81. },
  82. {
  83. label: '手机号', name: 'mobile', type: 'text',
  84. additionalProps: { placeholder: '请输入手机号' },
  85. rules: [{ required: true, message: '请输入手机号' }],
  86. },
  87. {
  88. label: '区域', name: 'regionId', type: 'select-id',
  89. additionalProps: {
  90. placeholder: '请选择区域',
  91. disabled: { callback: () => !options.isNew.value },
  92. loadData: async () => (await CommonContent.getCategoryList(1)).map(p => ({ text: p.title, value: p.id, raw: p }))
  93. } as IDynamicFormItemCallbackAdditionalProps<PickerIdFieldProps>,
  94. rules: [{ required: true, message: '请选择区域' }],
  95. },
  96. {
  97. label: '性别', name: 'sex', type: 'radio-value',
  98. additionalProps: {
  99. options: [
  100. { text: '男', value: 1 },
  101. { text: '女', value: 2 }
  102. ]
  103. } as RadioValueProps,
  104. },
  105. {
  106. label: '头像', name: 'image', type: 'uploader',
  107. additionalProps: {
  108. single: true,
  109. maxFileSize: 1024 * 1024 * 10,
  110. upload: useAliOssUploadCo('xiangyuan/volunteer/images')
  111. } as UploaderFieldProps,
  112. },
  113. {
  114. label: '类型', name: 'type', type: 'radio-value',
  115. additionalProps: {
  116. options: [
  117. { text: '志愿者', value: 'volunteer' },
  118. { text: '社区工作者', value: 'staff' }
  119. ]
  120. } as RadioValueProps,
  121. rules: [{ required: true, message: '请选择类型' }],
  122. },
  123. /* {
  124. label: '类型', name: 'residentStatus', type: 'radio-value',
  125. additionalProps: {
  126. options: [
  127. { text: '在村劳作', value: 1 },
  128. { text: '社区居民', value: 2 },
  129. { text: '在外游子', value: 3 },
  130. { text: '退休人员', value: 4 },
  131. ]
  132. } as RadioValueProps,
  133. rules: [{ required: true, message: '请选择类型' }],
  134. }, */
  135. {
  136. label: '工作单位', name: 'unit', type: 'text', additionalProps: { placeholder: '请输入手机号' } ,
  137. rules: [{ required: true, message: '请输入手机号' }],
  138. show: { callback: () => options.formRef.value?.getValueByPath('type') === 'staff' },
  139. },
  140. {
  141. label: '职位', name: 'job', type: 'text', additionalProps: { placeholder: '请输入手机号' } ,
  142. rules: [{ required: true, message: '请输入手机号' }],
  143. show: { callback: () => options.formRef.value?.getValueByPath('type') === 'staff' },
  144. },
  145. { label: '现居地址', name: 'address', type: 'text', additionalProps: { placeholder: '请输入现居地址' } },
  146. {
  147. label: '个人介绍',
  148. name: 'intro',
  149. type: 'textarea',
  150. additionalProps: {
  151. placeholder: '请输入个人介绍',
  152. showWordLimit: true,
  153. maxLength: 5000,
  154. } as FieldProps,
  155. },
  156. ...(options.canSetCatalog ? [{
  157. label: '采集版块', name: 'catalogIds', type: 'check-box-tree',
  158. additionalProps: {
  159. placeholder: '请选择采集版块',
  160. vertical: true,
  161. multiple: true,
  162. loadData: async (pid) => (await VillageApi.getCatalogList(options.villageId, undefined, pid)).map((p) => ({
  163. text: p.title,
  164. value: p.id,
  165. hasChildren: p.haschild,
  166. })),
  167. } as CheckBoxTreeListProps,
  168. }]: []),
  169. /* {
  170. label: '村落认领说明', name: 'claimReason', type: 'text',
  171. additionalProps: { placeholder: '请输入村落认领说明' } ,
  172. show: { callback: () => options.isNew.value },
  173. }, */
  174. ]
  175. },
  176. ],
  177. formAdditionaProps: {
  178. labelWidth: '160rpx',
  179. labelAlign: 'right',
  180. innerStyle: {
  181. radius: '10rpx',
  182. },
  183. } as Omit<FormProps, 'model'>,
  184. }
  185. }