工单小程序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.

170 lines
3.3 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 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. showLoading : true,
  55. },
  56. //工单信息-修改工单
  57. updateTemplate: {
  58. url: '/workorder/template/updateTemplate',
  59. method: 'GET',
  60. auth : true,
  61. showLoading : true,
  62. },
  63. //工单信息-工序卡3详情
  64. queryStepThree: {
  65. url: '/workorder/template/queryStepThree',
  66. method: 'GET',
  67. auth : true,
  68. },
  69. //工单信息-修改常规参数-工序卡1(选配)
  70. updateGeneralStepOne: {
  71. url: '/workorder/template/updateGeneralStepOne',
  72. method: 'POST',
  73. auth : true,
  74. },
  75. //工单信息-修改工序参数-工序卡1(选配)
  76. updateParamStepOne: {
  77. url: '/workorder/template/updateParamStepOne',
  78. method: 'POST',
  79. auth : true,
  80. },
  81. }
  82. export function api(key, data, callback, loadingTitle) {
  83. let req = config[key]
  84. if (!req) {
  85. console.error('无效key--------' + key);
  86. return
  87. }
  88. if (typeof callback == 'string') {
  89. loadingTitle = callback
  90. }
  91. if (typeof data == 'function') {
  92. callback = data
  93. data = {}
  94. }
  95. // 接口限流
  96. if (req.limit) {
  97. let storageKey = req.url
  98. let storage = limit[storageKey]
  99. if (storage && new Date().getTime() - storage < req.limit) {
  100. return
  101. }
  102. limit[storageKey] = new Date().getTime()
  103. }
  104. //必须登录
  105. if (req.auth) {
  106. if (!uni.getStorageSync('token')) {
  107. utils.toLogin()
  108. console.error('需要登录')
  109. return
  110. }
  111. }
  112. // 接口防抖
  113. if (req.debounce) {
  114. let storageKey = req.url
  115. let storage = debounce[storageKey]
  116. if (storage) {
  117. clearTimeout(storage)
  118. }
  119. debounce[storageKey] = setTimeout(() => {
  120. clearTimeout(storage)
  121. delete debounce[storageKey]
  122. http.http(req.url, data, callback, req.method,
  123. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  124. }, req.debounce)
  125. return
  126. }
  127. http.http(req.url, data, callback, req.method,
  128. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  129. }
  130. function addApiModel(model, key) {
  131. for (let k in model) {
  132. if (config[`${k}`]) {
  133. console.error(`重名api------model=${key},key=${k}`);
  134. continue
  135. }
  136. config[`${k}`] = model[k]
  137. // config[`${key}_${k}`] = model[k]
  138. }
  139. }
  140. models.forEach(key => {
  141. addApiModel(require(`./model/${key}.js`).default, key)
  142. })
  143. export default api