uni-id-roles.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // 表单校验规则由 schema2code 生成,不建议直接修改校验规则,而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema
  2. const validator = {
  3. "role_id": {
  4. "rules": [
  5. {
  6. "required": true
  7. },
  8. {
  9. "format": "string"
  10. }
  11. ],
  12. "label": "唯一ID"
  13. },
  14. "role_name": {
  15. "rules": [
  16. {
  17. "required": true
  18. },
  19. {
  20. "format": "string"
  21. }
  22. ],
  23. "label": "名称"
  24. },
  25. "permission": {
  26. "rules": [
  27. {
  28. "format": "array"
  29. }
  30. ],
  31. "label": "权限"
  32. },
  33. "comment": {
  34. "rules": [
  35. {
  36. "format": "string"
  37. }
  38. ],
  39. "label": "备注"
  40. },
  41. "create_date": {
  42. "rules": [
  43. {
  44. "format": "timestamp"
  45. }
  46. ]
  47. }
  48. }
  49. const enumConverter = {}
  50. function filterToWhere(filter, command) {
  51. let where = {}
  52. for (let field in filter) {
  53. let { type, value } = filter[field]
  54. switch (type) {
  55. case "search":
  56. if (typeof value === 'string' && value.length) {
  57. where[field] = new RegExp(value)
  58. }
  59. break;
  60. case "select":
  61. if (value.length) {
  62. let selectValue = []
  63. for (let s of value) {
  64. selectValue.push(command.eq(s))
  65. }
  66. where[field] = command.or(selectValue)
  67. }
  68. break;
  69. case "range":
  70. if (value.length) {
  71. let gt = value[0]
  72. let lt = value[1]
  73. where[field] = command.and([command.gte(gt), command.lte(lt)])
  74. }
  75. break;
  76. case "date":
  77. if (value.length) {
  78. let [s, e] = value
  79. let startDate = new Date(s)
  80. let endDate = new Date(e)
  81. where[field] = command.and([command.gte(startDate), command.lte(endDate)])
  82. }
  83. break;
  84. case "timestamp":
  85. if (value.length) {
  86. let [startDate, endDate] = value
  87. where[field] = command.and([command.gte(startDate), command.lte(endDate)])
  88. }
  89. break;
  90. }
  91. }
  92. return where
  93. }
  94. export { validator, enumConverter, filterToWhere }