feat: 新增小程序分享功能 — 全局默认+页面级定制
This commit is contained in:
@@ -75,6 +75,11 @@
|
||||
<view class="invite-action" @tap="copyInviteCode(group.invite_code)">
|
||||
<text class="invite-action-text">复制</text>
|
||||
</view>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button class="invite-action share-btn" open-type="share" @tap="shareInviteCode = group.invite_code">
|
||||
<text class="invite-action-text">分享</text>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
<view v-if="group.role === 'owner'" class="invite-action" @tap="handleRefreshCode(group)">
|
||||
<Icon name="refresh" :size="24" color="#8B7E7E" />
|
||||
<text class="invite-action-text">刷新</text>
|
||||
@@ -135,7 +140,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { onShow, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
|
||||
import { useGroupStore } from '@/stores/group'
|
||||
import { waitForReady } from '@/utils/app-ready'
|
||||
import { statusBarHeight, capsuleRight } from '@/utils/system'
|
||||
@@ -150,6 +155,7 @@ const newGroupName = ref('')
|
||||
const inviteCode = ref('')
|
||||
const saving = ref(false)
|
||||
const initialLoaded = ref(false)
|
||||
const shareInviteCode = ref('') // 当前要分享的邀请码
|
||||
|
||||
// 成员管理弹窗
|
||||
const showMemberModal = ref(false)
|
||||
@@ -168,6 +174,24 @@ onShow(() => {
|
||||
if (initialLoaded.value) groupStore.fetchGroups()
|
||||
})
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
onShareAppMessage(() => {
|
||||
// 空值保护:通过右上角菜单触发时 invite_code 可能为空
|
||||
const code = shareInviteCode.value
|
||||
const path = code
|
||||
? `/pages/group-manage/index?invite_code=${code}`
|
||||
: '/pages/group-manage/index'
|
||||
return {
|
||||
title: '一起来记账吧!',
|
||||
path
|
||||
}
|
||||
})
|
||||
|
||||
onShareTimeline(() => ({
|
||||
title: '小菜记账 — 一起来记账吧!'
|
||||
}))
|
||||
// #endif
|
||||
|
||||
function goBack() {
|
||||
uni.navigateBack()
|
||||
}
|
||||
@@ -555,6 +579,20 @@ function handleDissolve(group: Group) {
|
||||
color: $text-sec;
|
||||
}
|
||||
|
||||
/* 分享按钮重置默认样式 */
|
||||
.share-btn {
|
||||
margin: 0;
|
||||
padding: 4rpx 12rpx;
|
||||
line-height: normal;
|
||||
background: $bg;
|
||||
border: none;
|
||||
border-radius: $radius-sm;
|
||||
font-size: inherit;
|
||||
color: inherit;
|
||||
|
||||
&::after { border: none; }
|
||||
}
|
||||
|
||||
/* 操作按钮 */
|
||||
.group-actions {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user