Przeglądaj źródła

阅读器修改

wangzq 2 lat temu
rodzic
commit
e2143f75dd
1 zmienionych plików z 63 dodań i 13 usunięć
  1. 63 13
      src/views/Reader/index.ux

+ 63 - 13
src/views/Reader/index.ux

@@ -1,5 +1,6 @@
 <import name="short-page" src="../../components/short/index.ux"></import>
  <import name="wechat-page" src="../../components/wechat/index.ux"></import> 
+<import name="recom-page" src="../../components/book/read_recom.ux"></import>
 <template>
   <div id="reader-content">
     <stack>   
@@ -49,6 +50,7 @@
             </swiper>
           </div>
         </div>
+         <recom-page if="{{isShowBackRecom}}"  @addshort="changeRecomEnd"  recom_list="{{recom_list}}"></recom-page>
         <short-page if="{{showShortPop}}" @addshort="shortEnd" bottom="40"></short-page>
         <!-- <wechat-page></wechat-page> -->
         <div class='toast' if="{{showtoast}}">
@@ -249,6 +251,7 @@ export default {
     }).catch(r => {
       //TODO 失败后统计上报
     });
+    this.getRecomList();
   },
   goActivity(item) {
     router.push({
@@ -263,6 +266,7 @@ export default {
     })
   },
   backRouter() {
+    this.back_reader = 1;
     if (this.back_reader == 1) {
       it.backCreateShortCut(res => {
         if (res == 'back') {
@@ -515,28 +519,74 @@ export default {
 
   },
   onBackPress() {
+    this.back_reader = 1;
+    let that = this;
     if (this.back_reader == 1) {
+      if(this.back_nums == 0 && this.recom_list.length > 0){
+          this.showShortPop = false;
+          this.back_nums = 2;
+          this.isShowBackRecom = true;
+          return true;
+      }
+      if(this.back_nums == 2){
+          if(!this.hasShort){
+            this.showShortPop = true;
+          }
+          this.back_nums = 3;
+          this.isShowBackRecom = false;
+          return true;
+      }
+
       it.backCreateShortCut(res => {
         if (res == 'back') {
-          if (router.getLength() === 1) {
-            router.replace({ uri: "/views/Index" });
-            return true;
-          } else {
-            router.back()
-          }
+          that.getLastPage();
+          return true;
         }
       });
     } else {
-      if (router.getLength() === 1) {
-        router.replace({ uri: "/views/Index" });
-        return true;
-      } else {
-        router.back()
-      }
+      that.getLastPage();
     }
 
-
+    that.getLastPage();
     return true;
+  },async changeRecomEnd(data){
+    if(data.detail.op == "change_book"){
+      this.getRecomList(1);
+      
+    }else if(data.detail.op =="close"){
+      this.isShowBackRecom = false;
+    }
+  },async getRecomList(isChang=0){
+    let recom_list =  await recommendBooks(this.last_recom_bid);
+    if(recom_list.length > 0){
+      this.recom_list = recom_list;
+      this.last_recom_bid = recom_list[recom_list.length-1].book_id;
+    }
+    if(isChang == 1 || !this.last_recom_bid || this.last_recom_bid == ''){
+        await storage.set({ key: "last_recom_bid", value: this.last_recom_bid });
+    }
+  
+    // console.log(this.recom_list.length);
+    // if(this.recom_list.length == 3){
+    //   return true;
+    // }
+    
+  },getLastPage(){
+      let page = router.getState();
+      let allPage = router.getPages();
+      let back = {};
+      for (var i = allPage.length - 1; i >= 0; i--)
+      {
+        if (allPage[i].name != page.name) {
+          back = allPage[i];
+          break;
+        }
+      }
+      if(JSON.stringify(back) === '{}'){
+        router.replace({ uri: "/views/Index" });
+      }else{
+        router.back(back);
+      }
   }
 }
 </script>