瀏覽代碼

feat: 超级订阅关键词数量统计逻辑调整

cuiyalong 4 年之前
父節點
當前提交
6b18fd1c28

+ 17 - 1
src/jfw/modules/app/src/web/staticres/jyapp/vipsubscribe/js/keyWord.js

@@ -38,6 +38,23 @@ var vm = new Vue({
     selectedCount: function () {
       var selectedArr = this.getSelectedArr()
       return selectedArr.length
+    },
+    totalKeywordsCount: function () {
+      var count = 0
+      this.filter.allKeywordsList.forEach(function (item) {
+        if (item.matchway == 1) {
+          // 模糊匹配
+          var key = item.key
+          if (Array.isArray(item.appendkey)) {
+            key = key.concat(item.appendkey)
+          }
+          count += key.length
+        } else {
+          // 精准匹配(matchway:0/undefined)
+          count++
+        }
+      })
+      return count
     }
   },
   created: function () {
@@ -348,7 +365,6 @@ var vm = new Vue({
     getGroupIndexWithGroupName: function (gn) {
       var groupIndex = -1
       this.keywordsGroupList.forEach(function(item, index) {
-        console.log(item)
         if (gn === item.s_item) {
           groupIndex = index
         }

+ 20 - 4
src/jfw/modules/app/src/web/staticres/jyapp/vipsubscribe/js/keyword-info.js

@@ -50,16 +50,28 @@ var vm = new Vue({
     tooLittleTipShow: function () {
       return this.pInfo.pushCount < 30
     },
+    // 监听关键词和匹配方式变化
+    needGetRecList: function () {
+      return {
+        key: this.keyInfo.key,
+        matchWay: this.keyInfo.matchWay
+      }
+    },
+    // 监听关键词、匹配方式和排除词变化
     keyInfoChange: function () {
       return {
         key: this.keyInfo.key,
+        notKey: this.keyInfo.notKey,
         matchWay: this.keyInfo.matchWay
       }
     }
   },
   watch: {
-    keyInfoChange: utils.debounce(function (newVal, oldVal) {
+    needGetRecList: utils.debounce(function (newVal, oldVal) {
       this.getKeyRecommend()
+    }, 2000),
+    keyInfoChange: utils.debounce(function () {
+      this.getPushCount()
     }, 2000)
   },
   created: function () {
@@ -81,9 +93,6 @@ var vm = new Vue({
         if (this.pInfo.editType === 'add') {
           this.getKeyRecommend()
         }
-        if (this.pInfo.editType === 'edit') {
-          this.getPushCount()
-        }
       }.bind(this)
     })
   },
@@ -512,6 +521,9 @@ var vm = new Vue({
 
       if (keysArr.length === 0) return
 
+      if (this.recListState.loading) return
+      this.recListState.loading = true
+
       var fetchData = {
         count: 20, // 最少需要多少条数据
         value: utils.unique(keysArr).join(' ')
@@ -521,9 +533,13 @@ var vm = new Vue({
         type: 'POST',
         data: fetchData,
         success: function (r) {
+          _this.recListState.loading = false
           if (r && r instanceof Array && r.length !== 0) {
             _this.loadKeyRecommend(r)
           }
+        },
+        complete: function () {
+          _this.recListState.loading = false
         }
       })
     },

+ 1 - 1
src/jfw/modules/app/src/web/templates/vipsubscribe/infoWord.html

@@ -94,7 +94,7 @@
         </div>
         <div class="j-footer">
             <van-notice-bar
-                v-show="tooLittleTipShow && pInfo.editType === 'edit'"
+                v-show="tooLittleTipShow"
                 class="footer-tip center"
                 color="#ff9f40"
                 background="#fff4e8"

+ 2 - 2
src/jfw/modules/app/src/web/templates/vipsubscribe/keyWord.html

@@ -92,7 +92,7 @@
                     <span class="button-text">订阅关键词</span>
                 </button>
                 <div class="keywords-count">
-                    关键词添加数量:<span class="highlight-text">${ filter.allKeywordsList.length }</span> / ${ conf.keywordMax }
+                    关键词添加数量:<span class="highlight-text">${ totalKeywordsCount }</span> / ${ conf.keywordMax }
                 </div>
           </div>
         </div>
@@ -114,7 +114,7 @@
             <div class="j-button-group" v-else>
                 <button class="j-button-confirm" @click="addKeyWord" :disabled="filter.allKeywordsList.length >= conf.keywordMax">
                     <span class="info-text">新增关键词</span>
-                    <span class="sub-text">(${ filter.allKeywordsList.length } / ${ conf.keywordMax })</span>
+                    <span class="sub-text">(${ totalKeywordsCount } / ${ conf.keywordMax })</span>
                 </button>
             </div>
         </div>

+ 17 - 1
src/web/staticres/vipsubscribe/js/keyWord.js

@@ -38,6 +38,23 @@ var vm = new Vue({
     selectedCount: function () {
       var selectedArr = this.getSelectedArr()
       return selectedArr.length
+    },
+    totalKeywordsCount: function () {
+      var count = 0
+      this.filter.allKeywordsList.forEach(function (item) {
+        if (item.matchway == 1) {
+          // 模糊匹配
+          var key = item.key
+          if (Array.isArray(item.appendkey)) {
+            key = key.concat(item.appendkey)
+          }
+          count += key.length
+        } else {
+          // 精准匹配(matchway:0/undefined)
+          count++
+        }
+      })
+      return count
     }
   },
   created: function () {
@@ -348,7 +365,6 @@ var vm = new Vue({
     getGroupIndexWithGroupName: function (gn) {
       var groupIndex = -1
       this.keywordsGroupList.forEach(function(item, index) {
-        console.log(item)
         if (gn === item.s_item) {
           groupIndex = index
         }

+ 21 - 4
src/web/staticres/vipsubscribe/js/keyword-info.js

@@ -50,16 +50,28 @@ var vm = new Vue({
     tooLittleTipShow: function () {
       return this.pInfo.pushCount < 30
     },
+    // 监听关键词和匹配方式变化
+    needGetRecList: function () {
+      return {
+        key: this.keyInfo.key,
+        matchWay: this.keyInfo.matchWay
+      }
+    },
+    // 监听关键词、匹配方式和排除词变化
     keyInfoChange: function () {
       return {
         key: this.keyInfo.key,
+        notKey: this.keyInfo.notKey,
         matchWay: this.keyInfo.matchWay
       }
     }
   },
   watch: {
-    keyInfoChange: utils.debounce(function (newVal, oldVal) {
+    needGetRecList: utils.debounce(function (newVal, oldVal) {
       this.getKeyRecommend()
+    }, 2000),
+    keyInfoChange: utils.debounce(function () {
+      this.getPushCount()
     }, 2000)
   },
   created: function () {
@@ -81,9 +93,6 @@ var vm = new Vue({
         if (this.pInfo.editType === 'add') {
           this.getKeyRecommend()
         }
-        if (this.pInfo.editType === 'edit') {
-          this.getPushCount()
-        }
       }.bind(this)
     })
   },
@@ -516,14 +525,22 @@ var vm = new Vue({
         count: 20, // 最少需要多少条数据
         value: utils.unique(keysArr).join(' ')
       }
+
+      if (this.recListState.loading) return
+      this.recListState.loading = true
+
       $.ajax({
         url: '/member/getRecomKWs',
         type: 'POST',
         data: fetchData,
         success: function (r) {
+          _this.recListState.loading = false
           if (r && r instanceof Array && r.length !== 0) {
             _this.loadKeyRecommend(r)
           }
+        },
+        complete: function () {
+          _this.recListState.loading = false
         }
       })
     },

+ 1 - 1
src/web/templates/weixin/vipsubscribe/infoWord.html

@@ -93,7 +93,7 @@
             </div>
             <div class="j-footer">
                 <van-notice-bar
-                    v-show="tooLittleTipShow && pInfo.editType === 'edit'"
+                    v-show="tooLittleTipShow"
                     class="footer-tip center"
                     color="#ff9f40"
                     background="#fff4e8"

+ 2 - 2
src/web/templates/weixin/vipsubscribe/keyWord.html

@@ -86,7 +86,7 @@
                     <span class="button-text">订阅关键词</span>
                 </button>
                 <div class="keywords-count">
-                    关键词添加数量:<span class="highlight-text">${ filter.allKeywordsList.length }</span> / ${ conf.keywordMax }
+                    关键词添加数量:<span class="highlight-text">${ totalKeywordsCount }</span> / ${ conf.keywordMax }
                 </div>
           </div>
         </div>
@@ -108,7 +108,7 @@
             <div class="j-button-group" v-else>
                 <button class="j-button-confirm" @click="addKeyWord" :disabled="filter.allKeywordsList.length >= conf.keywordMax">
                     <span class="info-text">新增关键词</span>
-                    <span class="sub-text">(${ filter.allKeywordsList.length } / ${ conf.keywordMax })</span>
+                    <span class="sub-text">(${ totalKeywordsCount } / ${ conf.keywordMax })</span>
                 </button>
             </div>
         </div>