123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import Vue from 'vue'
- const config = {
- timeout: 15000,
- baseURL: 'http://127.0.0.1:7000',
- headers: {
- 'Content-Type':'application/x-www-form-urlencoded'
- }
- }
- export const Method = {
- GET: 'GET',
- POST: 'POST',
- PUT: 'PUT',
- DELETE: 'DELETE'
- }
- function service(options) {
- let url = config.baseURL + '/' + options.url
- if (options.url.includes("http")){
- url = options.url
- }
- let headers = config.headers
- if (options.config.isJson){
- headers['Content-Type']='application/json'
- } else {
- headers['Content-Type']='application/x-www-form-urlencoded'
- }
- if (options.config.loading){
- uni.showLoading()
- }
- return new Promise((resolve,reject)=>{
- // console.log(options, config);
- uni.request({
- url: url,
- data: options.params,
- header: headers,
- timeout: config.timeout,
- method: options.config.method,
- success(res) {
- uni.hideLoading()
- if (res.statusCode == 200){
- resolve(res.data)
- } else{
- if (url.indexOf("/wx_mobile") === -1) {
- Vue.prototype.$message.error(res.data.message)
- }
- reject(res)
- }
- },
- fail(err){
- uni.hideLoading()
- console.log(err);
- Vue.prototype.$message.error(err.data.message)
- reject(err)
- }
- });
- })
- }
- export default function request(options){
- return service(options)
- }
|