refactor(ShareButton): 重构分享按钮组件为独立按钮形式
移除原有的气泡弹窗设计,改为直接显示分享活动和分享海报两个独立按钮 简化组件逻辑,删除不必要的状态管理和动画样式 优化按钮样式,使用更明显的颜色区分不同功能
Showing
1 changed file
with
66 additions
and
145 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | + * @Date: 2025-09-03 14:34:58 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-09-08 11:16:47 | ||
| 5 | + * @FilePath: /lls_program/src/components/ShareButton/index.vue | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | +--> | ||
| 8 | +<!-- | ||
| 2 | * @Description: 分享按钮组件 - 点击后弹出分享选项 | 9 | * @Description: 分享按钮组件 - 点击后弹出分享选项 |
| 3 | --> | 10 | --> |
| 4 | <template> | 11 | <template> |
| 5 | <view class="share-button-container"> | 12 | <view class="share-button-container"> |
| 6 | - <!-- 分享按钮 --> | 13 | + <!-- 分享活动按钮 --> |
| 7 | - <view @tap="toggleShareOptions" class="share-button"> | 14 | + <button id="share" data-name="shareBtn" open-type="share" class="share-button share-activity-btn"> |
| 8 | - <text>分享</text> | 15 | + 分享活动 |
| 9 | - </view> | 16 | + </button> |
| 10 | - | 17 | + |
| 11 | - <!-- 分享选项气泡弹窗 --> | 18 | + <!-- 分享海报按钮 --> |
| 12 | - <view v-if="showOptions" class="share-popover"> | 19 | + <view @tap="handleSharePoster" class="share-button share-poster-btn"> |
| 13 | - <view class="popover-arrow"></view> | 20 | + 分享海报 |
| 14 | - <view class="popover-content"> | ||
| 15 | - <view class="popover-item" style="padding: 0; padding-top: 8rpx;"> | ||
| 16 | - <button id="share" data-name="shareBtn" open-type="share" class="share-native-button">活动</button> | ||
| 17 | - </view> | ||
| 18 | - <view class="popover-divider"></view> | ||
| 19 | - <view @tap="handleSharePoster" class="popover-item"> | ||
| 20 | - <text>海报</text> | ||
| 21 | - </view> | ||
| 22 | - </view> | ||
| 23 | </view> | 21 | </view> |
| 24 | - | ||
| 25 | - <!-- 遮罩层 --> | ||
| 26 | - <view v-if="showOptions" class="popover-mask" @tap="hideShareOptions"></view> | ||
| 27 | </view> | 22 | </view> |
| 28 | </template> | 23 | </template> |
| 29 | 24 | ||
| ... | @@ -43,36 +38,10 @@ const props = defineProps({ | ... | @@ -43,36 +38,10 @@ const props = defineProps({ |
| 43 | // 组件事件 | 38 | // 组件事件 |
| 44 | const emit = defineEmits(['shareActivity', 'sharePoster']) | 39 | const emit = defineEmits(['shareActivity', 'sharePoster']) |
| 45 | 40 | ||
| 46 | -// 响应式数据 | ||
| 47 | -const showOptions = ref(false) | ||
| 48 | - | ||
| 49 | -/** | ||
| 50 | - * 切换分享选项显示状态 | ||
| 51 | - */ | ||
| 52 | -const toggleShareOptions = () => { | ||
| 53 | - showOptions.value = !showOptions.value | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | -/** | ||
| 57 | - * 隐藏分享选项 | ||
| 58 | - */ | ||
| 59 | -const hideShareOptions = () => { | ||
| 60 | - showOptions.value = false | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -/** | ||
| 64 | - * 处理活动分享 | ||
| 65 | - */ | ||
| 66 | -const handleShareActivity = () => { | ||
| 67 | - hideShareOptions() | ||
| 68 | - emit('shareActivity', props.activityData) | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | /** | 41 | /** |
| 72 | * 处理海报分享 | 42 | * 处理海报分享 |
| 73 | */ | 43 | */ |
| 74 | const handleSharePoster = () => { | 44 | const handleSharePoster = () => { |
| 75 | - hideShareOptions() | ||
| 76 | emit('sharePoster', props.activityData) | 45 | emit('sharePoster', props.activityData) |
| 77 | } | 46 | } |
| 78 | </script> | 47 | </script> |
| ... | @@ -83,121 +52,73 @@ const handleSharePoster = () => { | ... | @@ -83,121 +52,73 @@ const handleSharePoster = () => { |
| 83 | top: 40rpx; | 52 | top: 40rpx; |
| 84 | right: 40rpx; | 53 | right: 40rpx; |
| 85 | z-index: 1000; | 54 | z-index: 1000; |
| 86 | -} | ||
| 87 | - | ||
| 88 | -.share-button { | ||
| 89 | - color: white; | ||
| 90 | - width: 80rpx; | ||
| 91 | - height: 80rpx; | ||
| 92 | - border-radius: 50%; | ||
| 93 | - background: rgba(0, 0, 0, 0.6); | ||
| 94 | display: flex; | 55 | display: flex; |
| 56 | + flex-direction: column; | ||
| 57 | + gap: 16rpx; | ||
| 95 | align-items: center; | 58 | align-items: center; |
| 96 | - justify-content: center; | ||
| 97 | - box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2); | ||
| 98 | - transition: all 0.3s ease; | ||
| 99 | - backdrop-filter: blur(10rpx); | ||
| 100 | - | ||
| 101 | - &:active { | ||
| 102 | - transform: scale(0.95); | ||
| 103 | - background: rgba(0, 0, 0, 0.8); | ||
| 104 | - } | ||
| 105 | } | 59 | } |
| 106 | 60 | ||
| 107 | -.share-icon { | 61 | +.share-button { |
| 108 | - font-size: 32rpx; | 62 | + // 重置所有默认样式 - 使用!important强制覆盖 |
| 109 | - color: white; | 63 | + margin: 0 !important; |
| 110 | -} | 64 | + padding: 0 !important; |
| 111 | - | ||
| 112 | -// 气泡弹窗样式 | ||
| 113 | -.share-popover { | ||
| 114 | - position: fixed; | ||
| 115 | - top: 140rpx; | ||
| 116 | - right: 40rpx; | ||
| 117 | - z-index: 9999; | ||
| 118 | - animation: popoverFadeIn 0.2s ease; | ||
| 119 | -} | ||
| 120 | - | ||
| 121 | -.popover-arrow { | ||
| 122 | - position: absolute; | ||
| 123 | - top: -12rpx; | ||
| 124 | - right: 30rpx; | ||
| 125 | - width: 0; | ||
| 126 | - height: 0; | ||
| 127 | - border-left: 12rpx solid transparent; | ||
| 128 | - border-right: 12rpx solid transparent; | ||
| 129 | - border-bottom: 12rpx solid white; | ||
| 130 | -} | ||
| 131 | - | ||
| 132 | -.popover-content { | ||
| 133 | - background: white; | ||
| 134 | - border-radius: 16rpx; | ||
| 135 | - box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15); | ||
| 136 | - overflow: hidden; | ||
| 137 | - min-width: 160rpx; | ||
| 138 | -} | ||
| 139 | - | ||
| 140 | -.popover-item { | ||
| 141 | - padding: 24rpx 32rpx; | ||
| 142 | - font-size: 28rpx; | ||
| 143 | - color: #333; | ||
| 144 | - text-align: center; | ||
| 145 | - transition: background-color 0.2s ease; | ||
| 146 | - | ||
| 147 | - &:active { | ||
| 148 | - background-color: #f5f5f5; | ||
| 149 | - } | ||
| 150 | -} | ||
| 151 | - | ||
| 152 | -.popover-divider { | ||
| 153 | - height: 1rpx; | ||
| 154 | - background-color: #f0f0f0; | ||
| 155 | - margin: 0 16rpx; | ||
| 156 | -} | ||
| 157 | - | ||
| 158 | -.popover-mask { | ||
| 159 | - position: fixed; | ||
| 160 | - top: 0; | ||
| 161 | - left: 0; | ||
| 162 | - right: 0; | ||
| 163 | - bottom: 0; | ||
| 164 | - z-index: 9998; | ||
| 165 | -} | ||
| 166 | - | ||
| 167 | -// 原生button样式重置 | ||
| 168 | -.share-native-button { | ||
| 169 | border: none !important; | 65 | border: none !important; |
| 170 | outline: none !important; | 66 | outline: none !important; |
| 171 | - background: transparent !important; | 67 | + background: none !important; |
| 172 | - padding: 0 !important; | 68 | + font: inherit !important; |
| 173 | - margin: 0 !important; | 69 | + position: relative !important; |
| 174 | - font-size: 28rpx !important; | 70 | + display: inline-block !important; |
| 175 | - line-height: 2 !important; | ||
| 176 | - color: #333 !important; | ||
| 177 | - width: 100% !important; | ||
| 178 | - height: auto !important; | ||
| 179 | - text-align: center !important; | ||
| 180 | 71 | ||
| 72 | + // 应用自定义样式 | ||
| 73 | + color: white !important; | ||
| 74 | + padding: 12rpx 20rpx !important; | ||
| 75 | + border-radius: 32rpx !important; | ||
| 76 | + background: rgba(0, 0, 0, 0.6) !important; | ||
| 77 | + display: flex !important; | ||
| 78 | + align-items: center !important; | ||
| 79 | + justify-content: center !important; | ||
| 80 | + box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2) !important; | ||
| 81 | + transition: all 0.3s ease !important; | ||
| 82 | + backdrop-filter: blur(10rpx) !important; | ||
| 83 | + font-size: 24rpx !important; | ||
| 84 | + width: 140rpx !important; | ||
| 85 | + height: 60rpx !important; | ||
| 86 | + white-space: nowrap !important; | ||
| 87 | + flex-shrink: 0 !important; | ||
| 88 | + box-sizing: border-box !important; | ||
| 89 | + line-height: normal !important; | ||
| 90 | + text-align: center !important; | ||
| 91 | + | ||
| 92 | + &:active { | ||
| 93 | + transform: scale(0.95) !important; | ||
| 94 | + background: rgba(0, 0, 0, 0.8) !important; | ||
| 95 | + } | ||
| 96 | + | ||
| 181 | // 去除微信小程序button的默认样式 | 97 | // 去除微信小程序button的默认样式 |
| 182 | &::after { | 98 | &::after { |
| 183 | border: none !important; | 99 | border: none !important; |
| 100 | + content: none !important; | ||
| 184 | } | 101 | } |
| 185 | 102 | ||
| 186 | - // 去除点击态样式 | 103 | + // 去除button默认的点击效果 |
| 187 | - &:active { | 104 | + &.button-hover { |
| 188 | - background: transparent !important; | 105 | + background: rgba(0, 0, 0, 0.8) !important; |
| 189 | } | 106 | } |
| 190 | } | 107 | } |
| 191 | 108 | ||
| 192 | -// 动画 | 109 | +.share-activity-btn { |
| 193 | -@keyframes popoverFadeIn { | 110 | + background: rgba(74, 144, 226, 0.9); |
| 194 | - from { | 111 | + |
| 195 | - opacity: 0; | 112 | + &:active { |
| 196 | - transform: translateY(-10rpx); | 113 | + background: rgba(74, 144, 226, 1); |
| 197 | } | 114 | } |
| 198 | - to { | 115 | +} |
| 199 | - opacity: 1; | 116 | + |
| 200 | - transform: translateY(0); | 117 | +.share-poster-btn { |
| 118 | + background: rgba(52, 199, 89, 0.9); | ||
| 119 | + | ||
| 120 | + &:active { | ||
| 121 | + background: rgba(52, 199, 89, 1); | ||
| 201 | } | 122 | } |
| 202 | } | 123 | } |
| 203 | </style> | 124 | </style> | ... | ... |
-
Please register or login to post a comment