添加环境判断
diff --git a/static/js/config.js b/static/js/config.js
new file mode 100644
index 0000000..e6285be
--- /dev/null
+++ b/static/js/config.js
@@ -0,0 +1,22 @@
+let config = {}
+
+if (process.env.NODE_ENV === 'development') {
+ // 开发环境
+ config = {
+ // #ifdef H5
+ base_api: "/api", //测试地址
+ // #endif
+ // base_api: "http://172.28.43.20:8089/portal/mobileapi",//本地地址
+ // #ifndef H5
+ base_api: 'http://yy.dlsmk.cn:8080/portal/mobileapi',
+ // #endif
+ }
+
+} else {
+ // 生产环境
+ config = {
+ base_api: 'https://yy.dlsmk.cn/portal/mobileapi'
+ }
+}
+
+export default config
diff --git a/static/js/http.interceptor.js b/static/js/http.interceptor.js
index 0748b4b..db568be 100644
--- a/static/js/http.interceptor.js
+++ b/static/js/http.interceptor.js
@@ -1,12 +1,10 @@
+import config from './config.js'
+const base_url = config.base_api
+console.log(base_url)
const install = (Vue, vm) => {
// 此为自定义配置参数,具体参数见上方说明
Vue.prototype.$u.http.setConfig({
- // baseUrl: 'https://yy.dlsmk.cn/payapi/mobileapi', // 大理智警域名
- // baseUrl:'https://yy.dlsmk.cn/portal/mobileapi', //正式地址
- // baseUrl:'http://yy.dlsmk.cn:8080/portal/mobileapi', //测试地址
- // baseUrl:'/api',
- baseUrl: "http://172.28.43.20:8089/portal/mobileapi",//本地地址
- // method: 'POST',
+ baseUrl: base_url,
// 设置为json,返回后会对数据进行一次JSON.parse()
dataType: 'json',
// sslVerify:false,
@@ -26,14 +24,14 @@
const tenantid = uni.getStorageSync('tenantid');
if (token) {
config.header['Authorization'] = "Bearer " + token;
- }else{
+ } else {
config.header['Authorization'] = ''
}
//console.log(config.url,config.header['Authorization'])
config.header["X-TENANT-ID"] = tenantid;
- if (config.url == "/i/activity" || config.url == "/v1/feedback/release"
- || config.url == '/medicineapi/medicalcard/add' || config.url == '/medicalapi/pay'
- ||config.url == '/v1/security/save' || config.url == '/i/security/check' || config.url == '/i/security/pwdset') {
+ if (config.url == "/i/activity" || config.url == "/v1/feedback/release" ||
+ config.url == '/medicineapi/medicalcard/add' || config.url == '/medicalapi/pay' ||
+ config.url == '/v1/security/save' || config.url == '/i/security/check' || config.url == '/i/security/pwdset') {
config.header['content-type'] = "application/json";
} else {
config.header['content-type'] = "application/x-www-form-urlencoded";
@@ -49,7 +47,7 @@
// 如果配置了originalData为true,请留意这里的返回值
if (res.data.code == 200) {
return res.data
- } else if(res.data.code == 500){
+ } else if (res.data.code == 500) {
uni.showModal({
title: "提示",
content: res.data.code + ":" + res.data.msg,
@@ -68,7 +66,7 @@
uni.showToast({
title: "登录状态失效,请重新登录",
icon: "none",
- mask:true,
+ mask: true,
duration: 1500,
complete(res) {
setTimeout(() => {
@@ -83,14 +81,14 @@
} else {
// 如果返回false,则会调用Promise的reject回调,
// 并将进入this.$u.post(url).then().catch(res=>{})的catch回调中,res为服务端的返回值
- if(res.errMsg.indexOf('fail') == -1){
+ if (res.errMsg.indexOf('fail') == -1) {
uni.showModal({
title: "错误",
content: res.data.status + ":" + res.data.message,
// content: `${res.data.status}:${res.data.message}`,
showCancel: false,
})
- }else{
+ } else {
uni.showModal({
title: "错误",
content: res.errMsg,
@@ -107,4 +105,3 @@
// export default install
module.exports = install
-