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

71 lines
1.8 KiB

8 months ago
7 months ago
7 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: '/api/login/login', method: 'GET' , limit : 500 },
  11. //修改个人信息接口
  12. updateInfo: { url: '/api/info/updateInfo', method: 'POST' , limit : 500 },
  13. //获取用户信息接口
  14. getInfo: { url: '/api/info/getInfo', method: 'GET' , limit : 500 },
  15. //增加报修单
  16. addSchoolOrder : {url : '/school-api/addSchoolOrder', method : 'GET', limit : 500},
  17. //驳回
  18. editSchoolOrderError : {url : '/school-api/editSchoolOrderError', method : 'GET', limit : 500},
  19. //结单
  20. editSchoolOrderSuccess : {url : '/school-api/editSchoolOrderSuccess', method : 'GET', limit : 500},
  21. //报修列表
  22. getSchoolOrderPage : {url : '/school-api/getSchoolOrderPage', method : 'GET', limit : 500},
  23. }
  24. export function api(key, data, callback, loadingTitle){
  25. let req = config[key]
  26. if (!req) {
  27. console.error('无效key' + key);
  28. return
  29. }
  30. if(typeof callback == 'string'){
  31. loadingTitle = callback
  32. }
  33. if(typeof data == 'function'){
  34. callback = data
  35. data = {}
  36. }
  37. // 接口限流
  38. if(req.limit){
  39. let storageKey = 'limit:' + req.url
  40. let storage = uni.getStorageSync(storageKey)
  41. if(storage && new Date().getTime() - parseInt(storage) < req.limit){
  42. return
  43. }
  44. uni.setStorageSync(storageKey, new Date().getTime())
  45. }
  46. //必须登录
  47. if (req.auth) {
  48. if (!uni.getStorageSync('token')) {
  49. uni.navigateTo({
  50. url: '/pages/login/mobile'
  51. })
  52. console.error('需要登录')
  53. return
  54. }
  55. }
  56. http.http(req.url, data, callback, req.method,
  57. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  58. }
  59. export default api