Explorar el Código

feat: 区分环境

linwenxin hace 1 año
padre
commit
ac29df22a4
Se han modificado 2 ficheros con 16 adiciones y 1 borrados
  1. 12 1
      src/common/utils/navPag.js
  2. 4 0
      src/store/modules/user/index.js

+ 12 - 1
src/common/utils/navPag.js

@@ -15,7 +15,7 @@ export const navToPage = (function() {
     // #ifdef H5
     if (isWeixin()) {
       wx.miniProgram.getEnv(res => {
-        if (res.miniprogram) {
+        if (res.miniprogram && uni.getStorageSync('miniProgram') == "jsm_env") {
           var i = 0;
           (function goTo() {
             if (gopageid) {
@@ -65,6 +65,7 @@ export function webViewHref(url, pam = {}) {
   var pamstr = Object.entries(pam).map(item => {
     return item.join("=")
   }).join("&");
+  // #ifdef H5
   if (!!~url.indexOf("?")) {
     return process.env.VUE_APP_HREF + url +
       `${pamstr?"&"+pamstr:""}&x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&userId=${store.state.user.userId}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}`
@@ -72,4 +73,14 @@ export function webViewHref(url, pam = {}) {
     return process.env.VUE_APP_HREF + url +
       `?${pamstr?pamstr+"&":""}x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&userId=${store.state.user.userId}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}`
   }
+  // #endif
+  // #ifndef H5
+  if (!!~url.indexOf("?")) {
+    return process.env.VUE_APP_HREF + url +
+      `${pamstr?"&"+pamstr:""}&x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&userId=${store.state.user.userId}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}&miniProgram=jsm_env`
+  } else {
+    return process.env.VUE_APP_HREF + url +
+      `?${pamstr?pamstr+"&":""}x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&userId=${store.state.user.userId}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}&miniProgram=jsm_env`
+  }
+  // #endif
 }

+ 4 - 0
src/store/modules/user/index.js

@@ -39,6 +39,10 @@ var userId = getQueryVariable("userId")
 if (userId) {
   uni.setStorageSync('recycle_mobile_userId', userId)
 }
+var miniProgram = getQueryVariable("miniProgram")
+if (miniProgram) {
+  uni.setStorageSync('miniProgram', miniProgram)
+}
 // #endif
 
 const state = {