123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // 请求后端服务器工具类
- import Vue from 'vue'
- import { TOKEN_NAME } from "./cacheConstant";
- const baseURL = "http://114.115.167.11:8081/api"
- export function request(url, data, method) {
- console.log(url,data,method)
- // 赋值token
- const token = Vue.prototype.$token
- console.log()
- console.log(!token)
- if(token){
- var hander = {
- 'Authorization': Vue.prototype.$token,
- }
- }else{
- var hander = {}
- }
- // 默认执行get方法
- method = method===undefined ? 'post' : method
- wx.showNavigationBarLoading()
- return new Promise((resove, reject) => {
- uni.request({
- url: baseURL + url,
- method,
- data,
- header: hander,
- success: function (res) {
- const data = res.data
- // 对错误进行拦截提示
- if (data.code != 200) {
- uni.showToast({
- title: data.msg,
- icon: 'none',
- duration: 2000
- })
- reject()
- }
- resove(data.data);
- },
- fail: function (msg) {
- console.log('请求失败=======', msg)
- uni.showToast({
- title: "网络异常,连接服务器失败",
- icon: 'none',
- duration: 2000
- })
- reject()
- },
- complete: function () {
- uni.hideNavigationBarLoading();
- }
- })
- })
- }
|