| | |
| | | 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; |
| | |
| | | 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 { |
| | |
| | | * @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); |
| | |
| | | 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; |
| | |
| | | } |
| | | // 非 http 协议打开时,使用设置的服务器地址 |
| | | else if (project.host.server) { |
| | | return project.host.hosts[project.host.severType]; |
| | | return project.host.hosts[project.host.serverType]; |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | // 生产 |
| | | else { |
| | | return project.host.hosts[project.host.severType]; |
| | | return project.host.hosts[project.host.serverType]; |
| | | } |
| | | } |
| | | })(); |