Переглянути джерело

fix(front): 长难句阅读

Go 5 роки тому
батько
коміт
b462701c9e

+ 2 - 2
front/project/www/components/Panel/index.js

@@ -171,7 +171,7 @@ export function BuyPanel(props) {
 
 export function SmallPanel(props) {
   const { style, title, lock, data = {}, onClick } = props;
-  const { useEndTime, needService } = data;
+  const { expireTime, needService } = data;
   return (
     <Module style={style} className="panel small-panel">
       <div className="header">
@@ -193,7 +193,7 @@ export function SmallPanel(props) {
                 </div>
               );
             })}
-            {needService && <div className="date">有效期至:{useEndTime && formatDate(useEndTime, 'YYYY-MM-DD')}</div>}
+            {needService && <div className="date">有效期至:{expireTime && formatDate(expireTime, 'YYYY-MM-DD')}</div>}
           </div>
         </div>
       </div>

+ 27 - 17
front/project/www/routes/sentence/read/page.js

@@ -19,12 +19,16 @@ export default class extends Page {
     this.pageLine = 100;
   }
 
+  initState() {
+    return { article: {}, showJump: false, showMenu: false, currentPage: 0, totalPage: 0 };
+  }
+
   init() {
     this.lastTime = new Date();
-  }
 
-  initState() {
-    return { showJump: false, showMenu: false, currentPage: 0, totalPage: 0 };
+    Main.getSentence().then(result => {
+      this.setState({ info: result });
+    });
   }
 
   initData() {
@@ -42,9 +46,6 @@ export default class extends Page {
       }
       this.jumpPage(page);
     });
-    Main.getSentence().then(result => {
-      this.setState({ info: result });
-    });
   }
 
   refreshSentence() {
@@ -107,9 +108,15 @@ export default class extends Page {
   }
 
   nextPage() {
+    const { sentence = {} } = this.state;
     const { currentPage, totalPage } = this.state;
     if (currentPage < totalPage) {
       this.jumpPage(currentPage + 1);
+    } else {
+      const code = !!sentence.code;
+      if (!code) {
+        this.setState({ article: null });
+      }
     }
   }
 
@@ -117,7 +124,7 @@ export default class extends Page {
     // 计算哪篇文章
     const { target, index, allow } = this.computeArticle(targetPage);
     if (!allow) {
-      // todo 无法访问:非试用
+      this.setState({ article: null });
       return;
     }
     this.page = targetPage;
@@ -186,14 +193,20 @@ export default class extends Page {
       clearTimeout(this.timeout);
       this.timeout = null;
     }
-    const now = new Date();
-    const time = (now.getTime() - this.lastTime.getTime()) / 1000;
-    this.lastTime = now;
     const progress = ((index + 1) * 100) / target.pages;
-    Sentence.updateProgress(target.chapter, target.part, progress, time, current.chapter, current.page);
+    if (target.chapter === current.chapter && target.part === current.part) {
+      Sentence.updateProgress(target.chapter, target.part, progress);
+    } else {
+      const now = new Date();
+      const time = (now.getTime() - this.lastTime.getTime()) / 1000;
+      this.lastTime = now;
+      Sentence.updateProgress(target.chapter, target.part, progress, time, current.chapter, current.part);
+    }
+
     this.timeout = setTimeout(() => {
       // 最长5分钟阅读时间
       Sentence.updateProgress(0, 0, 0, 5 * 60, target.chapter, target.part);
+      this.lastTime = null;
     }, 5 * 60 * 1000);
   }
 
@@ -234,8 +247,7 @@ export default class extends Page {
           })}
         </div>
       </div>
-    </div>
-    );
+    </div>);
   }
 
   renderMenu() {
@@ -276,8 +288,7 @@ export default class extends Page {
                 {chapter.title}
                 <div className="page">{chapter.startPage}</div>
               </div>
-            </Tooltip>
-            );
+            </Tooltip>);
             const list = [_item];
             if (chapter.value) {
               (articleMap[chapter.value] || []).forEach(article => {
@@ -298,8 +309,7 @@ export default class extends Page {
                     {article.title}
                     <div className="page">{article.startPage}</div>
                   </div>
-                </Tooltip>
-                );
+                </Tooltip>);
                 list.push(item);
               });
             }

+ 3 - 1
server/gateway-api/src/main/java/com/qxgmat/controller/api/QuestionController.java

@@ -465,7 +465,9 @@ public class QuestionController {
             if(user != null){
                 if (serviceKey != null){
                     // 服务, 判断对应服务状态
-                    dto.setHasService(userServiceService.hasService(user.getId(), serviceKey));
+                    UserService userService = userServiceService.getService(user.getId(), serviceKey);
+                    dto.setHasService(userService!= null);
+                    dto.setExpireTime(userService != null ? userService.getExpireTime() : null);
                     UserOrderRecord record = userOrderRecordService.getUnUseService(user.getId(), serviceKey);
                     dto.setUnUseRecord(Transform.convert(record, UserServiceRecordExtendDto.class));
                 }

+ 3 - 1
server/gateway-api/src/main/java/com/qxgmat/controller/api/TextbookController.java

@@ -143,7 +143,9 @@ public class TextbookController
             Map<Object, UserQuestionStat> userQuestionStatMap = null;
             if(user != null){
                 if (dto.getNeedService()){
-                    dto.setHasService(userServiceService.hasService(user.getId(), ServiceKey.TEXTBOOK));
+                    UserService userService = userServiceService.getService(user.getId(), ServiceKey.TEXTBOOK);
+                    dto.setHasService(userService != null);
+                    dto.setExpireTime(userService != null ? userService.getExpireTime() : null);
                     // 服务, 判断对应服务状态
                     UserOrderRecord record = userOrderRecordService.getUnUseService(user.getId(), ServiceKey.TEXTBOOK);
                     dto.setUnUseRecord(Transform.convert(record, UserServiceRecordExtendDto.class));

+ 12 - 0
server/gateway-api/src/main/java/com/qxgmat/dto/response/UserExaminationGroupDto.java

@@ -2,6 +2,8 @@ package com.qxgmat.dto.response;
 
 import com.qxgmat.dto.extend.UserServiceRecordExtendDto;
 
+import java.util.Date;
+
 public class UserExaminationGroupDto {
     private Integer id;
     private String titleZh;
@@ -22,6 +24,8 @@ public class UserExaminationGroupDto {
 
     private Boolean hasService;
 
+    private Date expireTime;
+
     private UserServiceRecordExtendDto unUseRecord;
 
     public Integer getId() {
@@ -119,4 +123,12 @@ public class UserExaminationGroupDto {
     public void setNeedService(Boolean needService) {
         this.needService = needService;
     }
+
+    public Date getExpireTime() {
+        return expireTime;
+    }
+
+    public void setExpireTime(Date expireTime) {
+        this.expireTime = expireTime;
+    }
 }

+ 10 - 0
server/gateway-api/src/main/java/com/qxgmat/dto/response/UserTextbookGroupDto.java

@@ -26,6 +26,8 @@ public class UserTextbookGroupDto {
 
     private Boolean hasService;
 
+    private Date expireTime;
+
     private UserServiceRecordExtendDto unUseRecord;
 
     private Integer questionNumber;
@@ -151,4 +153,12 @@ public class UserTextbookGroupDto {
     public void setIsLatest(Integer isLatest) {
         this.isLatest = isLatest;
     }
+
+    public Date getExpireTime() {
+        return expireTime;
+    }
+
+    public void setExpireTime(Date expireTime) {
+        this.expireTime = expireTime;
+    }
 }