index.vue
3.69 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
<!--
* @Date: 2025-09-03 14:34:58
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-26 10:50:10
* @FilePath: /lls_program/src/components/ShareButton/index.vue
* @Description: 分享按钮组件 - 点击后弹出分享选项
-->
<template>
<view class="share-button-container">
<!-- 分享活动按钮 -->
<button id="share" data-name="shareBtn" open-type="share" class="share-button share-activity-btn">
分享朋友
</button>
<!-- 分享海报按钮 -->
<view @tap="handleSharePoster" class="share-button share-poster-btn">
分享海报
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import Taro from '@tarojs/taro'
import { addShareFlag } from '@/utils/authRedirect'
// 组件属性
const props = defineProps({
// 活动数据
activityData: {
type: Object,
default: () => ({})
},
// 分享配置
shareConfig: {
type: Object,
default: () => ({
title: '精彩活动等你参与',
path: '/pages/ActivitiesCover/index',
imageUrl: ''
})
}
})
// 组件事件
const emit = defineEmits(['shareActivity', 'sharePoster'])
/**
* 处理海报分享
*/
const handleSharePoster = () => {
emit('sharePoster', props.activityData)
}
/**
* 定义分享给朋友的内容
* @param {Object} res - 分享来源信息
* @returns {Object} 分享配置对象
*/
const onShareAppMessage = (res) => {
// 构建分享数据
const shareData = {
title: props.shareConfig.title || '精彩活动等你参与',
path: addShareFlag(props.shareConfig.path || '/pages/ActivitiesCover/index'),
imageUrl: props.shareConfig.imageUrl || ''
}
// 触发分享事件
emit('shareActivity', {
...props.activityData,
shareData
})
return shareData
}
// 使用Taro的useShareAppMessage Hook来处理分享
Taro.useShareAppMessage((res) => {
return onShareAppMessage(res)
})
// 导出分享方法供Taro使用(保持兼容性)
defineExpose({
onShareAppMessage,
})
</script>
<style lang="less">
.share-button-container {
position: fixed;
top: 40rpx;
right: 30rpx;
z-index: 1000;
display: flex;
flex-direction: column;
gap: 28rpx;
align-items: center;
}
.share-button {
// 重置所有默认样式 - 使用!important强制覆盖
margin: 0 !important;
padding: 0 !important;
border: none !important;
outline: none !important;
background: none !important;
font: inherit !important;
position: relative !important;
display: inline-block !important;
// 应用自定义样式
color: white !important;
padding: 12rpx 20rpx !important;
border-radius: 32rpx !important;
background: rgba(0, 0, 0, 0.6) !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2) !important;
transition: all 0.3s ease !important;
backdrop-filter: blur(10rpx) !important;
font-size: 24rpx !important;
width: 140rpx !important;
height: 60rpx !important;
white-space: nowrap !important;
flex-shrink: 0 !important;
box-sizing: border-box !important;
line-height: normal !important;
text-align: center !important;
&:active {
transform: scale(0.95) !important;
background: rgba(0, 0, 0, 0.8) !important;
}
// 去除微信小程序button的默认样式
&::after {
border: none !important;
content: none !important;
}
// 去除button默认的点击效果
&.button-hover {
background: rgba(0, 0, 0, 0.8) !important;
}
}
.share-activity-btn {
background: rgba(74, 144, 226, 0.9);
&:active {
background: rgba(74, 144, 226, 1);
}
}
.share-poster-btn {
background: rgba(52, 199, 89, 0.9);
&:active {
background: rgba(52, 199, 89, 1);
}
}
</style>