uni-id-users.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // 表单校验规则由 schema2code 生成,不建议直接修改校验规则,而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema
  2. const validator = {
  3. "username": {
  4. "rules": [{
  5. "required": true,
  6. },
  7. {
  8. "format": "string"
  9. },
  10. {
  11. "minLength": 2
  12. }
  13. ],
  14. "label": "用户名"
  15. },
  16. "password": {
  17. "rules": [{
  18. "required": true,
  19. },
  20. {
  21. "format": "password"
  22. },
  23. {
  24. "minLength": 6
  25. }
  26. ],
  27. "label": "密码"
  28. },
  29. "mobile": {
  30. "rules": [{
  31. "format": "string"
  32. },
  33. {
  34. "pattern": "^\\+?[0-9-]{3,20}$"
  35. }
  36. ],
  37. "label": "手机号码"
  38. },
  39. "status": {
  40. "rules": [{
  41. "format": "int"
  42. },
  43. {
  44. "range": [{
  45. "text": "正常",
  46. "value": 0
  47. },
  48. {
  49. "text": "禁用",
  50. "value": 1
  51. },
  52. {
  53. "text": "审核中",
  54. "value": 2
  55. },
  56. {
  57. "text": "审核拒绝",
  58. "value": 3
  59. }
  60. ]
  61. }
  62. ],
  63. "defaultValue": 0,
  64. "label": "用户状态"
  65. },
  66. "email": {
  67. "rules": [{
  68. "format": "string"
  69. },
  70. {
  71. "format": "email"
  72. }
  73. ],
  74. "label": "邮箱"
  75. },
  76. "role": {
  77. "rules": [{
  78. "format": "array"
  79. }],
  80. "label": "角色"
  81. },
  82. "last_login_date": {
  83. "rules": [{
  84. "format": "timestamp"
  85. }]
  86. }
  87. }
  88. const enumConverter = {
  89. "status_valuetotext": {
  90. "0": "正常",
  91. "1": "禁用",
  92. "2": "审核中",
  93. "3": "审核拒绝"
  94. }
  95. }
  96. function filterToWhere(filter, command) {
  97. let where = {}
  98. for (let field in filter) {
  99. let {
  100. type,
  101. value
  102. } = filter[field]
  103. switch (type) {
  104. case "search":
  105. if (typeof value === 'string' && value.length) {
  106. where[field] = new RegExp(value)
  107. }
  108. break;
  109. case "select":
  110. if (value.length) {
  111. let selectValue = []
  112. for (let s of value) {
  113. selectValue.push(command.eq(s))
  114. }
  115. where[field] = command.or(selectValue)
  116. }
  117. break;
  118. case "range":
  119. if (value.length) {
  120. let gt = value[0]
  121. let lt = value[1]
  122. where[field] = command.and([command.gte(gt), command.lte(lt)])
  123. }
  124. break;
  125. case "date":
  126. if (value.length) {
  127. let [s, e] = value
  128. let startDate = new Date(s)
  129. let endDate = new Date(e)
  130. where[field] = command.and([command.gte(startDate), command.lte(endDate)])
  131. }
  132. break;
  133. case "timestamp":
  134. if (value.length) {
  135. let [startDate, endDate] = value
  136. where[field] = command.and([command.gte(startDate), command.lte(endDate)])
  137. }
  138. break;
  139. }
  140. }
  141. return where
  142. }
  143. export {
  144. validator,
  145. enumConverter,
  146. filterToWhere
  147. }