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

75 lines
2.0 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 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: '/school/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. getActorGoList : {url : '/school-api/getActorGoList', method : 'GET', limit : 500},
  25. //获取室号
  26. getFloorList : {url : '/school-api/getFloorList', method : 'GET', limit : 500},
  27. }
  28. export function api(key, data, callback, loadingTitle){
  29. let req = config[key]
  30. if (!req) {
  31. console.error('无效key' + key);
  32. return
  33. }
  34. if(typeof callback == 'string'){
  35. loadingTitle = callback
  36. }
  37. if(typeof data == 'function'){
  38. callback = data
  39. data = {}
  40. }
  41. // 接口限流
  42. if(req.limit){
  43. let storageKey = 'limit:' + req.url
  44. let storage = uni.getStorageSync(storageKey)
  45. if(storage && new Date().getTime() - parseInt(storage) < req.limit){
  46. return
  47. }
  48. uni.setStorageSync(storageKey, new Date().getTime())
  49. }
  50. //必须登录
  51. if (req.auth) {
  52. if (!uni.getStorageSync('token')) {
  53. uni.navigateTo({
  54. url: '/pages/login/mobile'
  55. })
  56. console.error('需要登录')
  57. return
  58. }
  59. }
  60. http.http(req.url, data, callback, req.method,
  61. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  62. }
  63. export default api