liyongli 3 роки тому
батько
коміт
9aabedb28e
1 змінених файлів з 79 додано та 70 видалено
  1. 79 70
      src/components/maincomponents.vue

+ 79 - 70
src/components/maincomponents.vue

@@ -194,82 +194,91 @@ export default {
     type() {
       this.bmGet();
     },
+    hd() {
+      this.init();
+    },
+    topic() {
+      this.init();
+    },
   },
   mounted() {
     this.height = (this.$refs.main.offsetWidth / 24) * 6.9;
-    linechart && linechart.destroy();
-    barchart && barchart.destroy();
-    piechart && piechart.destroy();
-    linechart = null;
-    barchart = null;
-    piechart = null;
-    platformData(this.topic).then(r => {
-      let platform = {},
-        pli = [];
-      for (let i = 0; i < (r || []).length; i++) {
-        const v = (r || [])[i];
-        if (v.platform === "总传播量") {
-          this.playT = v.playCount || 0;
-          continue;
-        }
-        if (!platform[v.platform] && platform[v.platform] !== 0) {
-          platform[v.platform] = pli.length;
-          pli.push({ p: v.platform, val: v.playCount, a: 1 });
-        } else {
-          pli[platform[v.platform]] &&
-            (pli[platform[v.platform]].val += v.playCount);
-        }
-      }
-      this.plays = pli;
-      this.pie1(pli);
-    });
-    qushiData(this.topic).then(r => {
-      this.line1(r);
-    });
-    this.bmGet();
-    pingtaiData({
-      depRange: "ALL",
-      title: this.topic,
-    }).then(r => {
-      this.platformList = (r || []).sort((a, b) => b.readTotal - a.readTotal);
-      //   let obj = {},
-      //     li = [];
-      //   for (let i = 0; i < this.platformList.length; i++) {
-      //     const v = this.platformList[i];
-      //     let l = v.list || [];
-      //     l.map(o => {
-      //       if (!obj[o.platform] && obj[o.platform] !== 0) {
-      //         obj[o.platform] = li.length;
-      //         li.push({
-      //           platform: o.platform || "",
-      //           publishCount: o.publishCount || 0,
-      //           readCount: o.readCount || 0,
-      //         });
-      //       } else {
-      //         li[obj[o.platform]].publishCount = o.publishCount;
-      //         li[obj[o.platform]].readCount = o.readCount;
-      //       }
-      //     });
-      //   }
-      //   this.pie1(li);
-    });
-    this.grtzhData();
-    bumenList().then(r => {
-      let options = (r || []).map(v => {
-        return {
-          value: v.depName,
-          label: v.depName,
-        };
-      });
-      options.unshift({
-        value: "全部",
-        label: "全部",
-      });
-      this.options = options;
-    });
+    this.init();
   },
   computed: {},
   methods: {
+    init() {
+      linechart && linechart.destroy();
+      barchart && barchart.destroy();
+      piechart && piechart.destroy();
+      linechart = null;
+      barchart = null;
+      piechart = null;
+      platformData(this.topic).then(r => {
+        let platform = {},
+          pli = [];
+        for (let i = 0; i < (r || []).length; i++) {
+          const v = (r || [])[i];
+          if (v.platform === "总传播量") {
+            this.playT = v.playCount || 0;
+            continue;
+          }
+          if (!platform[v.platform] && platform[v.platform] !== 0) {
+            platform[v.platform] = pli.length;
+            pli.push({ p: v.platform, val: v.playCount, a: 1 });
+          } else {
+            pli[platform[v.platform]] &&
+              (pli[platform[v.platform]].val += v.playCount);
+          }
+        }
+        this.plays = pli;
+        this.pie1(pli);
+      });
+      qushiData(this.topic).then(r => {
+        this.line1(r);
+      });
+      this.bmGet();
+      pingtaiData({
+        depRange: "ALL",
+        title: this.topic,
+      }).then(r => {
+        this.platformList = (r || []).sort((a, b) => b.readTotal - a.readTotal);
+        //   let obj = {},
+        //     li = [];
+        //   for (let i = 0; i < this.platformList.length; i++) {
+        //     const v = this.platformList[i];
+        //     let l = v.list || [];
+        //     l.map(o => {
+        //       if (!obj[o.platform] && obj[o.platform] !== 0) {
+        //         obj[o.platform] = li.length;
+        //         li.push({
+        //           platform: o.platform || "",
+        //           publishCount: o.publishCount || 0,
+        //           readCount: o.readCount || 0,
+        //         });
+        //       } else {
+        //         li[obj[o.platform]].publishCount = o.publishCount;
+        //         li[obj[o.platform]].readCount = o.readCount;
+        //       }
+        //     });
+        //   }
+        //   this.pie1(li);
+      });
+      this.grtzhData();
+      bumenList().then(r => {
+        let options = (r || []).map(v => {
+          return {
+            value: v.depName,
+            label: v.depName,
+          };
+        });
+        options.unshift({
+          value: "全部",
+          label: "全部",
+        });
+        this.options = options;
+      });
+    },
     change() {
       this.grtzhData();
     },