import http from './http.js'
|
|
|
|
|
|
let limit = {}
|
|
let debounce = {}
|
|
|
|
const config = {
|
|
// 示例
|
|
// wxLogin : {url : '/api/wxLogin', method : 'POST',
|
|
// auth : false, showLoading : true, loadingTitle : '加载中...',
|
|
// limit : 1000
|
|
// },
|
|
|
|
getConfig : {url : '/api/getConfig', method : 'GET', limit : 500},
|
|
|
|
|
|
// 微信登录接口
|
|
wxLogin: {
|
|
url: '/login/login',
|
|
method: 'POST',
|
|
limit : 500,
|
|
showLoading : true,
|
|
},
|
|
// 修改个人信息接口
|
|
updateInfo: {
|
|
url: '/info/updateInfo',
|
|
method: 'POST',
|
|
auth: true,
|
|
limit : 500,
|
|
showLoading : true,
|
|
},
|
|
//隐私政策
|
|
getPrivacyPolicy: {
|
|
url: '/login/getPrivacyPolicy',
|
|
method: 'GET',
|
|
},
|
|
//用户协议
|
|
getUserAgreement: {
|
|
url: '/login/getUserAgreement',
|
|
method: 'GET',
|
|
},
|
|
|
|
|
|
// 不需要登录的接口
|
|
|
|
|
|
//获取分类
|
|
getClassInfo: {
|
|
url: '/api/city/getClassInfo',
|
|
method: 'GET',
|
|
},
|
|
//获取首页头部信息
|
|
getIndexHeaderInfo: {
|
|
url: '/api/city/getIndexHeaderInfo',
|
|
method: 'GET',
|
|
},
|
|
//获取工作信息列表
|
|
getJobPage: {
|
|
url: '/api/city/getJobPage',
|
|
method: 'GET',
|
|
},
|
|
//根据分类获取租房信息列表
|
|
getRentPage: {
|
|
url: '/api/city/getRentPage',
|
|
method: 'GET',
|
|
},
|
|
//根据分类获取动态帖子列表带分页
|
|
getPostPage: {
|
|
url: '/api/city/getPostPage',
|
|
method: 'GET',
|
|
},
|
|
}
|
|
|
|
|
|
|
|
export function api(key, data, callback, loadingTitle) {
|
|
let req = config[key]
|
|
|
|
if (!req) {
|
|
console.error('无效key--------' + key);
|
|
return
|
|
}
|
|
|
|
if (typeof callback == 'string') {
|
|
loadingTitle = callback
|
|
}
|
|
|
|
if (typeof data == 'function') {
|
|
callback = data
|
|
data = {}
|
|
}
|
|
|
|
// 接口限流
|
|
if (req.limit) {
|
|
let storageKey = req.url
|
|
let storage = limit[storageKey]
|
|
if (storage && new Date().getTime() - storage < req.limit) {
|
|
return
|
|
}
|
|
limit[storageKey] = new Date().getTime()
|
|
}
|
|
|
|
//必须登录
|
|
if (req.auth) {
|
|
if (!uni.getStorageSync('token')) {
|
|
uni.navigateTo({
|
|
url: '/pages_order/auth/wxLogin'
|
|
})
|
|
console.error('需要登录')
|
|
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,
|
|
loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
|
|
}
|
|
|
|
|
|
|
|
export default api
|