import { Api_url } from './config' // import {Token} from './token.js' // var token = new Token(); export default { async post(url, param, yanci = false) { // wx.showLoading(); // setTimeout(() => { // wx.hideLoading(); // }, 3000) const res = await this.uni_request(url, param, 'post') return res; }, async get(url, param, yanci = false) { // wx.showLoading(); // setTimeout(() => { // wx.hideLoading(); // }, 3000) const res = await this.uni_request(url, param, 'get') return res; }, async put(url, param) { // wx.showLoading(); // setTimeout(() => { // wx.hideLoading(); // }, 3000) const res = await this.uni_request(url, param, 'put') return res; }, uni_request(url, param, method, again_quest = false) { const that = this uni.showLoading({ title:'加载中...' }) return new Promise((cback, reject) => { console.log(Api_url + url) uni.request({ url: Api_url + url, data: param, method: method, header: { 'token': uni.getStorageSync("token") }, }).then(data => { //data为一个数组,数组第一项为错误信息,第二项为返回数据 var [error, res] = data; uni.hideLoading() var res_code = res.statusCode.toString(); var res_codes = res.data.code.toString(); if (res_code.charAt(0) == 2) { if (res_code == 200) { if (res_codes == 401) { uni.navigateTo({ url: '/pages/student/login/login' }) }else{ cback(res.data); } } else { console.log('201', url) uni.showToast({ title: res.data.msg, icon: 'none' }) } } else { if (res_codes == 401) { uni.navigateTo({ url: '/pages/student/login/login' }) } else { console.log('400/500', url, error, res) uni.showToast({ title: res.data.msg ? res.data.msg : '请求异常', icon: 'none' }) } } }).catch(err => { console.log('catch:', err); }) }) }, }