fix(mockManager): 修复mock成功后仍然发出请求的问题

This commit is contained in:
TENCENT\ivinwu
2019-03-25 19:45:15 +08:00
parent 9b195301cd
commit 6998bf15e3
7 changed files with 29 additions and 23 deletions

View File

@@ -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>

View File

@@ -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

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
{
"name": "we-request",
"version": "1.2.3",
"version": "1.2.4",
"description": "本工具通过拓展小程序的wx.request让开发者通过简单的配置实现自动管理登录态等功能",
"keywords": [
"登录态",

View File

@@ -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 {

View File

@@ -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(() => {