123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- export default {
- config: {
- baseUrl: "http://192.168.0.15:666",
- header: {
- 'Content-Type':'application/json;charset=UTF-8',
- 'Content-Type':'application/x-www-form-urlencoded'
- },
- data: {},
- method: "GET",
- dataType: "json",
- responseType: "text",
- success() {},
- fail() {},
- complete() {}
- },
- interceptor: {
- request: null,
- response: null
- },
- request(options) {
- if (!options) {
- options = {}
- }
- options.baseUrl = options.baseUrl || this.config.baseUrl
- options.dataType = options.dataType || this.config.dataType
- options.url = options.baseUrl + options.url
- options.data = options.data || {}
- options.method = options.method || this.config.method
-
-
-
-
-
- return new Promise((resolve, reject) => {
- let _config = null
-
- options.complete = (response) => {
- let statusCode = response.statusCode
- response.config = _config
- if (process.env.NODE_ENV === 'development') {
- if (statusCode === 200) {
-
- }
- }
- if (this.interceptor.response) {
- let newResponse = this.interceptor.response(response)
- if (newResponse) {
- response = newResponse
- }
- }
-
- _reslog(response)
- if (statusCode === 200) {
- resolve(response);
- } else {
- reject(response)
- }
- }
- _config = Object.assign({}, this.config, options)
- _config.requestId = new Date().getTime()
- if (this.interceptor.request) {
- this.interceptor.request(_config)
- }
-
-
- _reqlog(_config)
- if (process.env.NODE_ENV === 'development') {
-
- if (_config.data) {
-
- }
- }
- uni.request(_config);
- });
- },
- get(url, data, options) {
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.method = 'GET'
- return this.request(options)
- },
- post(url, data, options) {
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.method = 'POST'
- return this.request(options)
- },
- put(url, data, options) {
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.method = 'PUT'
- return this.request(options)
- },
- delete(url, data, options) {
- if (!options) {
- options = {}
- }
- options.url = url
- options.data = data
- options.method = 'DELETE'
- return this.request(options)
- }
- }
- function _reqlog(req) {
- if (process.env.NODE_ENV === 'development') {
-
- if (req.data) {
-
- }
- }
-
- }
- function _reslog(res) {
- let _statusCode = res.statusCode;
- if (process.env.NODE_ENV === 'development') {
-
- if (res.config.data) {
-
- }
-
- }
-
- switch(_statusCode){
- case 200:
- break;
- case 401:
- break;
- case 404:
- break;
- default:
- break;
- }
- }
|