MCPcopy Create free account
hub / github.com/CoderOpen/waimai / Request

Class Request

front/utils/luch-request/core/Request.js:16–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14import { isBoolean } from '../utils'
15
16export default class Request {
17 config = {
18 baseUrl: '',
19 header: {},
20 method: 'GET',
21 dataType: 'json',
22 // #ifndef MP-ALIPAY || APP-PLUS
23 responseType: 'text',
24 // #endif
25 custom: {},
26 // #ifdef MP-ALIPAY || MP-WEIXIN
27 timeout: 30000,
28 // #endif
29 // #ifdef APP-PLUS
30 sslVerify: true,
31 // #endif
32 // #ifdef H5
33 withCredentials: false
34 // #endif
35 }
36
37 /**
38 * @property {Function} request 请求拦截器
39 * @property {Function} response 响应拦截器
40 * @type {{request: Request.interceptor.request, response: Request.interceptor.response}}
41 */
42 interceptor = {
43 /**
44 * @param {Request~requestCallback} cb - 请求之前拦截,接收一个函数(config, cancel)=> {return config}。第一个参数为全局config,第二个参数为函数,调用则取消本次请求。
45 */
46 request: (cb) => {
47 if (cb) {
48 this.requestBeforeFun = cb
49 }
50 },
51 /**
52 * @param {Request~responseCallback} cb 响应拦截器,对响应数据做点什么
53 * @param {Request~responseErrCallback} ecb 响应拦截器,对响应错误做点什么
54 */
55 response: (cb, ecb) => {
56 if (cb) {
57 this.requestComFun = cb
58 }
59 if (ecb) {
60 this.requestComFail = ecb
61 }
62 }
63 }
64
65 requestBeforeFun = (config) => {
66 return config
67 }
68
69 requestComFun = (response) => {
70 return response
71 }
72
73 requestComFail = (response) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected