John-Hong 2 år sedan
förälder
incheckning
b5873ea22f
3 ändrade filer med 128 tillägg och 117 borttagningar
  1. 1 0
      src/pages/login/openWx.vue
  2. 125 115
      src/utils/cache-tool.js
  3. 2 2
      src/utils/login.js

+ 1 - 0
src/pages/login/openWx.vue

@@ -7,6 +7,7 @@
 <script>
 <script>
 import { getUrlParams } from '@/utils/index';
 import { getUrlParams } from '@/utils/index';
 import { WxJsOpenId } from '@/utils/login';
 import { WxJsOpenId } from '@/utils/login';
+import uni from '@/utils/uniHooks';
 
 
 export default {
 export default {
   created() {
   created() {

+ 125 - 115
src/utils/cache-tool.js

@@ -1,124 +1,134 @@
 import {
 import {
-	ENV_LIST,
-	APPID,
-	LOGO_DEFAULT,
-	APPID_MAP,
-	LOGO_KO_DEFAULT,
+  ENV_LIST,
+  APPID,
+  LOGO_DEFAULT,
+  APPID_MAP,
+  LOGO_KO_DEFAULT,
 } from '@/constants.js'
 } from '@/constants.js'
 import uni from './uniHooks'
 import uni from './uniHooks'
 export default {
 export default {
-	init() {
-		const href = `${window.location.href}`
-		// dev
-		if (/8080|dev-tparking/g.test(href)) {
-			this.setEnv('qa')
-			return
-		}
-		// qa
-		if (/qa-tparking/g.test(href)) {
-			this.setEnv('qa')
-			return
-		}
-		// prod
-		this.setEnv('prod')
-	},
-	setEnv(env) {
-		// console.log(2020202020, env)
-		uni.setStorageSync("env", env);
-	},
-	getEnv() {
-		const env = uni.getStorageSync("env");
-		if (!env) {
-			const env = ENV_LIST[1];
-			uni.setStorageSync("env", env.name);
-			return env.name
-		}
-		return env;
-	},
-	cleanAllCache() {
-		uni.clearStorageSync()
-	},
-	getCurEnvConst(key) {
-		const curEnvName = this.getEnv();
-		const curEnvConst = ENV_LIST.find(item => item.name == curEnvName);
-		// 如果是来自 window.injectConfig
-		if (window?.injectConfig) {
-			console.log(464646, window?.injectConfig);
-			console.log(474747, key);
-			if (key === 'KIP_API') {
-				return window?.injectConfig?.profileApi
-			}
-			curEnvConst.constants = {
-				...curEnvConst?.constants,
-				...window?.injectConfig
-			}
-		}
-		if (key) {
-			return curEnvConst?.constants[key];
-		} else {
-			return curEnvConst?.constants;
-		}
-	},
-	setMiniAppOptions(options) {
-		if (!options) {
-			return;
-		}
-		uni.setStorageSync('options', options);
-		const query = options.query
-		if (!query.scene) {
-			this.setMiniAppOptionsQuery(query)
-		}
+  init() {
+    const href = `${window.location.href}`
+    // dev
+    if (/8080|dev-tparking/g.test(href)) {
+      this.setEnv('qa')
+      return
+    }
+    // qa
+    if (/qa-tparking/g.test(href)) {
+      this.setEnv('qa')
+      return
+    }
+    // prod
+    this.setEnv('prod')
+  },
+  setEnv(env) {
+    // console.log(2020202020, env)
+    uni.setStorageSync("env", env);
+  },
+  getEnv() {
+    const env = uni.getStorageSync("env");
+    if (!env) {
+      const env = ENV_LIST[1];
+      uni.setStorageSync("env", env.name);
+      return env.name
+    }
+    return env;
+  },
+  cleanAllCache() {
+    uni.clearStorageSync()
+  },
+  getCurEnvConst(key) {
+    const curEnvName = this.getEnv();
+    let curEnvConst = ENV_LIST.find(item => item.name == curEnvName);
+    // 如果是来自 window.injectConfig
+    if (window?.injectConfig) {
+      console.log(464646, window?.injectConfig);
+      console.log(474747, key);
+      if (key === 'KIP_API') {
+        return window?.injectConfig?.profileApi
+      }
+      if (curEnvConst?.constants) {
+        curEnvConst.constants = {
+          ...curEnvConst?.constants,
+          ...window?.injectConfig
+        }
+      } else {
+        curEnvConst = {
+          ...curEnvConst,
+          constants: {
+            ...window?.injectConfig
+          }
+        }
+      }
 
 
-	},
-	setMiniAppOptionsQuery(query) {
-		if (!query || JSON.stringify(query) == '{}') {
-			// 直接进入的utm_lbs是空的
-			// const mallid = uni.getStorageSync("mallid")
-			const defaultOptionsQuery = {
-				channel: APPID,
-				utm_channel: APPID,
-				utm_method: 'dr',
-				// utm_lbs: mallid,
-			}
-			query = defaultOptionsQuery;
-		}
-		// channel 肯定是当前小程序的appid
-		query.channel = APPID;
-		uni.setStorageSync("options_query", query);
-	},
-	getLogoByMallid(mallid) {
-		console.log(90, mallid);
-		const defaultLogo = isKerryOnAppid() ? LOGO_KO_DEFAULT : LOGO_DEFAULT
-		if (!mallid) {
-			console.error("=>[getLogoByMallid]mallid is null")
-			return defaultLogo
-		}
-		const marketList = this.getMarketList()
-		if (!marketList) {
-			console.error("=>[setMarketList]marketList is null")
-			return defaultLogo;
-		}
-		const market = marketList.find(item => item.mallid == mallid)
-		if (!market) {
-			console.error("=>[setMarketList]market is null")
-			return defaultLogo;
-		}
-		return market?.logoPicture || defaultLogo;
-	},
-	getMarketList() {
-		const marketList = uni.getStorageSync("marketList");
-		if (!marketList || marketList.length === 0) {
-			console.error("=>[getMarketList]marketList is empty")
-			return []
-		}
-		return marketList;
-	},
+    }
+    if (key) {
+      return curEnvConst?.constants[key];
+    } else {
+      return curEnvConst?.constants;
+    }
+  },
+  setMiniAppOptions(options) {
+    if (!options) {
+      return;
+    }
+    uni.setStorageSync('options', options);
+    const query = options.query
+    if (!query.scene) {
+      this.setMiniAppOptionsQuery(query)
+    }
+
+  },
+  setMiniAppOptionsQuery(query) {
+    if (!query || JSON.stringify(query) == '{}') {
+      // 直接进入的utm_lbs是空的
+      // const mallid = uni.getStorageSync("mallid")
+      const defaultOptionsQuery = {
+        channel: APPID,
+        utm_channel: APPID,
+        utm_method: 'dr',
+        // utm_lbs: mallid,
+      }
+      query = defaultOptionsQuery;
+    }
+    // channel 肯定是当前小程序的appid
+    query.channel = APPID;
+    uni.setStorageSync("options_query", query);
+  },
+  getLogoByMallid(mallid) {
+    console.log(90, mallid);
+    const defaultLogo = isKerryOnAppid() ? LOGO_KO_DEFAULT : LOGO_DEFAULT
+    if (!mallid) {
+      console.error("=>[getLogoByMallid]mallid is null")
+      return defaultLogo
+    }
+    const marketList = this.getMarketList()
+    if (!marketList) {
+      console.error("=>[setMarketList]marketList is null")
+      return defaultLogo;
+    }
+    const market = marketList.find(item => item.mallid == mallid)
+    if (!market) {
+      console.error("=>[setMarketList]market is null")
+      return defaultLogo;
+    }
+    return market?.logoPicture || defaultLogo;
+  },
+  getMarketList() {
+    const marketList = uni.getStorageSync("marketList");
+    if (!marketList || marketList.length === 0) {
+      console.error("=>[getMarketList]marketList is empty")
+      return []
+    }
+    return marketList;
+  },
 }
 }
 
 
 function isKerryOnAppid() {
 function isKerryOnAppid() {
-	if (APPID == APPID_MAP.kerryMall) {
-		return true;
-	} else {
-		return false;
-	}
+  if (APPID == APPID_MAP.kerryMall) {
+    return true;
+  } else {
+    return false;
+  }
 }
 }

+ 2 - 2
src/utils/login.js

@@ -155,8 +155,8 @@ async function WxJsSdkConfig(jsApiList = [], url = '', openTagList = []) {
   return new Promise((resolve, reject) => {
   return new Promise((resolve, reject) => {
     wx.config({
     wx.config({
       debug,
       debug,
-      // appId: res.data.appId,
-      appId: 'wx907c27f16841a919',
+      appId: res.data.appId,
+      // appId: 'wx907c27f16841a919',
       timestamp: res.data.timestamp,
       timestamp: res.data.timestamp,
       nonceStr: res.data.nonceStr,
       nonceStr: res.data.nonceStr,
       signature: res.data.signature,
       signature: res.data.signature,