From 09035f0b64c0056be7433a9180225cf6bbc7b487 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Thu, 08 Apr 2021 15:16:29 +0800 Subject: [PATCH] 增加小程序当请求状态为没有登陆的处理 --- bases/Fetcher.js | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bases/Fetcher.js b/bases/Fetcher.js index b683b42..4112dc5 100644 --- a/bases/Fetcher.js +++ b/bases/Fetcher.js @@ -18,7 +18,7 @@ this._data = { urlPrefix: options.urlPrefix || ['/api/common/', '/api/common/'], }; - if (project.host.mock) { + if (project.host.mock === 'on') { this._defaultConfig.url = Fetcher.host + project.host.assetsPath.replace('/assets', '/mocks'); } else { this._defaultConfig.url = Fetcher.host; @@ -50,8 +50,12 @@ spellURL(devSuffix, serSuffix) { let url = ''; // mock 模式 - if (project.host.mock) { + if (project.host.mock === 'on') { url = this._data.urlPrefix[0].replace('api/', '') + devSuffix + '.json'; + } + // 强制实际请求模式 + else if (project.host.mock === 'real') { + url = this._data.urlPrefix[1] + (serSuffix || devSuffix); } // 正常模式 else { @@ -99,7 +103,7 @@ * @return {Promise<any>} */ post(url, data, remap = [], options = null) { - if (project.host.mock) { + if (project.host.mock === 'on') { return this.get(url, data, remap = [], options); } const params = Qs.stringify(data); @@ -283,7 +287,9 @@ this.message('info', response.state.msg); return null; } else if (response.state.code === 9001) { - // this._showLoginExpired(); + if (process.env.TARO_ENV === 'weapp') { + Taro.navigateTo({ url: '/pages/home/index/index?mode=login' }); + } } else { this.message('error', response.state.msg); return null; @@ -560,7 +566,7 @@ } // 非 http 协议打开时,使用设置的服务器地址 else if (project.host.server) { - return project.host.hosts[project.host.severType]; + return project.host.hosts[project.host.serverType]; } } } @@ -572,7 +578,7 @@ } // 生产 else { - return project.host.hosts[project.host.severType]; + return project.host.hosts[project.host.serverType]; } } })(); -- Gitblit v1.9.1