fix(mockManager): 修复mock成功后仍然发出请求的问题
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<p align="center"><img src="./image/logo.png" alt="weRequest" height="160"/></p>
|
||||
<h2 align="center">v1.2.3</h2>
|
||||
<h2 align="center">v1.2.4</h2>
|
||||
<p align="center"><b>解决繁琐的小程序会话管理,一款自带登录态管理的网络请求组件。</b></p>
|
||||
|
||||
|
||||
|
||||
2
build/module/mockManager.d.ts
vendored
2
build/module/mockManager.d.ts
vendored
@@ -1,5 +1,5 @@
|
||||
import { IRequestOption, IUploadFileOption } from "../interface";
|
||||
declare function get(obj: IRequestOption | IUploadFileOption, method: "request" | "uploadFile"): any;
|
||||
declare function get(obj: IRequestOption | IUploadFileOption): any;
|
||||
declare const _default: {
|
||||
get: typeof get;
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
4
build/weRequest.min.js
vendored
4
build/weRequest.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "we-request",
|
||||
"version": "1.2.3",
|
||||
"version": "1.2.4",
|
||||
"description": "本工具通过拓展小程序的wx.request,让开发者通过简单的配置,实现自动管理登录态等功能",
|
||||
"keywords": [
|
||||
"登录态",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import config from '../store/config'
|
||||
import loading from '../util/loading'
|
||||
import responseHandler from './responseHandler'
|
||||
import { IRequestOption, IUploadFileOption } from "../interface"
|
||||
|
||||
function get(obj: IRequestOption | IUploadFileOption, method: "request" | "uploadFile"): any {
|
||||
function get(obj: IRequestOption | IUploadFileOption): any {
|
||||
|
||||
if(!(config.mockJson[obj.url] || (obj.originUrl && config.mockJson[obj.originUrl]))) {
|
||||
// mock 没有对应接口的数据
|
||||
@@ -20,7 +19,7 @@ function get(obj: IRequestOption | IUploadFileOption, method: "request" | "uploa
|
||||
};
|
||||
|
||||
loading.hide();
|
||||
return responseHandler(res, obj, method)
|
||||
return res
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
@@ -174,9 +174,10 @@ function request(obj: IRequestOption): any {
|
||||
obj = preDo(obj);
|
||||
|
||||
if (config.mockJson) {
|
||||
let mockResponse = mockManager.get(obj, 'request');
|
||||
let mockResponse = mockManager.get(obj);
|
||||
if (mockResponse) {
|
||||
return resolve(mockResponse);
|
||||
let response = responseHandler(mockResponse, obj, 'request');
|
||||
return resolve(response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,8 +201,11 @@ function uploadFile(obj: IUploadFileOption): any {
|
||||
obj = preDo(obj);
|
||||
|
||||
if (config.mockJson) {
|
||||
mockManager.get(obj, 'uploadFile');
|
||||
return;
|
||||
let mockResponse = mockManager.get(obj);
|
||||
if (mockResponse) {
|
||||
let response = responseHandler(mockResponse, obj, 'uploadFile');
|
||||
return resolve(response);
|
||||
}
|
||||
}
|
||||
|
||||
sessionManager.main().then(() => {
|
||||
|
||||
Reference in New Issue
Block a user