uni-stat-pages.js 1.6 KB

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