工单小程序2024-11-20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
2.8 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. import http from './http.js'
  2. import utils from '../utils/utils.js'
  3. let limit = {}
  4. let debounce = {}
  5. const models = ['login', 'user', 'config']
  6. const config = {
  7. //轮播图-轮播图列表
  8. queryBannerList: {
  9. url: '/workorder/banner/queryBannerList',
  10. method: 'GET',
  11. auth : true,
  12. },
  13. //工单信息-查询工单列表
  14. queryTemplateList: {
  15. url: '/workorder/template/queryTemplateList',
  16. method: 'GET',
  17. auth : true,
  18. },
  19. //公告信息-查询公告列表
  20. queryNewsList: {
  21. url: '/workorder/news/queryNewsList',
  22. method: 'GET',
  23. auth : true,
  24. },
  25. // 公告信息-根据id查询公告信息
  26. queryNewsById: {
  27. url: '/workorder/news/queryNewsById',
  28. method: 'GET',
  29. auth : true,
  30. },
  31. //工单信息-工序卡1(选配)详情
  32. queryStepOne: {
  33. url: '/workorder/template/queryStepOne',
  34. method: 'GET',
  35. auth : true,
  36. },
  37. //工单信息-工序卡2详情
  38. queryStepTwo: {
  39. url: '/workorder/template/queryStepTwo',
  40. method: 'GET',
  41. auth : true,
  42. },
  43. //收藏信息-我的收藏
  44. queryCollectionList: {
  45. url: '/workorder/collection/queryCollectionList',
  46. method: 'GET',
  47. auth : true,
  48. },
  49. //工单信息-根据id查询工单详情
  50. queryTemplateById: {
  51. url: '/workorder/template/queryTemplateById',
  52. method: 'GET',
  53. auth : true,
  54. },
  55. //工单信息-工序卡3详情
  56. queryStepThree: {
  57. url: '/workorder/template/queryStepThree',
  58. method: 'GET',
  59. auth : true,
  60. },
  61. }
  62. export function api(key, data, callback, loadingTitle) {
  63. let req = config[key]
  64. if (!req) {
  65. console.error('无效key--------' + key);
  66. return
  67. }
  68. if (typeof callback == 'string') {
  69. loadingTitle = callback
  70. }
  71. if (typeof data == 'function') {
  72. callback = data
  73. data = {}
  74. }
  75. // 接口限流
  76. if (req.limit) {
  77. let storageKey = req.url
  78. let storage = limit[storageKey]
  79. if (storage && new Date().getTime() - storage < req.limit) {
  80. return
  81. }
  82. limit[storageKey] = new Date().getTime()
  83. }
  84. //必须登录
  85. if (req.auth) {
  86. if (!uni.getStorageSync('token')) {
  87. utils.toLogin()
  88. console.error('需要登录')
  89. return
  90. }
  91. }
  92. // 接口防抖
  93. if (req.debounce) {
  94. let storageKey = req.url
  95. let storage = debounce[storageKey]
  96. if (storage) {
  97. clearTimeout(storage)
  98. }
  99. debounce[storageKey] = setTimeout(() => {
  100. clearTimeout(storage)
  101. delete debounce[storageKey]
  102. http.http(req.url, data, callback, req.method,
  103. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  104. }, req.debounce)
  105. return
  106. }
  107. http.http(req.url, data, callback, req.method,
  108. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  109. }
  110. function addApiModel(model, key) {
  111. for (let k in model) {
  112. if (config[`${k}`]) {
  113. console.error(`重名api------model=${key},key=${k}`);
  114. continue
  115. }
  116. config[`${k}`] = model[k]
  117. // config[`${key}_${k}`] = model[k]
  118. }
  119. }
  120. models.forEach(key => {
  121. addApiModel(require(`./model/${key}.js`).default, key)
  122. })
  123. export default api