帧视界壹通告,付费看视频的微信小程序
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.

69 lines
1.6 KiB

11 months ago
11 months ago
11 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. //获取banner列表
  10. indexGetBanner : {url : '/api/index/getBanner', method : 'GET'},
  11. //获取认证演员
  12. indexGetActorList : {url : '/api/index/getActorList', method : 'GET'},
  13. //获取动态列表带分页
  14. indexGetTrendsPage : {url : '/api/index/getTrendsPage', method : 'GET'},
  15. //获取动态列表带分页
  16. indexGetActorSetPage : {url : '/api/index/getActorSetPage', method : 'GET'},
  17. //获取动态详情
  18. indexGetTrendsDetail : {url : '/api/index/getTrendsDetail', method : 'GET'},
  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/auth/login'
  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