知识付费微信小程序
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.

70 lines
1.7 KiB

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