import http from './http.js'
|
|
|
|
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: 'GET',
|
|
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',
|
|
},
|
|
|
|
/**
|
|
* 首页相关接口
|
|
*/
|
|
|
|
// 添加建议
|
|
addAdvice: {
|
|
url: '/info/addAdvice',
|
|
method: 'POST',
|
|
limit: 500,
|
|
showLoading: true,
|
|
},
|
|
// 添加志愿者
|
|
addVolunteer: {
|
|
url: '/info/addVolunteer',
|
|
method: 'POST',
|
|
limit: 500,
|
|
showLoading: true,
|
|
},
|
|
// 获取景区列表
|
|
queryAreaList: {
|
|
url: '/info/queryAreaList',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 根据id获取文章详情
|
|
queryArticleById: {
|
|
url: '/info/queryArticleById',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 获取文章列表
|
|
queryArticleList: {
|
|
url: '/info/queryArticleList',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 根据分类获取文章列表
|
|
queryArticleListByType: {
|
|
url: '/info/queryArticleListByType',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 获取banner图列表
|
|
queryBannerList: {
|
|
url: '/info/queryBannerList',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 根据角色Id获取角色信息详情
|
|
queryRoleInfoById: {
|
|
url: '/info/queryRoleInfoById',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 根据角色类型获取角色信息列表-讲解员-达人-摄影师
|
|
queryRoleInfoList: {
|
|
url: '/info/queryRoleInfoList',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 根据景区id获取该景区下的地点列表:景点-厕所-美食店铺-民宿
|
|
querySpotList: {
|
|
url: '/info/querySpotList',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 根据角色id获取视频列表
|
|
queryVedioBySpot: {
|
|
url: '/info/queryVedioBySpot',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
// 获取视频列表
|
|
queryVideoList: {
|
|
url: '/info/queryVideoList',
|
|
method: 'GET',
|
|
showLoading: true,
|
|
},
|
|
}
|
|
|
|
|
|
|
|
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 = 'limit:' + req.url
|
|
let storage = uni.getStorageSync(storageKey)
|
|
if (storage && new Date().getTime() - parseInt(storage) < req.limit) {
|
|
return
|
|
}
|
|
uni.setStorageSync(storageKey, new Date().getTime())
|
|
}
|
|
|
|
//必须登录
|
|
if (req.auth) {
|
|
if (!uni.getStorageSync('token')) {
|
|
uni.navigateTo({
|
|
url: '/pages/login/mobile'
|
|
})
|
|
console.error('需要登录')
|
|
return
|
|
}
|
|
}
|
|
|
|
http.http(req.url, data, callback, req.method,
|
|
loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
|
|
}
|
|
|
|
|
|
|
|
export default api
|