uni-id-permissions.js 1.9 KB

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