index.vue
26.1 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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-26 10:45:08
* @FilePath: /lls_program/src/pages/ActivitiesCover/index.vue
* @Description: 活动海报页面 - 展示活动信息并处理定位授权
-->
<template>
<view class="activities-cover-container">
<!-- 背景图片 -->
<image
:src="defaultPoster"
class="background-image"
:mode="imageDisplayMode"
/>
<!-- 分享按钮组件 -->
<ShareButton
:activity-data="activityData"
:share-config="shareConfig"
@share-activity="onShareActivity"
@share-poster="onSharePoster"
class="share-button-wrapper"
/>
<!-- 底部按钮区域 -->
<view class="bottom-section">
<!-- 积分规则说明 -->
<view class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-4 opacity-90">
<text class="text-blue-500 text-base font-medium block mb-2">积分规则说明:</text>
<text class="text-blue-500 text-sm leading-relaxed block mb-1" style="padding-left: 20rpx; text-indent: -20rpx;">• 打卡任意1关,视为参与,奖励1000积分</text>
<text class="text-blue-500 text-sm leading-relaxed block mb-1" style="padding-left: 20rpx; text-indent: -20rpx;">• 打卡任意7关,视为完成,奖励5000积分</text>
<text class="text-blue-500 text-sm leading-relaxed block mb-1" style="padding-left: 20rpx; text-indent: -20rpx;">• 不需要区分打卡点的先后次序</text>
</view>
<!-- 未授权定位提示 - 仅在用户点击参加活动且未授权时显示 -->
<view v-if="showLocationPrompt && !hasLocationAuth && !locationError" class="location-tip" @click="retryGetLocation">
<view class="tip-content">
<view class="tip-icon">📍</view>
<view class="tip-text">点击获取您的位置信息来参与活动</view>
</view>
<!-- <view class="tip-retry">点击重新获取</view> -->
</view>
<!-- 位置获取失败提示 -->
<view v-if="hasLocationAuth && locationError" class="location-tip location-error" @click="retryGetLocation">
<view class="tip-content">
<view class="tip-icon">⚠️</view>
<view class="tip-text">可能是网络问题,获取位置信息失败</view>
</view>
<!-- <view class="tip-retry">点击重新获取</view> -->
</view>
<nut-button
type="primary"
size="large"
class="join-button"
:color="activityStatus.is_ended || !activityStatus.is_begin ? '#cccccc' : THEME_COLORS.PRIMARY"
:loading="isJoining || activityStatus.loading"
:disabled="activityStatus.is_ended || !activityStatus.is_begin"
@click="checkFamilyStatusAndJoinActivity"
>
{{ getButtonText() }}
</nut-button>
</view>
<!-- 底部导航 -->
<BottomNav />
<!-- 海报预览弹窗 -->
<nut-popup
v-model:visible="show_post"
position="center"
class="poster-preview-popup"
>
<view class="wrapper">
<view class="preview-area" @click="onClickPost">
<image v-if="posterPath" :src="posterPath" mode="widthFix" />
</view>
</view>
</nut-popup>
<!-- 海报生成组件 -->
<PosterBuilder
v-if="startDraw"
custom-style="position: fixed; left: 200%;"
:config="base"
@success="drawSuccess"
@fail="drawFail"
/>
<!-- 保存选项弹窗 -->
<nut-action-sheet
v-model:visible="show_save"
:menu-items="actions_save"
@choose="onSelectSave"
@cancel="onCancelSave"
cancel-txt="取消"
/>
<!-- 位置权限申请弹窗 -->
<nut-dialog
v-model:visible="showLocationDialog"
title="位置权限申请"
>
<template #default>
<view class=" text-gray-700 leading-loose text-sm text-left">
{{ locationContent }}
</view>
</template>
<template #footer>
<nut-row :gutter="10">
<nut-col :span="12">
<nut-button
@click="onLocationCancel"
type="default"
size="normal"
block
>
暂不授权
</nut-button>
</nut-col>
<nut-col :span="12">
<nut-button
@click="onLocationConfirm"
type="primary"
size="normal"
:color="THEME_COLORS.PRIMARY"
block
>
同意授权
</nut-button>
</nut-col>
</nut-row>
</template>
</nut-dialog>
</view>
</template>
<script setup>
import { ref, onMounted, computed } from "vue"
import Taro, { useLoad } from '@tarojs/taro'
import "./index.less"
import BottomNav from '../../components/BottomNav.vue'
import PosterBuilder from '../../components/PosterBuilder/index.vue'
import ShareButton from '../../components/ShareButton/index.vue'
// 接口信息
import { getMyFamiliesAPI } from '@/api/family'
import { getActivityStatusAPI } from '@/api/map'
import { handleSharePageAuth, addShareFlag } from '@/utils/authRedirect'
// 导入主题颜色
import { THEME_COLORS } from '@/utils/config';
// 默认海报图
const defaultPoster = 'https://cdn.ipadbiz.cn/lls_prog/images/welcome_8.jpg?imageMogr2/strip/quality/60';
// 系统信息
const systemInfo = ref({});
/**
* 获取系统信息
*/
const getSystemInfo = () => {
try {
const info = Taro.getWindowInfo();
systemInfo.value = info;
} catch (error) {
console.error('获取系统信息失败:', error);
}
};
/**
* 检测是否为 iPad 类型设备
*/
const isTabletDevice = computed(() => {
if (!systemInfo.value.screenWidth) {
return false;
}
const { screenWidth, screenHeight } = systemInfo.value;
const screenRatio = screenWidth / screenHeight;
// iPad 类型设备通常屏幕比例在 0.7-0.8 之间(4:3 约为 0.75)
// 普通手机设备比例通常在 0.4-0.6 之间
return screenRatio > 0.65;
});
/**
* 计算图片显示模式
*/
const imageDisplayMode = computed(() => {
// iPad 类型设备使用 widthFix 模式,普通设备使用 aspectFill
return isTabletDevice.value ? 'widthFix' : 'aspectFill';
});
/**
* 活动海报页面组件
* 功能:展示活动信息、处理定位授权、跳转到活动页面
*/
// 页面状态
const hasLocationAuth = ref(false) // 是否已授权定位
const locationError = ref(false) // 位置获取是否失败
const isJoining = ref(false) // 是否正在加入活动
const userLocation = ref({ lng: null, lat: null }) // 用户位置信息
const hasJoinedFamily = ref(false);
const showLocationPrompt = ref(false) // 是否显示定位权限提示
// 活动状态相关
const activityStatus = ref({
is_begin: false, // 活动是否已开始
is_ended: false, // 活动是否已结束
loading: false // 是否正在加载活动状态
})
// Dialog 相关状态
const showLocationDialog = ref(false) // 是否显示位置权限申请弹窗
const pendingLocationCallback = ref(null) // 待执行的位置获取回调
// 位置权限申请说明内容
const locationContent = '为了提供更好的活动体验,我们需要获取您的位置信息:验证您是否在活动区域内, 我们承诺严格保护您的位置隐私,仅用于活动相关功能。'
// 海报生成相关状态
const show_post = ref(false) // 显示海报预览
const show_save = ref(false) // 显示保存弹窗
const startDraw = ref(false) // 开始绘制海报
const posterPath = ref('') // 海报路径
const nickname = ref('老来赛用户') // 用户昵称
// const avatar = ref('https://cdn.ipadbiz.cn/icon/tou@2x.png') // 用户头像
// 保存选项
const actions_save = ref([{
name: '保存至相册'
}])
// 海报配置
let base = {}
let qrcode_url = 'https://cdn.ipadbiz.cn/space/068a790496c87cb8d2ed6e551401c544.png' // Mock二维码
// Mock活动数据
const activityData = ref({
title: '南京路商圈时尚Citywalk',
subtitle: '探索城市魅力,感受时尚脉搏',
dateRange: '2024年1月15日 - 2024年1月31日',
posterUrl: 'https://img.yzcdn.cn/vant/cat.jpeg', // 临时使用示例图片
description: '漫步南京路,感受上海的繁华与历史交融。从外滩到人民广场,体验这座城市独特的魅力和时尚气息。',
rules: [
'年满60岁的老年人可参与活动',
'需要在指定时间内完成所有打卡点',
'每个打卡点需上传照片验证',
'完成全部打卡可获得电子勋章和积分奖励'
],
rewards: [
'完成打卡获得500积分',
'获得专属电子勋章',
'有机会获得商户优惠券',
'参与月度积分排行榜'
]
})
// 分享配置
const shareConfig = ref({
title: '主题路线打卡活动等你参与',
path: '/pages/ActivitiesCover/index',
imageUrl: '',
})
/**
* 检查定位授权状态
*/
const checkLocationAuth = async () => {
try {
const authSetting = await Taro.getSetting()
hasLocationAuth.value = authSetting.authSetting['scope.userLocation'] === true
console.log('定位授权状态:', hasLocationAuth.value)
} catch (error) {
console.error('检查定位授权失败:', error)
hasLocationAuth.value = false
}
}
/**
* 获取用户位置信息
* @param {boolean} skipAuthCheck - 是否跳过授权检查(当调用方已经检查过授权状态时)
*/
const getUserLocation = async (skipAuthCheck = false) => {
try {
locationError.value = false // 重置错误状态
// 如果没有跳过授权检查,则检查权限状态
if (!skipAuthCheck) {
const authSetting = await Taro.getSetting()
const hasLocationAuth = authSetting.authSetting['scope.userLocation']
// 如果没有授权,先显示数据用途说明
if (hasLocationAuth !== true) {
return new Promise((resolve) => {
pendingLocationCallback.value = resolve
showLocationDialog.value = true
})
}
}
const location = await Taro.getLocation({
type: 'gcj02',
altitude: false, // 不需要海拔信息,提高获取速度
isHighAccuracy: true, // 开启高精度定位
highAccuracyExpireTime: 4000 // 高精度定位超时时间
})
userLocation.value = {
lng: location.longitude,
lat: location.latitude
}
console.log('获取到用户位置:', userLocation.value)
// 获取位置成功后隐藏提示
showLocationPrompt.value = false
hasLocationAuth.value = true
return true
} catch (error) {
console.error('获取位置失败:', error)
if (error.errMsg && error.errMsg.includes('auth deny')) {
// 用户拒绝授权,引导用户手动开启
hasLocationAuth.value = false
locationError.value = false
await Taro.showModal({
title: '需要位置权限',
content: '参与活动需要获取您的位置信息,请在设置中开启位置权限',
confirmText: '去设置',
success: (res) => {
if (res.confirm) {
Taro.openSetting()
}
}
})
} else if (error.errMsg && error.errMsg.includes('timeout')) {
// 定位超时
locationError.value = true
Taro.showToast({
title: '定位超时,请检查网络或GPS',
icon: 'none',
duration: 3000
})
} else if (error.errMsg && error.errMsg.includes('fail')) {
// 定位失败,可能是GPS关闭或网络问题
locationError.value = true
await Taro.showModal({
title: '定位失败',
content: '请确保已开启GPS定位服务,并检查网络连接是否正常',
showCancel: false,
confirmText: '我知道了'
})
} else {
// 其他未知错误
locationError.value = true
Taro.showToast({
title: '获取位置失败,请重试',
icon: 'none'
})
}
return false
}
}
/**
* 获取按钮显示文本
*/
const getButtonText = () => {
// 如果活动已结束,显示"活动已结束"
if (activityStatus.value.is_ended) {
return '活动已结束'
}
// 如果活动未开始,显示"活动未开始"
if (!activityStatus.value.is_begin) {
return '活动未开始'
}
// 如果没有加入家庭,显示"加入家庭"
if (!hasJoinedFamily.value) {
return '立即参加'
}
// 如果位置获取失败,显示"重新定位"
if (locationError.value) {
return '重新定位'
}
// 如果需要显示位置提示,说明需要授权
if (showLocationPrompt.value) {
return '授权定位'
}
// 如果已有定位授权且有位置信息,显示"进入活动"
if (hasLocationAuth.value && userLocation.value.lng && userLocation.value.lat) {
return '立即进入'
}
// 默认显示"立即参加"
return '立即参加'
}
/**
* 检查用户是否加入家庭并处理参加活动按钮点击
*/
const checkFamilyStatusAndJoinActivity = async () => {
// 如果活动已结束,显示提示
if (activityStatus.value.is_ended) {
Taro.showToast({
title: '活动已结束',
icon: 'none'
})
return
}
// 如果活动未开始,显示提示
if (!activityStatus.value.is_begin) {
Taro.showToast({
title: '活动尚未开始,请耐心等待',
icon: 'none'
})
return
}
// 如果没有加入家庭,引导用户加入家庭
if (!hasJoinedFamily.value) {
Taro.showModal({
title: '提示',
content: '没有加入家庭是无法参加活动的',
cancelText: '关闭',
confirmText: '前往加入',
success: (res) => {
if (res.confirm) {
Taro.redirectTo({
url: '/pages/Welcome/index',
});
}
},
});
return
}
// 如果位置获取失败,重新获取位置
if (locationError.value) {
await retryGetLocation()
return
}
// 如果需要显示位置提示,说明需要授权
if (showLocationPrompt.value) {
showLocationPrompt.value = false // 隐藏提示,直接尝试获取位置
await handleJoinActivity()
return
}
// 正常参加活动流程
await handleJoinActivity()
};
/**
* 重新获取位置信息
*/
const retryGetLocation = async () => {
try {
const success = await getUserLocation(false) // 不跳过授权检查,重新处理授权逻辑
if (success) {
hasLocationAuth.value = true
locationError.value = false
Taro.showToast({
title: '位置获取成功',
icon: 'success'
})
}
} catch (error) {
console.error('重新获取位置失败:', error)
}
}
/**
* 位置权限申请弹窗 - 取消操作
*/
const onLocationCancel = () => {
showLocationDialog.value = false
if (pendingLocationCallback.value) {
Taro.showToast({
title: '需要位置权限才能参与活动',
icon: 'none'
})
pendingLocationCallback.value(false)
pendingLocationCallback.value = null
}
}
/**
* 位置权限申请弹窗 - 同意授权
*/
const onLocationConfirm = async () => {
showLocationDialog.value = false
try {
const location = await Taro.getLocation({
type: 'gcj02',
altitude: false,
isHighAccuracy: true,
highAccuracyExpireTime: 4000
})
userLocation.value = {
lng: location.longitude,
lat: location.latitude
}
console.log('获取到用户位置:', userLocation.value)
showLocationPrompt.value = false
hasLocationAuth.value = true
if (pendingLocationCallback.value) {
pendingLocationCallback.value(true)
pendingLocationCallback.value = null
}
} catch (error) {
console.error('获取位置失败:', error)
if (pendingLocationCallback.value) {
pendingLocationCallback.value(false)
pendingLocationCallback.value = null
}
}
}
/**
* 处理参加活动按钮点击
*/
const handleJoinActivity = async () => {
isJoining.value = true
try {
// 检查定位授权状态
const authSetting = await Taro.getSetting()
const hasLocationPermission = authSetting.authSetting['scope.userLocation']
if (hasLocationPermission === false) {
// 用户之前拒绝过授权,显示提示让用户手动开启
showLocationPrompt.value = true
isJoining.value = false
return
} else if (hasLocationPermission === undefined) {
// 未请求过授权,直接尝试获取位置(会触发授权弹窗)
const success = await getUserLocation(false) // 不跳过授权检查,让getUserLocation处理授权逻辑
if (!success) {
showLocationPrompt.value = true
isJoining.value = false
return
}
} else {
// 已有授权,直接获取位置
const success = await getUserLocation(true) // 跳过授权检查,直接获取位置
if (!success) {
isJoining.value = false
return
}
}
// 跳转到Activities页面,并传递位置参数
await Taro.navigateTo({
url: `/pages/Activities/index?current_lng=${userLocation.value.lng}¤t_lat=${userLocation.value.lat}`
})
} catch (error) {
console.error('参加活动失败:', error)
Taro.showToast({
title: '参加活动失败',
icon: 'none'
})
} finally {
isJoining.value = false
}
}
/**
* 处理分享活动事件
*/
const onShareActivity = () => {
console.log('分享活动海报')
// 分享给朋友
// Taro.showToast({
// title: '请点击右上角分享给朋友',
// icon: 'none',
// duration: 2000
// });
}
/**
* 定义分享给朋友的内容
* @returns {Object} 分享配置对象
*/
const onShareAppMessage = () => {
return {
title: '主题路线打卡活动等你参与',
path: addShareFlag('/pages/ActivitiesCover/index'),
success: (res) => {
// 分享成功
},
fail: (err) => {
// 分享失败
}
}
}
// 导出分享方法供Taro使用
defineExpose({
onShareAppMessage,
})
/**
* 处理分享海报事件
*/
const onSharePoster = () => {
console.log('分享海报')
Taro.navigateTo({
url: '/pages/PosterCheckin/index',
})
}
/**
* 点击海报预览
*/
const onClickPost = () => {
show_save.value = true
}
/**
* 取消保存
*/
const onCancelSave = () => {
show_save.value = false
show_post.value = false
}
/**
* 选择保存方式
*/
const onSelectSave = (item) => {
if (item.name === '保存至相册') {
show_save.value = false
show_post.value = false
savePoster()
}
}
/**
* 开始生成海报
*/
// const startGeneratePoster = async () => {
// // 配置海报参数
// base = {
// width: 1024,
// height: 1334,
// backgroundColor: '',
// debug: false,
// blocks: [
// { // 上部分canvas画布高度
// x: 40,
// y: 20,
// width: 950,
// height: 950,
// paddingLeft: 0,
// paddingRight: 0,
// borderWidth: 1,
// borderColor: '#fff',
// backgroundColor: '#fff',
// borderRadiusGroup: [16, 16, 0, 0],
// },
// { // 活动时间背景图
// x: 40,
// y: 730,
// height: 75,
// paddingLeft: 80,
// paddingRight: 0,
// borderWidth: 0,
// text: {
// x: 0,
// y: 0,
// text: activityData.value.dateRange,
// fontSize: 40,
// color: '#222',
// opacity: 1,
// baseLine: 'top',
// lineHeight: 48,
// lineNum: 2,
// textAlign: 'left',
// zIndex: 0,
// },
// backgroundColor: '#FFF9F3',
// borderRadiusGroup: [0, 25, 25, 0],
// },
// { // 活动地点背景图
// x: 40,
// y: 830,
// height: 75,
// paddingLeft: 80,
// paddingRight: 0,
// borderWidth: 0,
// text: {
// x: 0,
// y: 0,
// text: '上海市黄浦区南京东路',
// fontSize: 40,
// color: '#222',
// opacity: 1,
// baseLine: 'top',
// lineHeight: 48,
// lineNum: 2,
// textAlign: 'left',
// zIndex: 0,
// },
// backgroundColor: '#FFF9F3',
// borderRadiusGroup: [0, 25, 25, 0],
// },
// { // 下部分canvas画布高度
// x: 40,
// y: 1060,
// width: 950,
// height: 250,
// paddingLeft: 0,
// paddingRight: 0,
// borderWidth: 1,
// borderColor: '#fff',
// backgroundColor: '#fff',
// borderRadiusGroup: [0, 0, 16, 16],
// }
// ],
// texts: [
// {
// x: 80,
// y: 630,
// text: activityData.value.title,
// fontSize: 50,
// color: '#000',
// opacity: 1,
// baseLine: 'middle',
// lineHeight: 60,
// lineNum: 2,
// textAlign: 'left',
// width: 800,
// zIndex: 999,
// fontFamily: 'Monospace',
// },
// {
// x: 135,
// y: 770,
// text: activityData.value.dateRange,
// fontSize: 40,
// color: '#222',
// opacity: 1,
// baseLine: 'middle',
// lineHeight: 48,
// lineNum: 2,
// textAlign: 'left',
// zIndex: 999,
// },
// {
// x: 135,
// y: 870,
// text: '上海市黄浦区南京东路',
// fontSize: 40,
// color: '#222',
// opacity: 1,
// baseLine: 'middle',
// lineHeight: 48,
// lineNum: 2,
// textAlign: 'left',
// zIndex: 999,
// },
// {
// x: 300,
// y: 1150,
// text: nickname.value,
// fontSize: 50,
// color: '#333',
// opacity: 1,
// baseLine: 'middle',
// textAlign: 'left',
// lineHeight: 50,
// lineNum: 1,
// zIndex: 999,
// },
// {
// x: 300,
// y: 1220,
// text: '邀请你一起来活动!',
// fontSize: 42,
// color: '#8F9399',
// opacity: 1,
// baseLine: 'middle',
// textAlign: 'left',
// lineHeight: 42,
// lineNum: 1,
// zIndex: 999,
// }
// ],
// images: [
// {
// url: qrcode_url,
// width: 949,
// height: 108,
// x: 40,
// y: 960,
// zIndex: 10,
// },
// {
// url: qrcode_url,
// width: 950,
// height: 500,
// x: 40,
// y: 20,
// borderRadiusGroup: [18, 18, 0, 0],
// zIndex: 10,
// },
// {
// url: qrcode_url,
// width: 40,
// height: 40,
// x: 80,
// y: 750,
// borderRadius: 100,
// borderWidth: 0,
// zIndex: 10,
// },
// {
// url: qrcode_url,
// width: 35,
// height: 40,
// x: 80,
// y: 850,
// borderRadius: 100,
// borderWidth: 0,
// zIndex: 10,
// },
// {
// url: qrcode_url,
// width: 170,
// height: 170,
// x: 80,
// y: 1090,
// borderRadius: 100,
// borderWidth: 0,
// zIndex: 10,
// },
// {
// url: qrcode_url,
// width: 170,
// height: 170,
// x: 750,
// y: 1090,
// borderRadius: 100,
// borderWidth: 0,
// zIndex: 10,
// },
// ],
// lines: []
// }
// startDraw.value = true
// if (!posterPath.value) Taro.showLoading({ title: '生成海报中...' })
// }
/**
* 海报绘制成功回调
*/
const drawSuccess = (result) => {
console.log('绘制成功', result)
const { tempFilePath, errMsg } = result
if (errMsg === 'canvasToTempFilePath:ok') {
posterPath.value = tempFilePath
Taro.hideLoading()
} else {
Taro.hideLoading()
Taro.showToast({
title: '生成失败,请稍后重试',
icon: 'none',
duration: 2500
})
}
}
/**
* 海报绘制失败回调
*/
const drawFail = (result) => {
console.log('绘制失败', result)
Taro.hideLoading()
Taro.showToast({
title: '生成失败,请稍后重试',
icon: 'none',
duration: 2500
})
}
/**
* 保存海报到相册
*/
const savePoster = () => {
Taro.saveImageToPhotosAlbum({
filePath: posterPath.value,
success() {
Taro.showToast({
title: '已保存到相册',
icon: 'success',
duration: 2000
})
},
fail() {
Taro.showToast({
title: '保存失败',
icon: 'none',
duration: 2000
})
}
})
}
/**
* 初始化页面数据
*/
const initPageData = async () => {
// 获取用户是否加入家庭
const { code, data } = await getMyFamiliesAPI()
if (code) {
// 如果加入家庭
if (data?.families?.length) {
hasJoinedFamily.value = true
}
}
// 获取活动状态
await fetchActivityStatus()
// 检查定位授权状态(不获取位置,只检查权限)
await checkLocationAuth()
}
/**
* 获取活动状态
*/
const fetchActivityStatus = async () => {
try {
activityStatus.value.loading = true
const { code, data } = await getActivityStatusAPI()
if (code === 1 && data) {
activityStatus.value.is_begin = Boolean(data.is_begin)
activityStatus.value.is_ended = Boolean(data.is_ended)
console.log('活动状态:', {
is_begin: activityStatus.value.is_begin ? '已开始' : '未开始',
is_ended: activityStatus.value.is_ended ? '已结束' : '进行中'
})
} else {
console.warn('获取活动状态失败:', data)
// 默认认为活动未开始且未结束,避免影响用户体验
activityStatus.value.is_begin = false
activityStatus.value.is_ended = false
}
} catch (error) {
console.error('获取活动状态异常:', error)
// 默认认为活动未开始且未结束,避免影响用户体验
activityStatus.value.is_begin = false
activityStatus.value.is_ended = false
} finally {
activityStatus.value.loading = false
}
}
// 处理页面加载时的授权检查
useLoad((options) => {
// 处理分享页面的授权逻辑
handleSharePageAuth(options, () => {
initPageData();
});
});
// 页面挂载时检查定位授权状态
onMounted(async () => {
// 获取系统信息
getSystemInfo();
initPageData()
})
</script>
<script>
export default {
name: "ActivitiesCover",
};
</script>