feat: 新增小程序分享功能 — 全局默认+页面级定制
This commit is contained in:
@@ -6,5 +6,23 @@ export function createApp() {
|
|||||||
const app = createSSRApp(App)
|
const app = createSSRApp(App)
|
||||||
const pinia = createPinia()
|
const pinia = createPinia()
|
||||||
app.use(pinia)
|
app.use(pinia)
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
// 全局分享配置,页面可通过定义 onShareAppMessage/onShareTimeline 覆盖
|
||||||
|
app.mixin({
|
||||||
|
onShareAppMessage() {
|
||||||
|
return {
|
||||||
|
title: '小菜记账 — 轻松记账,快乐生活',
|
||||||
|
path: '/pages/index/index'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onShareTimeline() {
|
||||||
|
return {
|
||||||
|
title: '小菜记账 — 轻松记账,快乐生活'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
|
||||||
return { app }
|
return { app }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,11 @@
|
|||||||
<view class="invite-action" @tap="copyInviteCode(group.invite_code)">
|
<view class="invite-action" @tap="copyInviteCode(group.invite_code)">
|
||||||
<text class="invite-action-text">复制</text>
|
<text class="invite-action-text">复制</text>
|
||||||
</view>
|
</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)">
|
<view v-if="group.role === 'owner'" class="invite-action" @tap="handleRefreshCode(group)">
|
||||||
<Icon name="refresh" :size="24" color="#8B7E7E" />
|
<Icon name="refresh" :size="24" color="#8B7E7E" />
|
||||||
<text class="invite-action-text">刷新</text>
|
<text class="invite-action-text">刷新</text>
|
||||||
@@ -135,7 +140,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
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 { useGroupStore } from '@/stores/group'
|
||||||
import { waitForReady } from '@/utils/app-ready'
|
import { waitForReady } from '@/utils/app-ready'
|
||||||
import { statusBarHeight, capsuleRight } from '@/utils/system'
|
import { statusBarHeight, capsuleRight } from '@/utils/system'
|
||||||
@@ -150,6 +155,7 @@ const newGroupName = ref('')
|
|||||||
const inviteCode = ref('')
|
const inviteCode = ref('')
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const initialLoaded = ref(false)
|
const initialLoaded = ref(false)
|
||||||
|
const shareInviteCode = ref('') // 当前要分享的邀请码
|
||||||
|
|
||||||
// 成员管理弹窗
|
// 成员管理弹窗
|
||||||
const showMemberModal = ref(false)
|
const showMemberModal = ref(false)
|
||||||
@@ -168,6 +174,24 @@ onShow(() => {
|
|||||||
if (initialLoaded.value) groupStore.fetchGroups()
|
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() {
|
function goBack() {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
}
|
}
|
||||||
@@ -555,6 +579,20 @@ function handleDissolve(group: Group) {
|
|||||||
color: $text-sec;
|
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 {
|
.group-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -120,7 +120,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted, watch } from 'vue'
|
import { ref, computed, onMounted, watch } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { onShow, onPullDownRefresh } from '@dcloudio/uni-app'
|
import { onShow, onPullDownRefresh, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
|
||||||
import { useStatsStore } from '@/stores/stats'
|
import { useStatsStore } from '@/stores/stats'
|
||||||
import { useGroupStore } from '@/stores/group'
|
import { useGroupStore } from '@/stores/group'
|
||||||
import { waitForReady } from '@/utils/app-ready'
|
import { waitForReady } from '@/utils/app-ready'
|
||||||
@@ -312,6 +312,20 @@ onPullDownRefresh(() => {
|
|||||||
loadData().finally(() => uni.stopPullDownRefresh())
|
loadData().finally(() => uni.stopPullDownRefresh())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
onShareAppMessage(() => {
|
||||||
|
const expense = formatAmount(overview.value.expense)
|
||||||
|
return {
|
||||||
|
title: `我的${formatMonth(currentMonth.value)}账单:支出 ${expense}`,
|
||||||
|
path: '/pages/stats/index'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onShareTimeline(() => ({
|
||||||
|
title: `小菜记账 — 我的${formatMonth(currentMonth.value)}账单`
|
||||||
|
}))
|
||||||
|
// #endif
|
||||||
|
|
||||||
function prevMonth() {
|
function prevMonth() {
|
||||||
const [y, m] = currentMonth.value.split('-').map(Number)
|
const [y, m] = currentMonth.value.split('-').map(Number)
|
||||||
currentMonth.value = m === 1 ? `${y - 1}-12` : `${y}-${String(m - 1).padStart(2, '0')}`
|
currentMonth.value = m === 1 ? `${y - 1}-12` : `${y}-${String(m - 1).padStart(2, '0')}`
|
||||||
|
|||||||
Reference in New Issue
Block a user