hookehuyr

feat(首页): 添加首页分享功能

启用页面分享配置,自定义分享标题优先使用首页内容标题或默认值「觉林寺」,使用首个顶部横幅图片作为分享封面,并为分享路径添加分享标记
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
6 * @Description: 首页配置 6 * @Description: 首页配置
7 */ 7 */
8 export default { 8 export default {
9 - navigationBarTitleText: '首页' 9 + navigationBarTitleText: '首页',
10 + enableShareAppMessage: true,
10 } 11 }
......
...@@ -76,11 +76,12 @@ ...@@ -76,11 +76,12 @@
76 76
77 <script setup> 77 <script setup>
78 import { computed, ref } from 'vue' 78 import { computed, ref } from 'vue'
79 -import Taro, { useLoad } from '@tarojs/taro' 79 +import Taro, { useLoad, useShareAppMessage } from '@tarojs/taro'
80 import AppTabbar from '@/components/AppTabbar.vue' 80 import AppTabbar from '@/components/AppTabbar.vue'
81 import { getHomeContentAPI } from '@/api' 81 import { getHomeContentAPI } from '@/api'
82 import { buildWebviewPreviewUrl } from '@/utils/webview' 82 import { buildWebviewPreviewUrl } from '@/utils/webview'
83 import { isMockEnabled } from '@/utils/config' 83 import { isMockEnabled } from '@/utils/config'
84 +import { addShareFlag } from '@/utils/authRedirect'
84 85
85 const defaultIcon = 'icon-jingxiuying' 86 const defaultIcon = 'icon-jingxiuying'
86 const homeContent = ref({ 87 const homeContent = ref({
...@@ -97,6 +98,11 @@ const homeIcons = computed(() => homeContent.value.volunteer_home_icon || []) ...@@ -97,6 +98,11 @@ const homeIcons = computed(() => homeContent.value.volunteer_home_icon || [])
97 const hasTopBanner = computed(() => topBanners.value.some((item) => item?.image_url)) 98 const hasTopBanner = computed(() => topBanners.value.some((item) => item?.image_url))
98 const shouldUseTopBannerSwiper = computed(() => topBanners.value.filter((item) => item?.image_url).length > 1) 99 const shouldUseTopBannerSwiper = computed(() => topBanners.value.filter((item) => item?.image_url).length > 1)
99 const isMockHomeData = computed(() => isMockEnabled()) 100 const isMockHomeData = computed(() => isMockEnabled())
101 +const shareTitle = computed(() => String(homeContent.value?.title || '').trim() || '觉林寺')
102 +const shareImageUrl = computed(() => {
103 + const firstBanner = topBanners.value.find((item) => item?.image_url)
104 + return firstBanner?.image_url || ''
105 +})
100 106
101 const getItemTargetUrl = (item) => String(item?.target_url || '').trim() 107 const getItemTargetUrl = (item) => String(item?.target_url || '').trim()
102 108
...@@ -169,6 +175,19 @@ const fetchHomeContent = async () => { ...@@ -169,6 +175,19 @@ const fetchHomeContent = async () => {
169 useLoad(() => { 175 useLoad(() => {
170 fetchHomeContent() 176 fetchHomeContent()
171 }) 177 })
178 +
179 +useShareAppMessage(() => {
180 + const shareOptions = {
181 + title: shareTitle.value,
182 + path: addShareFlag('pages/index/index'),
183 + }
184 +
185 + if (shareImageUrl.value) {
186 + shareOptions.imageUrl = shareImageUrl.value
187 + }
188 +
189 + return shareOptions
190 +})
172 </script> 191 </script>
173 192
174 <style lang="less"> 193 <style lang="less">
......