Преглед на файлове

update: 增加只能在iframe中显示

xyh преди 2 години
родител
ревизия
268c1aa620
променени са 2 файла, в които са добавени 26 реда и са изтрити 3 реда
  1. 18 2
      packages/app/src/components/authentication/index.tsx
  2. 8 1
      packages/app/src/pages/main/index.tsx

+ 18 - 2
packages/app/src/components/authentication/index.tsx

@@ -1,13 +1,29 @@
 import {FC, PropsWithChildren} from 'react';
-import {LOGIN_PATH} from '@routes';
+import {HOME_PATH, LOGIN_PATH} from '@routes';
 import {useStore} from 'zustand';
 import {userStore} from '@stores';
+import {useLocation} from 'react-router-dom';
 
 const LDAuthentication: FC<PropsWithChildren> = function({children}) {
+  const hasParent = window.location !== parent.location;
   const token = useStore(userStore, state => state.token);
+  const {pathname} = useLocation();
+  const parentRoutes = [HOME_PATH, LOGIN_PATH];
 
+  // 判断当前页面是否可以不在iframe中展示
+  // 只有home和login可以 其他的如果没有parent重定向到首页
+  if (!parentRoutes.includes(pathname) && !hasParent) {
+    location.replace(HOME_PATH);
+
+    return null;
+  }
+
+  // 判断是否登录
   if (!token) {
-    parent ? parent.location.replace(LOGIN_PATH) : location.replace(LOGIN_PATH);
+    hasParent
+      ? parent.location.replace(LOGIN_PATH)
+      : location.replace(LOGIN_PATH);
+
     return null;
   }
 

+ 8 - 1
packages/app/src/pages/main/index.tsx

@@ -1,7 +1,14 @@
+import {LDAuthentication} from '@components';
 import {FC} from 'react';
 
 const Main: FC = function() {
-  return <h1>首页</h1>;
+  return (
+    <LDAuthentication>
+      <div className="ld-content-main">
+        <h1>首页</h1>
+      </div>
+    </LDAuthentication>
+  );
 };
 
 export default Main;