|
|
- import http from './http.js'
- import utils from '../utils/utils.js'
-
- const config = {
- // 示例
- // wxLogin : {url : '/api/wxLogin', method : 'POST',
- // auth : false, showLoading : true, loadingTitle : '加载中...',
- // limit : 1000
- // },
-
- getConfig : {url : '/applet_index/commonConfig', method : 'GET', limit : 500},
-
-
- // 微信登录接口
- wxLogin: {
- url: '/login_common/appletLogin',
- method: 'GET',
- limit : 500,
- showLoading : true,
- },
-
- // 获取个人信息接口
- getInfo: {
- url: '/info_common/getInfo',
- method: 'GET',
- limit : 500,
- showLoading : true,
- },
- // 修改个人信息接口
- updateInfo: {
- url: '/info_common/updateInfo',
- method: 'POST',
- auth: true,
- limit : 500,
- showLoading : true,
- },
-
- // //首页-出现问题列表接口
- // problemList: {
- // url: '/applet_index/problemList',
- // method: 'GET',
- // },
-
- // //首页-文章列表接口
- // articleList: {
- // url: '/applet_index/articleList',
- // method: 'GET',
- // },
- //首页-品牌介绍接口
- getBrand: {
- url: '/applet_index/getBrand',
- method: 'GET',
- },
-
- //首页-轮播图接口
- // bannerList: {
- // url: '/applet_index/bannerList',
- // method: 'GET',
- // },
-
- //提交问答记录
- // submitLog: {
- // url: '/applet_post/submitLog',
- // method: 'POST',
- // limit : 1000,
- // showLoading : true,
- // auth: true,
- // },
-
- //提交预约信息
- submit: {
- url: '/applet_post/submit',
- method: 'POST',
- limit : 1000,
- showLoading : true,
- auth: true,
- },
- // //查询我的问答记录
- // queryMyLog: {
- // url: '/applet_post/queryMyLog',
- // method: 'GET',
- // auth: true,
- // showLoading : true,
- // },
- // //查询预约记录
- // queryReservation: {
- // url: '/applet_post/queryReservation',
- // method: 'GET',
- // auth: true,
- // },
- // //查询预约详情
- // queryReservationDetail: {
- // url: '/applet_post/queryReservationDetail',
- // method: 'GET',
- // auth: true,
- // },
- // //查询预约详情
- // queryReservationDetail: {
- // url: '/applet_post/queryReservationDetail',
- // method: 'GET',
- // auth: true,
- // },
- // //取消预约
- // cancelReservation: {
- // url: '/applet_post/cancelReservation',
- // method: 'GET',
- // auth: true,
- // showLoading : true,
- // },
-
- // //我的-评论题目列表接口
- // queryAnswerList: {
- // url: '/applet_post/queryAnswerList',
- // method: 'GET',
- // },
- // //我的-回答评论接口
- // answerComment: {
- // url: '/applet_post/answerComment',
- // method: 'POST',
- // auth : true,
- // },
-
- // =======================================================
- // 第二版本
- // =======================================================
-
- // 1、查询第一个题目接口(返回一个题目和答案列表)
- firstQuestion: {
- url: '/applet_index/firstQuestion',
- method: 'GET',
- },
- // 2、根据题目id查询题目接口(返回一个题目和答案列表)
- getProblemById: {
- url: '/applet_index/getProblemById',
- method: 'GET',
- limit : 500,
- },
- // 3、根据用户选择的答案id列表查询出获得的称号接口(返回称号图片、文章列表)
- getTitleByIds: {
- url: '/applet_index/getTitleByIds',
- method: 'GET',
- limit : 500,
- },
-
-
- // 查询所有隐私政策列表
- privacyPolicyList: {
- url: '/applet_index/privacyPolicyList',
- method: 'GET',
- limit : 500,
- },
- }
-
-
-
- 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){
- // uni.showToast({
- // title: '请勿点击过快',
- // icon: 'none',
- // })
- return
- }
- uni.setStorageSync(storageKey, new Date().getTime())
- }
-
- //必须登录
- if (req.auth) {
- if (!uni.getStorageSync('token')) {
- utils.toLogin()
- console.error('需要登录')
- return
- }
- }
-
- http.http(req.url, data, callback, req.method,
- loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
- }
-
-
-
- export default api
|