Эх сурвалжийг харах

feat: 标讯详情页列表提示优化

cuiyalong 1 жил өмнө
parent
commit
8f4d37c8b8

+ 5 - 2
src/pages/search/content/bidding/components/ContentProjectTimeline.vue

@@ -123,15 +123,18 @@ export default {
   },
   methods: {
     async itemClick(item) {
+      if (item.isActive) return
       if (this.beforeLeavePage) {
-        await this.beforeLeavePage()
+        const r = await this.beforeLeavePage(item)
+        if (!r) {
+          return
+        }
       }
       this.toArticleContent(item)
     },
     toArticleContent(item) {
       const id = item.id
       if (!id) return
-      if (item.isActive) return
       Taro.navigateTo({
         url: `/pages/search/content/bidding/index?id=${item.id}`,
       })

+ 75 - 18
src/pages/search/content/bidding/index.vue

@@ -36,6 +36,7 @@
                   class="tab-module"
                   :main-model="mainModel"
                   :expand-model="expandModel"
+                  :before-leave-page="beforeClickArticle"
                   :other-model="otherModel"
                 />
               </view>
@@ -63,7 +64,7 @@ import ToLoginDialog from '@/components/dialog/ToLoginDialog.vue'
 import PopupCustomerQR from '@/components/common/PopupCustomerQR.vue'
 import useContentModel from '@/data-models/modules/article/model/content'
 import useExpandModel from '@/data-models/modules/article/model/expand'
-import { getBiddingDetail } from '@/api/modules/search'
+import { getBiddingDetail, checkArticleReadMax } from '@/api/modules/search'
 const { model: mainModel, transformModel: contentTransform } = useContentModel()
 const { model: expandModel, transformModel: expandTransform } = useExpandModel()
 import { setTrackLog } from '@/track'
@@ -134,6 +135,7 @@ export default {
   data() {
     return {
       pageContentData: cloneDeep(defaultValueMap),
+      loading: false,
       popup: {
         customerQrShow: false
       },
@@ -307,21 +309,8 @@ export default {
               this.$nextTick(() => {
                 this.finishLoading()
               })
-            } else if (status === -5) {
-              // 免费用户配置免费可读的是0,直接跳转去购买
-              this.toBuyVip()
-            } else if (status === -4) {
-              // 免费用户查看达到上限,配置的免费可读数量不是0
-              this.showReadMaxDialog()
-            } else if (status === -3) {
-              // 付费用户查看次数用完
-              this.showVipReadMaxDialog()
-            } else if (status === -2) {
-              // 配置错误
-              // showToast('配置错误')
-            } else if (status === -1) {
-              console.log('未登录')
-              this.dialog.toLogin = true
+            } else {
+              this.showNoPowerCallback(status, 'content')
             }
           } else {
             if (res.error_code === 1001) {
@@ -353,6 +342,72 @@ export default {
         phoneNumber: phone
       })
     },
+    async checkArticleReadMax(id) {
+      const {
+        data,
+        error_code: code = 0,
+        error_msg: msg
+      } = await checkArticleReadMax({
+        id,
+        type: 1
+      })
+
+      if (code === 1001) {
+        return -1
+      }
+
+      if (data) {
+        return data.isView // 0可正常访问。-1:未登录,-2:配置错误,-3:付费次数用完,-4:免费次数用完,-5 免费用户配置可读的是0
+      } else {
+        return true
+      }
+    },
+    // type: list/content
+    showNoPowerCallback(status, type = 'content') {
+      if (status === -5) {
+        // 免费用户配置免费可读的是0,直接跳转去购买
+        this.toBuyVip()
+      } else if (status === -4) {
+        // 免费用户查看达到上限,配置的免费可读数量不是0
+        this.showReadMaxDialog(type)
+      } else if (status === -3) {
+        // 付费用户查看次数用完
+        if (type === 'content') {
+          this.showVipReadMaxDialog()
+        } else {
+          showToast('查看标讯数量已达到上限')
+        }
+      } else if (status === -2) {
+        // 配置错误
+        showToast('配置错误')
+      } else if (status === -1) {
+        console.log('未登录')
+        this.dialog.toLogin = true
+      } else {
+        console.log('未知的status')
+      }
+    },
+    async beforeClickArticle(item) {
+      let id = item.id
+      if (this.loading) {
+        return
+      }
+      this.loading = true
+      try {
+        const status = await this.checkArticleReadMax(id)
+        if (status === 0) {
+          return true
+        } else {
+          this.showNoPowerCallback(status, 'list')
+          return false
+        }
+      } catch (error) {
+        console.log(error)
+        return true
+      } finally {
+        this.loading = false
+      }
+    },
     showVipReadMaxDialog() {
       const defaultConf = {
         title: '',
@@ -371,7 +426,7 @@ export default {
         this.doBack()
       })
     },
-    showReadMaxDialog() {
+    showReadMaxDialog(type) {
       const defaultConf = {
         title: '免费查看项目数量已达上限',
         message: '您当前免费查看项目数量已达上限,您可购买会员获取更多查看标讯权限。',
@@ -388,7 +443,9 @@ export default {
         this.toBuyVip()
       }).catch((e) => {
         // 如果是分享过来的,则做其他操作
-        this.doBack()
+        if (type !== 'list') {
+          this.doBack()
+        }
       })
     },
     toBuyVip() {