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

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