|
@@ -38,229 +38,235 @@ const app_type_name = 'APP';
|
|
// #endif
|
|
// #endif
|
|
|
|
|
|
export default {
|
|
export default {
|
|
- sendRequest(params) {
|
|
|
|
- if (!Config.baseUrl) {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: '未配置请求域名',
|
|
|
|
- 'icon': 'none',
|
|
|
|
- duration: 10000
|
|
|
|
- });
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ sendRequest(params) {
|
|
|
|
+ if (!Config.baseUrl) {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: '未配置请求域名',
|
|
|
|
+ 'icon': 'none',
|
|
|
|
+ duration: 10000
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- var method = '' // 请求方式
|
|
|
|
-
|
|
|
|
- let baseUrl=""
|
|
|
|
-
|
|
|
|
- // localStorage.setItem("env","ywxk")
|
|
|
|
- if(process.env.NODE_ENV === 'production'){
|
|
|
|
- Config.baseUrl=Config.schoolBaseData.baseUrl
|
|
|
|
- }else{
|
|
|
|
- //开发环境读配置
|
|
|
|
- if(Config.isLocal==2){
|
|
|
|
- Config.baseUrl='http://125.124.170.221:8000'
|
|
|
|
- // Config.baseUrl='http://zhxy.com'
|
|
|
|
- }else{
|
|
|
|
- // Config.baseUrl='http://zhxy.com'
|
|
|
|
- Config.baseUrl='http://125.124.170.221:8000'
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- var url = Config.baseUrl + params.url // 请求路径
|
|
|
|
-
|
|
|
|
|
|
+ if (params.confirm) {
|
|
|
|
+ return uni.showModal({
|
|
|
|
+ title: params.confirm.title,
|
|
|
|
+ content: params.confirm.message,
|
|
|
|
+ success: res => {
|
|
|
|
+ if (res.confirm) {
|
|
|
|
+ delete params.confirm;
|
|
|
|
+ this.sendRequest(params);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var method = '' // 请求方式
|
|
|
|
+ let baseUrl = ""
|
|
|
|
|
|
- var data = {};
|
|
|
|
|
|
+ // localStorage.setItem("env","ywxk")
|
|
|
|
+ if (process.env.NODE_ENV === 'production') {
|
|
|
|
+ Config.baseUrl = Config.schoolBaseData.baseUrl
|
|
|
|
+ } else {
|
|
|
|
+ //开发环境读配置
|
|
|
|
+ if (Config.isLocal == 2) {
|
|
|
|
+ Config.baseUrl = 'http://125.124.170.221:8000'
|
|
|
|
+ // Config.baseUrl='http://zhxy.com'
|
|
|
|
+ } else {
|
|
|
|
+ // Config.baseUrl='http://zhxy.com'
|
|
|
|
+ Config.baseUrl = 'http://125.124.170.221:8000'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if (params.method) {
|
|
|
|
|
|
+ var url = Config.baseUrl + params.url // 请求路径
|
|
|
|
|
|
- method = params.method
|
|
|
|
- } else if (params.data != undefined) {
|
|
|
|
|
|
+ var data = {};
|
|
|
|
|
|
- method = 'POST'
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (params.method) {
|
|
|
|
+ method = params.method
|
|
|
|
+ } else if (params.data != undefined) {
|
|
|
|
+ method = 'POST'
|
|
|
|
+ } else {
|
|
|
|
+ method = 'GET'
|
|
|
|
+ }
|
|
|
|
|
|
- method = 'GET'
|
|
|
|
- }
|
|
|
|
|
|
+ // token
|
|
|
|
+ if (uni.getStorageSync('token')) data.token = uni.getStorageSync('token');
|
|
|
|
|
|
- // token
|
|
|
|
- if (uni.getStorageSync('token')) data.token = uni.getStorageSync('token');
|
|
|
|
|
|
+ // 门店id
|
|
|
|
+ if (uni.getStorageSync('store_info')) data.store_id = uni.getStorageSync('store_info').store_id;
|
|
|
|
|
|
- // 门店id
|
|
|
|
- if (uni.getStorageSync('store_info')) data.store_id = uni.getStorageSync('store_info').store_id;
|
|
|
|
|
|
+ // 参数
|
|
|
|
+ if (params.data != undefined) Object.assign(data, params.data);
|
|
|
|
|
|
- // 参数
|
|
|
|
- if (params.data != undefined) Object.assign(data, params.data);
|
|
|
|
|
|
+ if (params.async === false) {
|
|
|
|
+ console.log("zheli lema");
|
|
|
|
+ //同步
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ method: method,
|
|
|
|
+ data: data,
|
|
|
|
+ header: params.header || {
|
|
|
|
+ // 'Accept': 'application/json',
|
|
|
|
+ 'content-type': 'application/json',
|
|
|
|
+ Authorization: uni.getStorageSync('token') ? uni.getStorageSync('token') :
|
|
|
|
+ 'zhxy'
|
|
|
|
+ },
|
|
|
|
+ dataType: params.dataType || 'json',
|
|
|
|
+ responseType: params.responseType || 'text',
|
|
|
|
+ success: (res) => {
|
|
|
|
+ console.log(res, "success res");
|
|
|
|
+ // try {
|
|
|
|
+ // res.data = JSON.parse(res.data);
|
|
|
|
+ // } catch (e) {
|
|
|
|
+ // //TODO handle the exception
|
|
|
|
+ // console.log('api error:', e);
|
|
|
|
+ // }
|
|
|
|
+ if (res.data.code == -3 && store.state.siteState > 0) {
|
|
|
|
+ store.commit('setSiteState', -3)
|
|
|
|
+ Util.redirectTo('/pages_tool/storeclose/storeclose', {}, 'reLaunch');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (res.data.refreshtoken) {
|
|
|
|
+ uni.setStorage({
|
|
|
|
+ key: 'token',
|
|
|
|
+ data: res.data.refreshtoken
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
- if (params.async === false) {
|
|
|
|
- console.log("zheli lema");
|
|
|
|
- //同步
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- uni.request({
|
|
|
|
- url: url,
|
|
|
|
- method: method,
|
|
|
|
- data: data,
|
|
|
|
- header: params.header || {
|
|
|
|
- // 'Accept': 'application/json',
|
|
|
|
- 'content-type': 'application/json',
|
|
|
|
- Authorization: uni.getStorageSync('token') ? uni.getStorageSync('token') :
|
|
|
|
- 'zhxy'
|
|
|
|
- },
|
|
|
|
- dataType: params.dataType || 'json',
|
|
|
|
- responseType: params.responseType || 'text',
|
|
|
|
- success: (res) => {
|
|
|
|
- console.log(res, "success res");
|
|
|
|
- // try {
|
|
|
|
- // res.data = JSON.parse(res.data);
|
|
|
|
- // } catch (e) {
|
|
|
|
- // //TODO handle the exception
|
|
|
|
- // console.log('api error:', e);
|
|
|
|
- // }
|
|
|
|
- if (res.data.code == -3 && store.state.siteState > 0) {
|
|
|
|
- store.commit('setSiteState', -3)
|
|
|
|
- Util.redirectTo('/pages_tool/storeclose/storeclose', {}, 'reLaunch');
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (res.data.refreshtoken) {
|
|
|
|
- uni.setStorage({
|
|
|
|
- key: 'token',
|
|
|
|
- data: res.data.refreshtoken
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (res.data.code == -10009 || res.data.code == -10010) {
|
|
|
|
- uni.removeStorage({
|
|
|
|
- key: 'token'
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- // resolve(res.data)
|
|
|
|
- console.log(res.data,"res.data");
|
|
|
|
- if(res.data.code==200 || res.data.code==403){
|
|
|
|
- //typeof params.success == 'function' && params.success(res.data);
|
|
|
|
- resolve(res.data)
|
|
|
|
- } else {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: res.data.msg+url,
|
|
|
|
- 'icon': 'none',
|
|
|
|
- duration: 3000
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- fail: (res) => {
|
|
|
|
- if (res.errMsg && res.errMsg == 'request:fail url not in domain list') {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: Config.baseUrl + '不在request 合法域名列表中',
|
|
|
|
- 'icon': 'none',
|
|
|
|
- duration: 10000
|
|
|
|
- });
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ if (res.data.code == -10009 || res.data.code == -10010) {
|
|
|
|
+ uni.removeStorage({
|
|
|
|
+ key: 'token'
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ // resolve(res.data)
|
|
|
|
+ console.log(res.data, "res.data");
|
|
|
|
+ if (res.data.code == 200 || res.data.code == 403) {
|
|
|
|
+ //typeof params.success == 'function' && params.success(res.data);
|
|
|
|
+ resolve(res.data)
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: res.data.msg + url,
|
|
|
|
+ 'icon': 'none',
|
|
|
|
+ duration: 3000
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: (res) => {
|
|
|
|
+ if (res.errMsg && res.errMsg == 'request:fail url not in domain list') {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: Config.baseUrl + '不在request 合法域名列表中',
|
|
|
|
+ 'icon': 'none',
|
|
|
|
+ duration: 10000
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ reject(res);
|
|
|
|
+ },
|
|
|
|
+ complete: (res) => {
|
|
|
|
+ console.log(res, "complete complete");
|
|
|
|
+ if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200,
|
|
|
|
+ 500
|
|
|
|
+ ].indexOf(res.statusCode) == -1)) {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: Config.baseUrl + '请求失败',
|
|
|
|
+ 'icon': 'none',
|
|
|
|
+ duration: 10000
|
|
|
|
+ })
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ //异步
|
|
|
|
+ params.showLoading && uni.showLoading({
|
|
|
|
+ title: '加载中'
|
|
|
|
+ });
|
|
|
|
+ // console.log("token是什么", url,uni.getStorageSync('token'));
|
|
|
|
+
|
|
|
|
+ uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ method: method,
|
|
|
|
+ data: data,
|
|
|
|
+ header: params.header || {
|
|
|
|
+ // 'Accept': 'application/json',
|
|
|
|
+ 'content-type': 'application/json',
|
|
|
|
+ Authorization: uni.getStorageSync('token') ? uni.getStorageSync('token') : 'zhxy'
|
|
|
|
+ },
|
|
|
|
+ dataType: params.dataType || 'json',
|
|
|
|
+ responseType: params.responseType || 'text',
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // try {
|
|
|
|
+ // res.data = JSON.parse(res.data);
|
|
|
|
+ // } catch (e) {
|
|
|
|
+ // //TODO handle the exception
|
|
|
|
+ // console.log('api error:', e);
|
|
|
|
+ // }
|
|
|
|
+ if (res.data.code == -3 && store.state.siteState > 0) {
|
|
|
|
+ store.commit('setSiteState', -3)
|
|
|
|
+ Util.redirectTo('/pages_tool/storeclose/storeclose', {}, 'reLaunch');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (res.data.refreshtoken) {
|
|
|
|
+ uni.setStorage({
|
|
|
|
+ key: 'token',
|
|
|
|
+ data: res.data.refreshtoken
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (res.data.code == -10009 || res.data.code == -10010) {
|
|
|
|
+ uni.removeStorage({
|
|
|
|
+ key: 'token'
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
|
|
- reject(res);
|
|
|
|
- },
|
|
|
|
- complete: (res) => {
|
|
|
|
- console.log(res, "complete complete");
|
|
|
|
- if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200,
|
|
|
|
- 500
|
|
|
|
- ].indexOf(res.statusCode) == -1)) {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: Config.baseUrl + '请求失败',
|
|
|
|
- 'icon': 'none',
|
|
|
|
- duration: 10000
|
|
|
|
- })
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- //异步
|
|
|
|
- uni.showLoading({
|
|
|
|
- title: '加载中'
|
|
|
|
- });
|
|
|
|
- console.log("token是什么",uni.getStorageSync('token'));
|
|
|
|
-
|
|
|
|
- uni.request({
|
|
|
|
- url: url,
|
|
|
|
- method: method,
|
|
|
|
- data: data,
|
|
|
|
- header: params.header || {
|
|
|
|
- // 'Accept': 'application/json',
|
|
|
|
- 'content-type': 'application/json',
|
|
|
|
- Authorization: uni.getStorageSync('token') ? uni.getStorageSync('token') : 'zhxy'
|
|
|
|
- },
|
|
|
|
- dataType: params.dataType || 'json',
|
|
|
|
- responseType: params.responseType || 'text',
|
|
|
|
- success: (res) => {
|
|
|
|
- // try {
|
|
|
|
- // res.data = JSON.parse(res.data);
|
|
|
|
- // } catch (e) {
|
|
|
|
- // //TODO handle the exception
|
|
|
|
- // console.log('api error:', e);
|
|
|
|
- // }
|
|
|
|
- if (res.data.code == -3 && store.state.siteState > 0) {
|
|
|
|
- store.commit('setSiteState', -3)
|
|
|
|
- Util.redirectTo('/pages_tool/storeclose/storeclose', {}, 'reLaunch');
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (res.data.refreshtoken) {
|
|
|
|
- uni.setStorage({
|
|
|
|
- key: 'token',
|
|
|
|
- data: res.data.refreshtoken
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- if (res.data.code == -10009 || res.data.code == -10010) {
|
|
|
|
- uni.removeStorage({
|
|
|
|
- key: 'token'
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(res.data.code == 401){
|
|
|
|
|
|
+ if (res.data.code == 401) {
|
|
uni.setStorageSync("token", '')
|
|
uni.setStorageSync("token", '')
|
|
uni.reLaunch({
|
|
uni.reLaunch({
|
|
url: "/pages/login/login"
|
|
url: "/pages/login/login"
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (res.data.code == 200 || res.data.code == 403) {
|
|
|
|
- typeof params.success == 'function' && params.success(res.data);
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: res.data.msg ,
|
|
|
|
- 'icon': 'none',
|
|
|
|
- duration: 3000
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- uni.hideLoading();
|
|
|
|
- },
|
|
|
|
- fail: (res) => {
|
|
|
|
- if (res.errMsg && res.errMsg == 'request:fail url not in domain list') {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: Config.baseUrl + '不在request 合法域名列表中',
|
|
|
|
- 'icon': 'none',
|
|
|
|
- duration: 10000
|
|
|
|
- });
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- typeof params.fail == 'function' && params.fail(res);
|
|
|
|
|
|
+ if (res.data.code == 200 || res.data.code == 403) {
|
|
|
|
+ typeof params.success == 'function' && params.success(res.data);
|
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
- },
|
|
|
|
- complete: (res) => {
|
|
|
|
- if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200, 500].indexOf(
|
|
|
|
- res.statusCode) == -1)) {
|
|
|
|
- uni.showToast({
|
|
|
|
- title: Config.baseUrl + '请求失败',
|
|
|
|
- 'icon': 'none',
|
|
|
|
- duration: 10000
|
|
|
|
- })
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- typeof params.complete == 'function' && params.complete(res);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: res.data.msg,
|
|
|
|
+ 'icon': 'none',
|
|
|
|
+ duration: 3000
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ uni.hideLoading();
|
|
|
|
+ },
|
|
|
|
+ fail: (res) => {
|
|
|
|
+ if (res.errMsg && res.errMsg == 'request:fail url not in domain list') {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: Config.baseUrl + '不在request 合法域名列表中',
|
|
|
|
+ 'icon': 'none',
|
|
|
|
+ duration: 10000
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ typeof params.fail == 'function' && params.fail(res);
|
|
|
|
+ params.fail && params.fail(res.data);
|
|
|
|
+ uni.hideLoading();
|
|
|
|
+ },
|
|
|
|
+ complete: (res) => {
|
|
|
|
+ if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200, 500].indexOf(
|
|
|
|
+ res.statusCode) == -1)) {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: Config.baseUrl + '请求失败',
|
|
|
|
+ 'icon': 'none',
|
|
|
|
+ duration: 10000
|
|
|
|
+ })
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ typeof params.complete == 'function' && params.complete(res);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|