艺易修小程序24.08.21
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.

67 lines
1.6 KiB

8 months ago
7 months ago
8 months ago
  1. import http from './http.js'
  2. const config = {
  3. // 示例
  4. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  5. // auth : false, showLoading : true, loadingTitle : '加载中...',
  6. // limit : 1000
  7. // },
  8. getConfig : {url : '/api/getConfig', method : 'GET', limit : 500},
  9. // 登录接口
  10. loginLogin: { url: '/cheer/login/login', method: 'GET', },
  11. //增加报修单
  12. addSchoolOrder : {url : '/school-api/addSchoolOrder', method : 'GET', limit : 500},
  13. //驳回
  14. editSchoolOrderError : {url : '/school-api/editSchoolOrderError', method : 'GET', limit : 500},
  15. //结单
  16. editSchoolOrderSuccess : {url : '/school-api/editSchoolOrderSuccess', method : 'GET', limit : 500},
  17. //报修列表
  18. getSchoolOrderPage : {url : '/school-api/getSchoolOrderPage', method : 'GET', limit : 500},
  19. }
  20. export function api(key, data, callback, loadingTitle){
  21. let req = config[key]
  22. if (!req) {
  23. console.error('无效key' + key);
  24. return
  25. }
  26. if(typeof callback == 'string'){
  27. loadingTitle = callback
  28. }
  29. if(typeof data == 'function'){
  30. callback = data
  31. data = {}
  32. }
  33. // 接口限流
  34. if(req.limit){
  35. let storageKey = 'limit:' + req.url
  36. let storage = uni.getStorageSync(storageKey)
  37. if(storage && new Date().getTime() - parseInt(storage) < req.limit){
  38. return
  39. }
  40. uni.setStorageSync(storageKey, new Date().getTime())
  41. }
  42. //必须登录
  43. if (req.auth) {
  44. if (!uni.getStorageSync('token')) {
  45. uni.navigateTo({
  46. url: '/pages/login/mobile'
  47. })
  48. console.error('需要登录')
  49. return
  50. }
  51. }
  52. http.http(req.url, data, callback, req.method,
  53. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  54. }
  55. export default api