|
@ -1,5 +1,9 @@ |
|
|
import http from './http.js' |
|
|
import http from './http.js' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let limit = {} |
|
|
|
|
|
let debounce = {} |
|
|
|
|
|
|
|
|
const config = { |
|
|
const config = { |
|
|
// 示例
|
|
|
// 示例
|
|
|
// wxLogin : {url : '/api/wxLogin', method : 'POST',
|
|
|
// wxLogin : {url : '/api/wxLogin', method : 'POST',
|
|
@ -108,15 +112,9 @@ const config = { |
|
|
method: 'GET', |
|
|
method: 'GET', |
|
|
showLoading: true, |
|
|
showLoading: true, |
|
|
}, |
|
|
}, |
|
|
// 根据角色id获取视频列表
|
|
|
|
|
|
queryVedioBySpot: { |
|
|
|
|
|
url: '/info/queryVedioBySpot', |
|
|
|
|
|
method: 'GET', |
|
|
|
|
|
showLoading: true, |
|
|
|
|
|
}, |
|
|
|
|
|
// 获取视频列表
|
|
|
// 获取视频列表
|
|
|
queryVideoList: { |
|
|
|
|
|
url: '/info/queryVideoList', |
|
|
|
|
|
|
|
|
queryVedioById: { |
|
|
|
|
|
url: '/info/queryVedioById', |
|
|
method: 'GET', |
|
|
method: 'GET', |
|
|
showLoading: true, |
|
|
showLoading: true, |
|
|
}, |
|
|
}, |
|
@ -143,24 +141,47 @@ export function api(key, data, callback, loadingTitle) { |
|
|
|
|
|
|
|
|
// 接口限流
|
|
|
// 接口限流
|
|
|
if (req.limit) { |
|
|
if (req.limit) { |
|
|
let storageKey = 'limit:' + req.url |
|
|
|
|
|
let storage = uni.getStorageSync(storageKey) |
|
|
|
|
|
if (storage && new Date().getTime() - parseInt(storage) < req.limit) { |
|
|
|
|
|
|
|
|
let storageKey = req.url |
|
|
|
|
|
let storage = limit[storageKey] |
|
|
|
|
|
if (storage && new Date().getTime() - storage < req.limit) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
uni.setStorageSync(storageKey, new Date().getTime()) |
|
|
|
|
|
|
|
|
limit[storageKey] = new Date().getTime() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//必须登录
|
|
|
//必须登录
|
|
|
if (req.auth) { |
|
|
if (req.auth) { |
|
|
if (!uni.getStorageSync('token')) { |
|
|
if (!uni.getStorageSync('token')) { |
|
|
uni.navigateTo({ |
|
|
uni.navigateTo({ |
|
|
url: '/pages/login/mobile' |
|
|
|
|
|
|
|
|
url: '/pages_order/auth/wxLogin' |
|
|
}) |
|
|
}) |
|
|
console.error('需要登录') |
|
|
console.error('需要登录') |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 接口防抖
|
|
|
|
|
|
if(req.debounce){ |
|
|
|
|
|
|
|
|
|
|
|
let storageKey = req.url |
|
|
|
|
|
let storage = debounce[storageKey] |
|
|
|
|
|
|
|
|
|
|
|
if (storage) { |
|
|
|
|
|
clearTimeout(storage) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
debounce[storageKey] = setTimeout(() => { |
|
|
|
|
|
|
|
|
|
|
|
clearTimeout(storage) |
|
|
|
|
|
|
|
|
|
|
|
delete debounce[storageKey] |
|
|
|
|
|
|
|
|
|
|
|
http.http(req.url, data, callback, req.method, |
|
|
|
|
|
loadingTitle || req.showLoading, loadingTitle || req.loadingTitle) |
|
|
|
|
|
}, req.debounce) |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
http.http(req.url, data, callback, req.method, |
|
|
http.http(req.url, data, callback, req.method, |
|
|
loadingTitle || req.showLoading, loadingTitle || req.loadingTitle) |
|
|
loadingTitle || req.showLoading, loadingTitle || req.loadingTitle) |
|
|