123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //设置域名
- const dev_baseUrl = "https://test.hz-hanghui.com:18890/yx-fyzd"; //测试
- // const dev_baseUrl = "http://192.168.11.19:9100/yx-fyzd"; //本地
- // const pro_baseUrl = "http://192.168.77.19:8081/hanghui-server-platform"; //正式
- const pro_baseUrl = "https://tx.hz-hanghui.com:8088/hanghui-server-platform"; //正式
- //是否是正式环境
- const env = true;
- const baseUrl = env ? pro_baseUrl : dev_baseUrl;
- //https请求
- const request = e => {
- let token = my.getStorageSync({
- key: 'token'
- }).data;
- return new Promise(function (resolve, reject) {
- my.request({
- url: e.url.startsWith('http') ? e.url : (env ?
- pro_baseUrl + e.url :
- dev_baseUrl + e.url),
- data: e.data,
- method: e.method,
- headers: {
- "content-type": e.type,
- "Authorization": token ? token.token : '',
- },
- timeout: e.timeout ? e.timeout : 5000,
- success: res => {
- if (res.data.code == 200) {
- resolve(res.data);
- } else {
- my.hideLoading();
- my.showToast({
- content: e.errorTip + (res.data.msg ? res.data.msg : ''),
- duration: 3000
- });
- reject(res.data);
- }
- },
- fail: error => {
- my.hideLoading();
- my.showToast({
- content: e.errorTip + (error.errmsg ? error.errmsg : ''),
- duration: 3000,
- });
- reject(error.errorMessage);
- }
- });
- });
- };
- // 三要素获取接口
- const threeElementsRequest = e => {
- return new Promise(function (resolve, reject) {
- my.request({
- url: e.url,
- data: e.data,
- method: e.method,
- headers: {
- "content-type": e.type
- },
- timeout: 25000,
- success: res => {
- if (res.data.errcode == 0 || res.data.code == 200) {
- resolve(res.data);
- } else {
- my.hideLoading();
- my.showToast({
- content: e.errorTip + (res.data.msg ? res.data.msg : ''),
- duration: 3000
- });
- reject(res.data);
- }
- },
- fail: error => {
- my.hideLoading();
- my.showToast({
- content: e.errorTip + (error.errmsg ? error.errmsg : ''),
- duration: 3000,
- });
- reject(error.errorMessage);
- }
- });
- });
- };
- module.exports = {
- env: env,
- baseUrl,
- dev_baseUrl: dev_baseUrl,
- pro_baseUrl: pro_baseUrl,
- request: request,
- threeElementsRequest: threeElementsRequest,
- };
|