1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import config from "../config/config.js";
- import store from "../../store/index.js"
- import msg from './message.js'
- import statusCode from './statusCode.js'
- import utils from './util.js'
- import storage from './storage.js'
- export default{
- config:{
- header: {
- TargetCode: 3
- },
- data: {},
- url: config.baseUrl,
- method: "POST",
- timeout: 10000
- },
- async request(options = {}){
- let token = await storage.getStorageSync('token') || ''
- options.data.token = token
- !options.data.isUnShowLoading && msg.showLoading();
- return new Promise((resolve,reject)=>{
- options.header = options.header || this.config.header
- options.timeout = options.timeout || this.config.timeout
- options.method = options.method || this.config.method
- options.data = options.data || this.config.data
- options.url = options.url
- options.success = (response) => {
- !options.data.isUnShowLoading && msg.hideLoading()
- if (response.statusCode === 404) {
- console.log(options.url);
- return msg.showToast('未知的请求!')
- }
- let res = response.data
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return resolve(res);
- }
- options.fail = (err) => {
- console.log('请求失败')
- console.log(err)
-
- msg.showToast('请求失败,请检查网络是否正常!')
- msg.hideLoading()
- return reject(err)
- }
- uni.request(options)
- });
- },
- post2(url,data,options={}){
-
- options.url = config.baseUrl + url;
-
-
- options.data = data;
- options.method = 'POST';
- return this.request(options)
- },
- post(url,data,options={}){
-
- options.url = config.baseUrl + url;
-
-
- options.data = data;
- options.method = 'POST';
- return this.request(options)
- },
- get(url,data,options={}){
- options.url = config.baseUrl + url;
- options.method = 'GET';
- return this.request(options)
-
- }
- }
|