xunji-wode-zhuye.vue
12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<template>
<view class="container">
<view class="safe-area-top" :style="{ paddingTop: topSafeArea + 'px' }" @click="goBack">
<uni-nav-bar left-icon="left" backgroundColor="transparent" :border="false" fixed dark />
</view>
<!-- 背景图片 -->
<view class="backgroundImage">
<image
:src="
backgroundImage
? backgroundImage
: 'https://fitness-hcxtec-bucket.oss-cn-shenzhen.aliyuncs.com/20260316/order-empty_1773628059920.png'
"
class="img"
mode="aspectFill"
></image>
</view>
<!-- 内容 -->
<view class="content">
<view class="info">
<view class="left">
<view class="avatar">
<image
:src="
avatar
? avatar
: 'https://fitness-hcxtec-bucket.oss-cn-shenzhen.aliyuncs.com/20260526/默认头像_1779779926983.png'
"
class="img"
mode="aspectFill"
></image>
</view>
<view class="user-info">
<view class="nickname">{{ nickname }}</view>
<view class="user-tip"> 运动爱好者 </view>
</view>
</view>
<view class="right">
<view class="edit-btn" @click="openPopup">编辑</view>
</view>
</view>
<view class="signature" @click="goToEditSignature">
{{ signature ? signature : '点击这里,填写签名' }}
</view>
<view class="medal" v-if="medalList.length > 0">
<view class="title"> 勋章 </view>
<view class="medal-list">
<view class="medal-item" v-for="(item, index) in medalList" :key="index">
<image :src="item.image" class="img" mode="aspectFill"></image>
</view>
<uni-icons
type="right"
size="24"
color="#999"
@click="uni.navigateTo({ url: '/pages5/pages/user/wode-xunzhang' })"
></uni-icons>
</view>
</view>
<view class="trajectory">
<view class="header">
<view class="title"> 运动轨迹 </view>
<view class="data">
在鸿星运动<text class="time">{{ exerciseMinuteCount }}</text
>min,消耗<text class="energy">{{ calorieCount }}</text
>kcal
</view>
</view>
<view class="graph">
<!-- 点阵区域(基于motionMatrix渲染) -->
<view class="track-grid">
<!-- 星期标签(固定“一、三、五、日”) -->
<view class="week-labels">
<text
class="week-item"
v-for="(week, idx) in ['一', '二', '三', '四', '五', '六', '日']"
:key="idx"
>
{{ week !== '二' && week !== '六' && week !== '四' ? week : '' }}
</text>
</view>
<view class="month-dots">
<!-- 月份标签(改用后端返回的motionXAxis) -->
<view class="month-tabs">
<text class="month-item" v-for="(month, idx) in motionXAxis" :key="idx">
{{ month }}
</text>
</view>
<!-- 点阵(遍历motionMatrix渲染,false为灰色,可扩展true为彩色) -->
<view class="grid-dots">
<view class="dot-row" v-for="(row, rowIdx) in motionMatrix" :key="rowIdx">
<view
class="dot"
v-for="(isActive, colIdx) in row"
:key="colIdx"
:class="{ active: isActive }"
></view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 弹框 -->
<uni-popup ref="popup" background-color="#fff" type="bottom">
<view class="action-popup">
<view class="popup-item" @click="goToEditProfile">编辑资料</view>
<view class="popup-item" @click="handleChangeBg">更换背景图</view>
<view class="popup-item cancel" @click="handleCancel">取消</view>
</view>
</uni-popup>
</view>
</template>
<script setup>
import { ref } from 'vue';
import UserApi from '@/sheep/api/member/user.js';
import { onShow } from '@dcloudio/uni-app';
import { getTopSafeArea } from '@/utils/safeArea';
let topSafeArea = 0;
// #ifdef MP-WEIXIN
topSafeArea = getTopSafeArea();
// #endif
const popup = ref(null); // 定义弹窗引用
const backgroundImage = ref(''); // 背景图片
const nickname = ref(''); // 昵称
const avatar = ref(''); // 头像
const signature = ref(''); // 签名
const exerciseMinuteCount = ref(0); // 运动分钟数
const calorieCount = ref(0); // 消耗卡路里
const motionXAxis = ref([]); // 运动轨迹X轴
const motionMatrix = ref([]); // 运动轨迹矩阵
const medalList = ref([]); // 奖牌列表
onShow(() => {
getMotionData();
});
// 返回上一页
const goBack = () => {
uni.navigateBack();
};
// 打开弹窗
const openPopup = () => {
popup.value.open();
};
// 关闭弹窗
const handleCancel = () => {
popup.value.close();
};
// 获取运动轨迹数据
const getMotionData = async () => {
const res = await UserApi.getTrajectory();
nickname.value = res.data.nickname;
avatar.value = res.data.avatar;
signature.value = res.data.signature;
exerciseMinuteCount.value = res.data.exerciseMinuteCount;
calorieCount.value = res.data.calorieCount;
motionXAxis.value = res.data.motionXAxis;
motionMatrix.value = res.data.motionMatrix;
backgroundImage.value = res.data.backgroundImage;
medalList.value = res.data.medalList || [];
};
// 更换背景图
const handleChangeBg = () => {
popup.value.close();
// 调用选择图片接口
uni.chooseMedia({
count: 1, // 仅选1张背景图
mediaType: ['image'], // 只选图片
success: (res) => {
// 选择成功,res.tempFiles是选中的文件数组
UserApi.updateBgImage({
data: res.tempFiles[0].tempFilePath,
}).then(() => {
getMotionData();
});
},
fail: (err) => {
// 选择失败(如用户取消、权限不足)
uni.showToast({
title: '选择图片失败',
icon: 'none',
});
},
});
};
//
const goToEditProfile = () => {
popup.value.close();
uni.navigateTo({ url: '/pages5/pages/user/wode-geren-ziliao' });
};
// 跳转编辑签名
const goToEditSignature = () => {
uni.navigateTo({ url: '/pages4/pages/xunji/xunji-wode-qianming?signature=' + signature.value });
};
</script>
<style lang="scss" scoped>
.container {
width: 100%;
height: 100%;
.backgroundImage {
width: 100%;
height: 350rpx;
position: absolute;
top: 0;
background-color: bisque;
.img {
width: 100%;
height: 100%;
}
}
.content {
position: absolute;
top: 320rpx;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
padding: 0 20rpx;
background-color: #fff;
width: 100%;
box-sizing: border-box;
height: calc(100% - 320rpx);
.info {
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
margin-bottom: 130rpx;
.left {
height: 140rpx;
display: flex;
box-sizing: border-box;
align-items: center;
position: absolute;
top: -20rpx;
.avatar {
width: 140rpx;
height: 140rpx;
border-radius: 50%;
overflow: hidden;
background: #fff;
padding: 8rpx;
box-sizing: border-box;
margin-right: 15rpx;
.img {
width: 100%;
height: 100%;
border-radius: 50%;
}
}
.user-info {
.nickname {
font-size: 28rpx;
font-weight: 500;
color: #333333;
margin-bottom: 8rpx;
}
.user-tip {
background-color: #f7c29f;
padding: 5rpx 8rpx;
border-radius: 5rpx;
font-size: 20rpx;
font-weight: 400;
color: #a15624;
}
}
}
.right {
height: 140rpx;
display: flex;
box-sizing: border-box;
align-items: center;
position: absolute;
top: -20rpx;
right: 0;
.edit-btn {
background-color: #e68f55;
padding: 10rpx 20rpx;
border-radius: 5rpx;
font-size: 24rpx;
font-weight: 400;
color: #fff;
}
}
}
.medal {
width: 100%;
margin-bottom: 40rpx;
.title {
font-size: 30rpx;
font-weight: 550;
color: #333333;
margin-bottom: 20rpx;
}
.medal-list {
display: flex;
justify-content: space-between;
align-items: center;
.medal-item {
width: 90%;
gap: 30rpx;
background: #fff;
padding: 8rpx;
box-sizing: border-box;
display: flex;
align-items: center;
.img {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
}
}
}
}
.signature {
font-size: 20rpx;
font-weight: 400;
color: #999999;
margin-top: 20rpx;
margin-bottom: 80rpx;
}
.trajectory {
.header {
display: flex;
justify-content: space-between;
align-items: center;
.title {
font-size: 28rpx;
font-weight: 500;
color: #333333;
}
.data {
font-size: 20rpx;
font-weight: 400;
color: #999999;
.time,
.energy {
margin: 0 5rpx;
font-size: 24rpx;
font-weight: 500;
color: rgb(84, 198, 233);
}
}
}
.graph {
padding: 10rpx 5rpx;
// 星期标签和点阵容器
.track-grid {
display: flex;
align-items: flex-start;
padding: 0 8rpx;
.week-labels {
display: flex;
flex-direction: column;
margin-right: 18rpx;
padding-top: 48rpx;
.week-item {
font-size: 20rpx;
color: #999999;
height: 40rpx;
width: 20rpx;
text-align: center;
}
}
.month-dots {
// 月份标签样式
.month-tabs {
display: flex;
justify-content: space-between;
margin-bottom: 20rpx;
.month-item {
width: calc(100% / 6);
font-size: 22rpx;
color: #999999;
text-align: start;
line-height: 30rpx;
height: 30rpx;
}
}
}
}
// 点阵样式
.grid-dots {
flex: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
.dot-row {
display: flex;
margin-bottom: 11rpx;
align-items: center;
height: 30rpx;
.dot {
// 原无运动样式
width: 15rpx;
height: 15rpx;
border-radius: 50%;
background: #f8f8f8; // 无运动:浅灰
margin-right: 11rpx;
border: 1rpx solid #e5e5e5;
box-sizing: border-box;
// 有运动样式(可自定义颜色)
&.active {
background: #409eff; // 有运动:蓝色(示例)
border: none;
}
}
}
}
}
}
}
// 底部操作弹窗
.action-popup {
background: #fff;
border-top-left-radius: 24rpx;
border-top-right-radius: 24rpx;
padding: 24rpx 0;
.popup-item {
font-size: 32rpx;
color: #333;
text-align: center;
padding: 32rpx 0;
border-bottom: 1px solid #f5f5f5;
&.cancel {
color: #ff4d4f;
border-bottom: none;
}
}
}
}
</style>