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

169 lines
3.2 KiB

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