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

212 lines
4.4 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 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. //工单信息-工序卡3详情
  44. queryStepThree: {
  45. url: '/workorder/template/queryStepThree',
  46. method: 'GET',
  47. auth : true,
  48. },
  49. //工单信息-工序卡4(总成)详情
  50. queryStepFour: {
  51. url: '/workorder/template/queryStepFour',
  52. method: 'GET',
  53. auth : true,
  54. },
  55. //收藏信息-我的收藏
  56. queryCollectionList: {
  57. url: '/workorder/collection/queryCollectionList',
  58. method: 'GET',
  59. auth : true,
  60. },
  61. //工单信息-根据id查询工单详情
  62. queryTemplateById: {
  63. url: '/workorder/template/queryTemplateById',
  64. method: 'GET',
  65. auth : true,
  66. showLoading : true,
  67. },
  68. //工单信息-修改工单
  69. updateTemplate: {
  70. url: '/workorder/template/updateTemplate',
  71. method: 'POST',
  72. auth : true,
  73. showLoading : true,
  74. },
  75. //工单信息-修改常规参数-工序卡1(选配)
  76. updateGeneralStepOne: {
  77. url: '/workorder/template/updateGeneralStepOne',
  78. method: 'POST',
  79. auth : true,
  80. },
  81. //工单信息-修改工序参数-工序卡1(选配)
  82. updateParamStepOne: {
  83. url: '/workorder/template/updateParamStepOne',
  84. method: 'POST',
  85. auth : true,
  86. },
  87. //工单信息-修改常规参数-工序卡2
  88. updateGeneralStepTwo: {
  89. url: '/workorder/template/updateGeneralStepTwo',
  90. method: 'POST',
  91. auth : true,
  92. },
  93. //工单信息-修改工序参数-工序卡2
  94. updateParamStepTwo: {
  95. url: '/workorder/template/updateParamStepTwo',
  96. method: 'POST',
  97. auth : true,
  98. },
  99. //工单信息-修改常规参数-工序卡3
  100. updateGeneralStepThree: {
  101. url: '/workorder/template/updateGeneralStepThree',
  102. method: 'POST',
  103. auth : true,
  104. },
  105. //工单信息-修改工序参数-工序卡3
  106. updateParamStepThree: {
  107. url: '/workorder/template/updateParamStepThree',
  108. method: 'POST',
  109. auth : true,
  110. },
  111. //工单信息-修改常规参数-工序卡4(总成)
  112. updateGeneralStepFour: {
  113. url: '/workorder/template/updateGeneralStepFour',
  114. method: 'POST',
  115. auth : true,
  116. },
  117. //工单信息-修改工序参数-工序卡4(总成)
  118. updateParamStepFour: {
  119. url: '/workorder/template/updateParamStepFour',
  120. method: 'POST',
  121. auth : true,
  122. },
  123. }
  124. export function api(key, data, callback, loadingTitle) {
  125. let req = config[key]
  126. if (!req) {
  127. console.error('无效key--------' + key);
  128. return
  129. }
  130. if (typeof callback == 'string') {
  131. loadingTitle = callback
  132. }
  133. if (typeof data == 'function') {
  134. callback = data
  135. data = {}
  136. }
  137. // 接口限流
  138. if (req.limit) {
  139. let storageKey = req.url
  140. let storage = limit[storageKey]
  141. if (storage && new Date().getTime() - storage < req.limit) {
  142. return
  143. }
  144. limit[storageKey] = new Date().getTime()
  145. }
  146. //必须登录
  147. if (req.auth) {
  148. if (!uni.getStorageSync('token')) {
  149. utils.toLogin()
  150. console.error('需要登录')
  151. return
  152. }
  153. }
  154. // 接口防抖
  155. if (req.debounce) {
  156. let storageKey = req.url
  157. let storage = debounce[storageKey]
  158. if (storage) {
  159. clearTimeout(storage)
  160. }
  161. debounce[storageKey] = setTimeout(() => {
  162. clearTimeout(storage)
  163. delete debounce[storageKey]
  164. http.http(req.url, data, callback, req.method,
  165. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  166. }, req.debounce)
  167. return
  168. }
  169. http.http(req.url, data, callback, req.method,
  170. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  171. }
  172. function addApiModel(model, key) {
  173. for (let k in model) {
  174. if (config[`${k}`]) {
  175. console.error(`重名api------model=${key},key=${k}`);
  176. continue
  177. }
  178. config[`${k}`] = model[k]
  179. // config[`${key}_${k}`] = model[k]
  180. }
  181. }
  182. models.forEach(key => {
  183. addApiModel(require(`./model/${key}.js`).default, key)
  184. })
  185. export default api