瑶都万能墙
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.
 
 
 

394 lines
7.1 KiB

import http from './http.js'
import utils from '../utils/utils.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: 'GET',
limit : 500,
showLoading : true,
},
// 修改个人信息接口
updateInfo: {
url: '/token/updateInfo',
method: 'POST',
auth: true,
limit : 500,
showLoading : true,
},
// 获取个人信息接口
getInfo: {
url: '/token/getInfo',
method: 'GET',
auth: true,
limit : 500,
},
//隐私政策
getPrivacyPolicy: {
url: '/login/getPrivacyPolicy',
method: 'GET',
},
//用户协议
getUserAgreement: {
url: '/login/getUserAgreement',
method: 'GET',
},
// 不需要登录的接口
//获取分类
getClassInfo: {
url: '/city/getClassInfo',
method: 'GET',
},
//获取首页头部信息
getIndexHeaderInfo: {
url: '/city/getIndexHeaderInfo',
method: 'GET',
},
//获取banner列表
getBannerList: {
url: '/city/getBannerList',
method: 'GET',
},
//获取分类类型列表
getClassifyList: {
url: '/city/getClassifyList',
method: 'GET',
},
//获取工作信息列表
getJobPage: {
url: '/city/getJobPage',
method: 'GET',
},
//获取工作详情
getJobDetail: {
url: '/city/getJobDetail',
method: 'GET',
},
//根据分类获取租房信息列表
getRentPage: {
url: '/city/getRentPage',
method: 'GET',
},
//获取租房详情
getRentDetail: {
url: '/city/getRentDetail',
method: 'GET',
},
//获取动态帖子列表
getPostPage: {
url: '/city/getPostPage',
method: 'GET',
},
//获取帖子详情
getPostDetail: {
url: '/city/getPostDetail',
method: 'GET',
},
//获取活动列表信息
getActivityPage: {
url: '/city/getActivityPage',
method: 'GET',
},
//获取活动详情
getActivityDetail: {
url: '/city/getActivityDetail',
method: 'GET',
},
//获取活动详情
getActivityDetail: {
url: '/city/getActivityDetail',
method: 'GET',
},
//获取门店信息列表(美食)
getStorePage: {
url: '/city/getStorePage',
method: 'GET',
},
//获取门店详情(美食)
getStoreDetail: {
url: '/city/getStoreDetail',
method: 'GET',
},
//发布按钮列表
getPublishList: {
url: '/city/getPublishList',
method: 'GET',
},
//获取城市列表服务区域
getCityList: {
url: '/city/getCityList',
method: 'GET',
},
//获取景点列表带分页
getScenicPage: {
url: '/city/getScenicPage',
method: 'GET',
},
//获取景点详情
getScenicDetail: {
url: '/city/getScenicDetail',
method: 'GET',
},
//获取评论列表type-0帖子-1租房-2工作-3景点-4美食-5活动-6人找车-7车找人
getCommentPage: {
url: '/city/getCommentPage',
method: 'GET',
},
//获取江华人信息接口
getJiangHuInfo: {
url: '/city/getJiangHuInfo',
method: 'GET',
},
//获取人找车分页列表
getPeoplePage: {
url: '/city/getPeoplePage',
method: 'GET',
},
//获取人找车详情
getPeopleDetail: {
url: '/city/getPeopleDetail',
method: 'GET',
},
//获取车找人分页列表
getCatPage: {
url: '/city/getCatPage',
method: 'GET',
},
//获取车找人详情
getCatDetail: {
url: '/city/getCatDetail',
method: 'GET',
},
//查询商城信息列表带分页
getShopPingPage : {
url: '/city/getShopPingPage',
method: 'GET',
},
//根据商品标识查询商品信息详情
getShopPingDetail : {
url: '/city/getShopPingDetail',
method: 'GET',
},
//发布帖子\动态
publishPost: {
url: '/token/publishPost',
method: 'POST',
limit : 1000,
auth : true,
showLoading : true,
},
//发布评论
addComment: {
url: '/token/addComment',
method: 'POST',
limit : 1000,
auth : true,
showLoading : true,
},
//发布租房信息
publishRent: {
url: '/token/publishRent',
method: 'POST',
limit : 1000,
auth : true,
showLoading : true,
},
//发布招聘信息
publishJob: {
url: '/token/publishJob',
method: 'POST',
limit : 1000,
auth : true,
showLoading : true,
},
//发布车找人信息
publishCar: {
url: '/token/publishCar',
method: 'POST',
limit : 1000,
auth : true,
showLoading : true,
},
//查询自己发布的动态
getMyPostPage: {
url: '/token/getMyPostPage',
method: 'GET',
auth : true,
},
//删除自己发布的动态
deletePost: {
url: '/token/deletePost',
method: 'POST',
auth : true,
showLoading : true,
},
//店铺认证
companyAuthentication: {
url: '/token/companyAuthentication',
method: 'POST',
limit : 1000,
auth : true,
showLoading : true,
},
//个人认证
personalAuthentication: {
url: '/token/personalAuthentication',
method: 'POST',
limit : 1000,
auth : true,
showLoading : true,
},
//获取分享二维码
getQrCode: {
url: '/token/getQrCode',
method: 'GET',
auth : true,
},
//获取粉丝列表接口
getFansList: {
url: '/token/getFansList',
method: 'GET',
auth : true,
},
// 用户查询地址列表
getAddressList : {
url: '/token/getAddressList',
method: 'GET',
auth : true,
},
// 用户获取地址信息列表详情
getAddressDetail : {
url: '/token/getAddressDetail',
method: 'GET',
auth : true,
},
// 用户增加或者编辑地址信息
addOrEditAddress : {
url: '/token/addOrEditAddress',
method: 'POST',
auth : true,
showLoading : true,
limit : 1000,
},
// 删除地址
deleteAddress : {
url: '/token/deleteAddress',
method: 'POST',
auth : true,
showLoading : true,
},
}
const models = ['order']
models.forEach(key => {
addApiModel(require(`./model/${key}.js`).default, key)
})
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')) {
utils.toLogin()
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)
}
function addApiModel(model, key){
for(let k in model){
if(config[`${k}`]){
console.error(`重名api------model=${key},key=${k}`);
continue
}
config[`${k}`] = model[k]
// config[`${key}_${k}`] = model[k]
}
}
export default api