user.data.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
  2. // 国际化
  3. const { t } = useI18n()
  4. const validateMobile = (rule: any, value: any, callback: any) => {
  5. const reg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
  6. if (value === '') {
  7. callback(new Error('请输入联系手机'))
  8. } else {
  9. if (!reg.test(value)) {
  10. callback(new Error('请输入正确的手机号'))
  11. } else {
  12. callback()
  13. }
  14. }
  15. }
  16. // 表单校验
  17. export const rules = reactive({
  18. username: [required],
  19. nickname: [required],
  20. password: [required],
  21. deptId: [required],
  22. email: [
  23. { required: true, message: t('profile.rules.mail'), trigger: 'blur' },
  24. {
  25. type: 'email',
  26. message: t('profile.rules.truemail'),
  27. trigger: ['blur', 'change']
  28. }
  29. ],
  30. status: [required],
  31. postIds: [{ required: true, message: '请选择岗位', trigger: ['blur', 'change'] }],
  32. mobile: [
  33. required,
  34. {
  35. len: 11,
  36. trigger: 'blur',
  37. message: '请输入正确的手机号码'
  38. },
  39. { validator: validateMobile, trigger: 'blur' }
  40. ]
  41. })
  42. // crudSchemas
  43. const crudSchemas = reactive<VxeCrudSchema>({
  44. primaryKey: 'id',
  45. primaryType: 'id',
  46. primaryTitle: '用户编号',
  47. action: true,
  48. actionWidth: '200px',
  49. columns: [
  50. {
  51. title: '用户账号',
  52. field: 'username',
  53. isSearch: true
  54. },
  55. {
  56. title: '用户密码',
  57. field: 'password',
  58. isDetail: false,
  59. isTable: false,
  60. form: {
  61. component: 'InputPassword'
  62. }
  63. },
  64. {
  65. title: '用户' + t('profile.user.sex'),
  66. field: 'sex',
  67. dictType: DICT_TYPE.SYSTEM_USER_SEX,
  68. dictClass: 'number',
  69. table: { show: false }
  70. },
  71. {
  72. title: '用户昵称',
  73. field: 'nickname'
  74. },
  75. {
  76. title: '用户邮箱',
  77. field: 'email'
  78. },
  79. {
  80. title: '手机号码',
  81. field: 'mobile',
  82. isSearch: true
  83. },
  84. {
  85. title: '部门',
  86. field: 'deptId',
  87. isTable: false
  88. },
  89. {
  90. title: '岗位',
  91. field: 'postIds',
  92. isTable: false
  93. },
  94. {
  95. title: t('common.status'),
  96. field: 'status',
  97. dictType: DICT_TYPE.COMMON_STATUS,
  98. dictClass: 'number',
  99. isSearch: true,
  100. table: {
  101. slots: {
  102. default: 'status_default'
  103. }
  104. }
  105. },
  106. {
  107. title: '最后登录时间',
  108. field: 'loginDate',
  109. formatter: 'formatDate',
  110. isForm: false
  111. },
  112. {
  113. title: '最后登录IP',
  114. field: 'loginIp',
  115. isTable: false,
  116. isForm: false
  117. },
  118. {
  119. title: t('form.remark'),
  120. field: 'remark',
  121. isTable: false
  122. },
  123. {
  124. title: t('common.createTime'),
  125. field: 'createTime',
  126. formatter: 'formatDate',
  127. isTable: false,
  128. isForm: false,
  129. search: {
  130. show: true,
  131. itemRender: {
  132. name: 'XDataTimePicker'
  133. }
  134. }
  135. }
  136. ]
  137. })
  138. export const { allSchemas } = useVxeCrudSchemas(crudSchemas)