Browse Source

热门知识bug

彭宇 1 year ago
parent
commit
a70d544a05
1 changed files with 27 additions and 8 deletions
  1. 27 8
      pages/index/index.vue

+ 27 - 8
pages/index/index.vue

@@ -400,14 +400,27 @@
 			},
 			// 热门知识获取数据
 			getList() {
-				popularKnowledgeList(this.knowledgeParams).then(res => {
-					if (res.code == 200) {
-						this.dataSource = [...this.dataSource,...res.rows]
-						this.total = res.total
-						console.log("this.dataSource", this.dataSource)
-					}
-				})
+        popularKnowledgeList(this.knowledgeParams).then(res => {
+          if (res.code == 200) {
+            this.dataSource = this.cutarray([...this.dataSource,...res.rows])
+            this.total = res.total
+            console.log("this.dataSource", this.dataSource)
+          }
+        })
 			},
+      cutarray(arr) {//数组去重
+        let obj = {};    //obj用来记录该项重复出现了几次
+        let brr = [];    //brr是去重后的数组
+        arr.forEach((item) => {
+          if (obj[item.id] == undefined) {
+            obj[item.id] = 1;
+            brr.push(item);
+          } else {
+            obj[item.id] += 1;
+          }
+        });
+        return brr;
+      },
 			toLegal() {
 				uni.navigateTo({
 					url: '/pages/information/toLegal/toLegal'
@@ -563,6 +576,7 @@
 								title: '您的积分不足'
 							})
 						} else {
+              this.getList()
 							this.reduceScore(item)
 							this.addScore(item)
 							uni.navigateTo({
@@ -570,7 +584,12 @@
 							});
 						}
 					});
-				}
+				}else{
+          this.getList()
+          uni.navigateTo({
+            url: '/pages/highServer/knowledgeDetails/knowledgeDetails?id=' + item.id,
+          });
+        }
 			},
 			/**
 			 * 减少积分