feat: 支持多页面分享与统一默认头像

Made-with: Cursor
This commit is contained in:
nepiedg
2026-03-10 23:00:37 +08:00
parent 585b0a203f
commit bdb8d425eb
9 changed files with 128 additions and 68 deletions
+8
View File
@@ -98,6 +98,7 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
import { onShareAppMessage } from '@dcloudio/uni-app'
import { useLogin } from '@/hooks/useLogin'
import { useProfileStore } from '@/stores/profile'
import { storage } from '@/utils/storage'
@@ -410,6 +411,13 @@ async function initPage() {
onMounted(() => {
initPage()
})
onShareAppMessage(() => {
return {
title: '戒烟助手 - AI 戒烟教练陪你',
path: 'pages/index/index'
}
})
</script>
<style scoped>
+9 -1
View File
@@ -97,6 +97,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { onShareAppMessage } from '@dcloudio/uni-app'
import { useProfileStore } from '@/stores/profile'
import { useUserStore } from '@/stores/user'
import { useLogin } from '@/hooks/useLogin'
@@ -133,7 +134,7 @@ const userName = computed(() => {
})
const userAvatar = computed(() => {
return homeData.value?.greeting?.avatar_url || userStore.user?.avatar_url || '/static/images/default-avatar.png'
return homeData.value?.greeting?.avatar_url || userStore.user?.avatar_url || 'https://linghu-wmr.oss-cn-beijing.aliyuncs.com/smt/avatar.png'
})
const greetingTitle = computed(() => {
@@ -352,6 +353,13 @@ onMounted(() => {
onUnmounted(() => {
stopTimer()
})
onShareAppMessage(() => {
return {
title: '戒烟助手 - 记录与分析我的戒烟之路',
path: 'pages/index/index'
}
})
</script>
<style scoped>
+8
View File
@@ -123,6 +123,7 @@
<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { onShareAppMessage } from '@dcloudio/uni-app'
import { useLogsStore } from '@/stores/logs'
import { useLogin } from '@/hooks/useLogin'
@@ -284,6 +285,13 @@ function levelLabel(level) {
watch(currentTab, async (value) => {
await logsStore.fetchLogs(true, value)
})
onShareAppMessage(() => {
return {
title: '戒烟助手 - 我的戒烟记录',
path: 'pages/index/index'
}
})
</script>
<style scoped>
+8
View File
@@ -104,6 +104,7 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
import { onShareAppMessage } from '@dcloudio/uni-app'
import { useProfileStore } from '@/stores/profile'
import { useLogin } from '@/hooks/useLogin'
@@ -208,6 +209,13 @@ onMounted(async () => {
}
await waitForLogin()
})
onShareAppMessage(() => {
return {
title: '戒烟助手 - 帮你定制戒烟计划',
path: 'pages/index/index'
}
})
</script>
<style scoped>
+28 -19
View File
@@ -12,30 +12,17 @@
<view class="menu-content">
<text class="menu-label">分享戒烟记录</text>
<text class="menu-desc">{{ shareDesc }}</text>
<view class="menu-actions">
<text class="menu-action" @tap.stop="previewSharePage">预览分享页</text>
<text class="menu-action-sep">·</text>
<text class="menu-action" @tap.stop="handleRefreshShare">刷新分享链接</text>
</view>
</view>
<button class="share-btn" open-type="share" :disabled="shareLoading || !shareToken">
{{ shareLoading ? '生成中' : '分享' }}
</button>
</view>
<view class="menu-item" @tap="previewSharePage">
<view class="menu-icon menu-icon-green">👁</view>
<view class="menu-content">
<text class="menu-label">预览分享页</text>
<text class="menu-desc">本地查看分享落地页是否可访问</text>
</view>
<text class="menu-arrow"></text>
</view>
<view class="menu-item" @tap="prepareShareToken(true)">
<view class="menu-icon menu-icon-gray">🔄</view>
<view class="menu-content">
<text class="menu-label">刷新分享链接</text>
<text class="menu-desc">生成新的有效分享令牌</text>
</view>
<text class="menu-arrow"></text>
</view>
<view class="menu-item" @tap="goOnboarding">
<view class="menu-icon menu-icon-green">📝</view>
<view class="menu-content">
@@ -89,7 +76,7 @@ const shareExpireAt = ref('')
const shareLoading = ref(false)
const userName = computed(() => userStore.user?.nickname || '戒烟用户')
const userAvatar = computed(() => userStore.user?.avatar_url || '/static/icons/profile.png')
const userAvatar = computed(() => userStore.user?.avatar_url || 'https://linghu-wmr.oss-cn-beijing.aliyuncs.com/smt/avatar.png')
const shareDesc = computed(() => {
if (!shareToken.value) {
@@ -137,6 +124,10 @@ async function prepareShareToken(showToast = false) {
}
}
function handleRefreshShare() {
prepareShareToken(true)
}
function previewSharePage() {
if (!shareToken.value) {
uni.showToast({ title: '分享令牌尚未生成', icon: 'none' })
@@ -283,6 +274,24 @@ onMounted(async () => {
color: #6B7280;
}
.menu-actions {
margin-top: 6rpx;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8rpx;
font-size: 24rpx;
color: #10B981;
}
.menu-action {
color: #10B981;
}
.menu-action-sep {
color: #9CA3AF;
}
.menu-arrow {
font-size: 36rpx;
color: #9CA3AF;
+11 -2
View File
@@ -131,10 +131,10 @@
<script setup>
import { computed, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { onLoad, onShareAppMessage } from '@dcloudio/uni-app'
import { getShareData } from '@/api'
const defaultAvatar = '/static/icons/profile.png'
const defaultAvatar = 'https://linghu-wmr.oss-cn-beijing.aliyuncs.com/smt/avatar.png'
const loading = ref(true)
const loadingMore = ref(false)
@@ -307,6 +307,15 @@ onLoad(async (options) => {
shareToken.value = String(options?.share_token || '').trim()
await fetchShare(true)
})
onShareAppMessage(() => {
return {
title: '戒烟助手 - 查看我的戒烟记录',
path: shareToken.value
? `pages/share/index?share_token=${shareToken.value}`
: 'pages/index/index'
}
})
</script>
<style scoped>
+8
View File
@@ -181,6 +181,7 @@
<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { onShareAppMessage } from '@dcloudio/uni-app'
import { useLogin } from '@/hooks/useLogin'
import * as api from '@/api'
@@ -496,6 +497,13 @@ onMounted(() => {
statusBarHeight.value = Math.max((sys.statusBarHeight || 0) - 20, 0)
fetchStats()
})
onShareAppMessage(() => {
return {
title: '戒烟助手 - 我的戒烟数据分析',
path: 'pages/index/index'
}
})
</script>
<style scoped>