Selaa lähdekoodia

feat: display line chart in person cards based on ranking data availability

Yannay 4 päivää sitten
vanhempi
commit
46bd5cfa33
1 muutettua tiedostoa jossa 9 lisäystä ja 4 poistoa
  1. 9 4
      pages/person/cards/index.vue

+ 9 - 4
pages/person/cards/index.vue

@@ -105,8 +105,8 @@
105 105
                 </view>
106 106
             </view>
107 107
 
108
-            <!-- 折线图 -->
109
-            <view class="card_item" v-if="false">
108
+            <!-- 折线图:仅在有排名数据时展示 -->
109
+            <view class="card_item" v-if="hasRankingData">
110 110
                 <view class="chart_header">
111 111
                     <image class="chart_icon" src="../../../static/icons/line.png" alt=""></image>
112 112
                     <text class="card_title">近7天排名折线图</text>
@@ -197,6 +197,8 @@ export default {
197 197
             },
198 198
             clueList: [],
199 199
             currentTab: 0,
200
+            /** 近7天排名接口返回是否有数据,用于控制折线图是否展示 */
201
+            hasRankingData: false,
200 202
             tabList: [{
201 203
                 name: '当日',
202 204
                 value: 'today'
@@ -248,7 +250,7 @@ export default {
248 250
         },
249 251
         async getChartData() {
250 252
             const res = await uni.$u.api.getPersonRanking({ userId: this.$store.state.user.userInfo.userId });
251
-            if (res.code === 200) {
253
+            if (res.code === 200 && res.data && res.data.length > 0) {
252 254
                 let data = {
253 255
                     categories: res.data.map(item => item.x),
254 256
                     series: [
@@ -264,7 +266,10 @@ export default {
264 266
                         }
265 267
                     ]
266 268
                 }
267
-                this.chartData = JSON.parse(JSON.stringify(data))
269
+                this.chartData = JSON.parse(JSON.stringify(data));
270
+                this.hasRankingData = true;
271
+            } else {
272
+                this.hasRankingData = false;
268 273
             }
269 274
         },
270 275
         // 跳转私有线索页面