Browse Source

更新自动跳转

tianyunperfect 4 năm trước cách đây
mục cha
commit
ae97da0729
2 tập tin đã thay đổi với 21 bổ sung4 xóa
  1. 20 4
      src/pages/Memory/index.tsx
  2. 1 0
      src/pages/MemoryList/data.d.ts

+ 20 - 4
src/pages/Memory/index.tsx

@@ -51,6 +51,7 @@ const TableList: React.FC<{}> = () => {
     tag: '',
     updateTime: '',
     userId: 0,
+    onlyText: ''
   });
 
   const isPracticeFocus = () => {
@@ -60,11 +61,11 @@ const TableList: React.FC<{}> = () => {
   /**
    * 设置复习状态,对手机端返回页面的时候有用
    */
-  const setMemeory = () => {
+  const setMemoryTag = () => {
     localStorage.setItem("memory", '1');
   }
   const checkMemeory = () => {
-    if (localStorage.getItem("memory") === '1') {
+    if (localStorage.getItem("memory") === '1' && state.step !== Step.MEMORY) {
       setState({step: Step.MEMORY});
     } else {
       countRemind();
@@ -134,7 +135,7 @@ const TableList: React.FC<{}> = () => {
     const res = await service.findNext({});
     if (res.success) {
       setMemory({...memory, ...res.data});
-      setMemeory();
+      setMemoryTag();
     } else {
       setState({step: Step.MAIN});
       removeMemeory();
@@ -195,9 +196,22 @@ const TableList: React.FC<{}> = () => {
   const isBackEmpty = () => {
     return getTextFromHtml(memory.back).length === 0 && memory.back.indexOf('img') < 0;
   }
+  // 检测是否应该自动跳转
+  const checkGotoUrl = () => {
+    if (memory.onlyText.trim().startsWith("url") && localStorage.getItem("auto-url") !== memory.id + "") {
+      setTimeout(() => {
+        localStorage.setItem("auto-url", memory.id + "");
+        let a = document.querySelector(".ql-editor a");
+        if (a) {
+          // @ts-ignore
+          a.click()
+        }
+      }, 1500);
+
+    }
+  }
 
   useEffect(() => {
-    checkMemeory();
     setTimeout(() => {
       countRemind();
     }, 1000 * 60 * 60); // 每隔一个小时查询一次
@@ -223,6 +237,8 @@ const TableList: React.FC<{}> = () => {
     if (memory.front.length === 0) {
       return;
     }
+    // 检测是否需要跳转
+    checkGotoUrl()
     // 进入复习页面后
     // 如果没有文字,并且也没有图片
     if (isBackEmpty()) {

+ 1 - 0
src/pages/MemoryList/data.d.ts

@@ -8,6 +8,7 @@ export interface TableListItem {
   period: number;
   remindTime: Date;
   updateTime:string;
+  onlyText: string;
 }
 // 分页参数
 export interface TableListPagination {