user.data.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. mobile: [
  32. required,
  33. {
  34. len: 11,
  35. trigger: 'blur',
  36. message: '请输入正确的手机号码'
  37. },
  38. { validator: validateMobile, trigger: 'blur' }
  39. ]
  40. })
  41. // crudSchemas
  42. const crudSchemas = reactive<VxeCrudSchema>({
  43. primaryKey: 'id',
  44. primaryType: 'id',
  45. primaryTitle: '用户编号',
  46. action: true,
  47. actionWidth: '200px',
  48. columns: [
  49. {
  50. title: '用户账号',
  51. field: 'username',
  52. isSearch: true
  53. },
  54. {
  55. title: '用户密码',
  56. field: 'password',
  57. isDetail: false,
  58. isTable: false,
  59. form: {
  60. component: 'InputPassword'
  61. }
  62. },
  63. {
  64. title: '用户昵称',
  65. field: 'nickname'
  66. },
  67. {
  68. title: '用户邮箱',
  69. field: 'email'
  70. },
  71. {
  72. title: '手机号码',
  73. field: 'mobile',
  74. isSearch: true
  75. },
  76. {
  77. title: '部门',
  78. field: 'deptId',
  79. isTable: false
  80. },
  81. {
  82. title: '岗位',
  83. field: 'postIds',
  84. isTable: false
  85. },
  86. {
  87. title: t('common.status'),
  88. field: 'status',
  89. dictType: DICT_TYPE.COMMON_STATUS,
  90. dictClass: 'number',
  91. isSearch: true,
  92. table: {
  93. slots: {
  94. default: 'status_default'
  95. }
  96. }
  97. },
  98. {
  99. title: '最后登录时间',
  100. field: 'loginDate',
  101. formatter: 'formatDate',
  102. isForm: false
  103. },
  104. {
  105. title: '最后登录IP',
  106. field: 'loginIp',
  107. isTable: false,
  108. isForm: false
  109. },
  110. {
  111. title: t('form.remark'),
  112. field: 'remark',
  113. isTable: false
  114. },
  115. {
  116. title: t('common.createTime'),
  117. field: 'createTime',
  118. formatter: 'formatDate',
  119. isTable: false,
  120. isForm: false,
  121. search: {
  122. show: true,
  123. itemRender: {
  124. name: 'XDataTimePicker'
  125. }
  126. }
  127. }
  128. ]
  129. })
  130. export const { allSchemas } = useVxeCrudSchemas(crudSchemas)