| | |
| | | */ |
| | | |
| | | import Taro from '@tarojs/taro'; |
| | | import Qs from 'qs'; |
| | | import {Tools} from '@components/common/Tools'; |
| | | |
| | | export class Fetcher { |
| | |
| | | * @return {Promise<any>} |
| | | */ |
| | | get(url, data, remap = [], options = null) { |
| | | const params = Qs.stringify(data); |
| | | if (url.indexOf('?') >= 0) { |
| | | url += '&' + params; |
| | | } else { |
| | | url += '?' + params; |
| | | } |
| | | return this.query('get', url, null, remap, options); |
| | | } |
| | | |
| | |
| | | * @return {Promise<any>} |
| | | */ |
| | | post(url, data, remap = [], options = null) { |
| | | return this.query('post', url, data, remap, options); |
| | | const params = Qs.stringify(data); |
| | | const data2 = {}; |
| | | params.split('&').forEach(param => { |
| | | const item = param.split('='); |
| | | data2[decodeURIComponent(item[0])] = decodeURIComponent(item[1]); |
| | | }); |
| | | return this.query('post', url, data2, remap, options); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (Tools.getTopUrlParam('query') === 'real') { |
| | | return false; |
| | | } |
| | | // 当没有 url 指定时,只有内网 ip 和 35** 的端口号,视为本地开发模式 |
| | | return /^(192|127|localhost).*?:35\d{2}$/i.test(window.location.host); |
| | | // 当没有 url 指定时,只有内网 ip 和 33** 的端口号,视为本地开发模式 |
| | | return /^(192|127|localhost).*?:33\d{2}$/i.test(window.location.host); |
| | | })(); |
| | | |
| | | |