user.data.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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: '用户' + t('profile.user.sex'),
  65. field: 'sex',
  66. dictType: DICT_TYPE.SYSTEM_USER_SEX,
  67. dictClass: 'number',
  68. table: { show: false }
  69. },
  70. {
  71. title: '用户昵称',
  72. field: 'nickname'
  73. },
  74. {
  75. title: '用户邮箱',
  76. field: 'email'
  77. },
  78. {
  79. title: '手机号码',
  80. field: 'mobile',
  81. isSearch: true
  82. },
  83. {
  84. title: '部门',
  85. field: 'deptId',
  86. isTable: false
  87. },
  88. {
  89. title: '岗位',
  90. field: 'postIds',
  91. isTable: false
  92. },
  93. {
  94. title: t('common.status'),
  95. field: 'status',
  96. dictType: DICT_TYPE.COMMON_STATUS,
  97. dictClass: 'number',
  98. isSearch: true,
  99. table: {
  100. slots: {
  101. default: 'status_default'
  102. }
  103. }
  104. },
  105. {
  106. title: '最后登录时间',
  107. field: 'loginDate',
  108. formatter: 'formatDate',
  109. isForm: false
  110. },
  111. {
  112. title: '最后登录IP',
  113. field: 'loginIp',
  114. isTable: false,
  115. isForm: false
  116. },
  117. {
  118. title: t('form.remark'),
  119. field: 'remark',
  120. isTable: false
  121. },
  122. {
  123. title: t('common.createTime'),
  124. field: 'createTime',
  125. formatter: 'formatDate',
  126. isTable: false,
  127. isForm: false,
  128. search: {
  129. show: true,
  130. itemRender: {
  131. name: 'XDataTimePicker'
  132. }
  133. }
  134. }
  135. ]
  136. })
  137. export const { allSchemas } = useVxeCrudSchemas(crudSchemas)