ソースを参照

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

Yannay 4 日 前
コミット
46bd5cfa33
共有1 個のファイルを変更した9 個の追加4 個の削除を含む
  1. 9 4
      pages/person/cards/index.vue

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

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