Kaynağa Gözat

fix(小程序): 启动参数中channelCode值无法覆盖问题处理

qq12rrr 4 hafta önce
ebeveyn
işleme
f562359be0
2 değiştirilmiş dosya ile 21 ekleme ve 2 silme
  1. 16 0
      src/app.tsx
  2. 5 2
      src/pages/home/index.tsx

+ 16 - 0
src/app.tsx

@@ -100,7 +100,23 @@ const App = (props: PropsWithChildren<IAppProps>) => {
     if (options.query?.channelCode) {
       StorageUtil.set(EStorage.channelCode, options.query?.channelCode);
     }
+
+    const channelCode = extractChannelCodeValue(options.query);
+
+    if (channelCode) {
+      StorageUtil.set(EStorage.channelCode, channelCode);
+    }
   });
+
+  const extractChannelCodeValue = (query: any) => {
+    for (let key in query) {
+      if (key.includes("?channelCode")) {
+        return query[key];
+      }
+    }
+    return null;
+  };
+
   return (
     // (appContext.systemInfo?.screenHeight || 0) - (appContext.systemInfo?.safeArea?.bottom || 0);
     <AppContext.Provider

+ 5 - 2
src/pages/home/index.tsx

@@ -31,7 +31,7 @@ import LoginBox from "../user/components/LoginBox";
 import BottomBarContext from "@/context/bottomBarContext";
 
 const Home = () => {
-  const channelCode = StorageUtil.get(EStorage.channelCode) || "";
+  const channelCode: any = StorageUtil.get(EStorage.channelCode) || "";
 
   const bottomBarContext = useContext(BottomBarContext);
 
@@ -51,7 +51,10 @@ const Home = () => {
 
   const channelResult: any = useRequest(() => {
     return UserApi.homeFetchChannel({
-      data: { channelCode: APPConfig.CHANNELCODE, refer: "" },
+      data: {
+        channelCode: channelCode || APPConfig.CHANNELCODE,
+        refer: "",
+      },
     })
       .toData()
       .then((res) => {