Explorar el Código

fix: 解决iframe url缓存问题

xyh hace 2 años
padre
commit
ef140b8c68

+ 2 - 27
packages/app/src/pages/home/main/hooks.tsx

@@ -1,6 +1,5 @@
 import {Modal, TabPaneProps, TabsProps} from 'antd';
-import {ReactNode, useMemo} from 'react';
-import css from './index.module.css';
+import {ReactNode} from 'react';
 import {useStore} from 'zustand';
 import {tabStore} from '@stores';
 import {useContextMenu, ItemParams} from 'react-contexify';
@@ -25,8 +24,6 @@ export type Tab = {
 } & Omit<TabPaneProps, 'tab'>;
 
 export function useTabItems() {
-  const {host} = location;
-
   const {originalTab, dispatch} = useStore(
     tabStore,
     function (state) {
@@ -38,28 +35,6 @@ export function useTabItems() {
     shallowEqual,
   );
 
-  const tabs = useMemo(
-    function () {
-      return originalTab.map<Tab>(function (tab) {
-        return {
-          ...tab,
-          originalTab: tab,
-          forceRender: true,
-          closable: tab.key !== '-1',
-          animated: true,
-          children: (
-            <iframe
-              src={`http://${host}${tab.url}`}
-              className={css.iframe}
-              data-url={tab.url}
-            />
-          ),
-        };
-      });
-    },
-    [host, originalTab],
-  );
-
   function onDragEnd({active, over}: DragEndEvent) {
     if (!over) return;
 
@@ -74,7 +49,7 @@ export function useTabItems() {
     });
   }
 
-  return [tabs, onDragEnd] as const;
+  return [originalTab, onDragEnd] as const;
 }
 
 export function useTabActive() {

+ 7 - 1
packages/app/src/pages/home/main/tab-panel/index.tsx

@@ -22,7 +22,13 @@ const TabPanel: FC = function () {
         if (map.has(key)) {
           nextMap.set(key, map.get(key));
         } else {
-          nextMap.set(key, <iframe src={url} className={css.iframe} />);
+          nextMap.set(
+            key,
+            <iframe
+              src={url + `?timestamp=${new Date().getTime()}`}
+              className={css.iframe}
+            />,
+          );
         }
       });