|
|
- 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},
- // 登录接口
- loginLogin: { url: '/api/login/login', method: 'GET' , limit : 500 },
- //修改个人信息接口
- updateInfo: { url: '/api/info/updateInfo', method: 'POST' , limit : 500 },
- //获取用户信息接口
- getInfo: { url: '/api/info/getInfo', method: 'GET' , limit : 500 },
- //增加报修单
- addSchoolOrder : {url : '/school-api/addSchoolOrder', method : 'GET', limit : 500},
- //驳回
- editSchoolOrderError : {url : '/school-api/editSchoolOrderError', method : 'GET', limit : 500},
- //结单
- editSchoolOrderSuccess : {url : '/school-api/editSchoolOrderSuccess', method : 'GET', limit : 500},
- //报修列表
- getSchoolOrderPage : {url : '/school-api/getSchoolOrderPage', 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){
- 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
|