123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- // const ip = 'http://192.168.2.8:8080'; //线下
- //const ip = 'http://hs-server.aseanbusiness.cn'; //线上
- // const ngip = 'http://hs.tbgjhc.top:7010'
- const ip = 'http://hs-server.tbgjhc.top:8018';
- //静态图片地址前缀
- // const ngip = 'http://192.168.3.15:8080/sp-admin'
- // const ip = 'http://192.168.3.15:8080'; //线下
- /**
- * 封装的http请求
- */
- const request = (opt) => {
- opt = opt || {};
- opt.url = ip + opt.url || '';
- opt.data = opt.data || null;
- opt.method = opt.method || 'GET';
- opt.contentType = opt.contentType || 'application/x-www-form-urlencoded'
- opt.header = opt.header || {
- 'app-version':uni.getAppBaseInfo().appVersion,
- "Content-Type": opt.contentType,
- "satoken": uni.getStorageSync('token')
- };
- opt.loading = opt.loading || 'true';
- opt.success = opt.success || function() {};
- opt.fail = opt.fail || function() {};
- if (process.env.NODE_ENV) {
- console.log(
- "**************************************参数调式***************************************************");
- console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
- console.log(
- "************************************************************************************************");
- }
- if (opt.loading == 'true') {
- uni.showLoading({
- title: '正在加载',
- mask: true
- });
- }
- uni.request({
- url: opt.url,
- data: opt.data,
- method: opt.method,
- header: opt.header,
- dataType: 'json',
- responseType: opt.responseType,
- success: res => {
- setTimeout(() => {
- uni.hideLoading();
- }, 500)
- /*******************未授权***************************/
- if (res.data.code === 401) {
- uni.removeStorageSync('info');
- uni.removeStorageSync('token');
- uni.redirectTo({url:'/pages/login/login'})
- return;
- }
- /*******************未授权***************************/
- if (res.data.code === 403) {
- uni.showModal({
- content: res.data.msg,
- showCancel: false
- });
- return;
- }
- /*******************系统内部错误***************************/
- if (res.data.code === 500) {
- uni.showModal({
- content: res.data.msg,
- showCancel: false
- });
- opt.fail(res);
- return;
- }
- opt.success(res);
- },
- fail: e => {
- uni.hideLoading();
- uni.getNetworkType({
- success: res => {
- if (res.networkType == 'none') {
- uni.showModal({
- content: '当前网络不可用,请检查网络稍后重试',
- showCancel: false
- });
- } else {
- uni.showModal({
- content: '服务异常,请稍后重试',
- showCancel: false
- })
- }
- }
- });
- }
- })
- }
- module.exports = {
- ip,
- request
- };
|