feat(share): 全站开放转发与分享朋友圈,分享落地支持指定场馆
- 全局 mixin 注册 onShareAppMessage/onShareTimeline,默认分享首页并携带 venue 参数 - 隐私/流程页(支付、登录、订单、预约、会员卡等)在 onShow 隐藏分享入口 - useShare 组合式工具,活动/排课/课程/商品等 6 个详情页自定义标题、封面与直达路径 - tab 壳页新增 useVenueRouteQuery,冷启动按 ?venue= 参数切换到对应场馆
This commit is contained in:
@@ -3,11 +3,13 @@ import App from './App.vue'
|
||||
import * as Pinia from 'pinia'
|
||||
import uviewPlus from 'uview-plus'
|
||||
import 'uview-plus/index.scss'
|
||||
import { shareMixin } from '@/utils/share'
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.use(Pinia.createPinia())
|
||||
app.use(uviewPlus)
|
||||
app.mixin(shareMixin)
|
||||
return {
|
||||
app,
|
||||
Pinia
|
||||
|
||||
@@ -14,12 +14,24 @@ import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { contentApi } from '@/modules/comprehensive/api/content'
|
||||
import { formatDate } from '@/modules/comprehensive/utils/date'
|
||||
import { useShare } from '@/utils/share'
|
||||
|
||||
const article = ref(null)
|
||||
|
||||
onLoad(async (query) => {
|
||||
article.value = await contentApi.getArticleDetail(query.id)
|
||||
})
|
||||
|
||||
useShare(() => {
|
||||
const data = article.value
|
||||
if (!data) return null
|
||||
return {
|
||||
title: data.title,
|
||||
path: `/pages/comprehensive/activities/detail?id=${data.id}`,
|
||||
imageUrl: data.cover_image || '',
|
||||
timelineQuery: `id=${data.id}`
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -39,6 +39,7 @@ import { computed, ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { courseApi } from '@/modules/comprehensive/api/course'
|
||||
import { formatTimeRange } from '@/modules/comprehensive/utils/date'
|
||||
import { useShare } from '@/utils/share'
|
||||
|
||||
const session = ref(null)
|
||||
|
||||
@@ -46,6 +47,17 @@ const canBook = computed(() => {
|
||||
return session.value && session.value.remaining_count > 0 && session.value.status === 'published'
|
||||
})
|
||||
|
||||
useShare(() => {
|
||||
const data = session.value
|
||||
if (!data) return null
|
||||
return {
|
||||
title: data.title,
|
||||
path: `/pages/comprehensive/courses/detail?id=${data.id}`,
|
||||
imageUrl: data.cover_image || '',
|
||||
timelineQuery: `id=${data.id}`
|
||||
}
|
||||
})
|
||||
|
||||
const infoItems = computed(() => {
|
||||
if (!session.value) return []
|
||||
return [
|
||||
|
||||
@@ -17,12 +17,24 @@ import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { courseInfoApi } from '@/modules/comprehensive/api/courseInfo'
|
||||
import { formatDate } from '@/modules/comprehensive/utils/date'
|
||||
import { useShare } from '@/utils/share'
|
||||
|
||||
const course = ref(null)
|
||||
|
||||
onLoad(async (query) => {
|
||||
course.value = await courseInfoApi.getCourseDetail(query.id)
|
||||
})
|
||||
|
||||
useShare(() => {
|
||||
const data = course.value
|
||||
if (!data) return null
|
||||
return {
|
||||
title: data.title,
|
||||
path: `/pages/comprehensive/courses/info-detail?id=${data.id}`,
|
||||
imageUrl: data.cover_image || '',
|
||||
timelineQuery: `id=${data.id}`
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -53,11 +53,22 @@ import { onLoad } from '@dcloudio/uni-app'
|
||||
import { membershipApi } from '@/modules/comprehensive/api/membership'
|
||||
import { storedValueApi } from '@/modules/comprehensive/api/storedValue'
|
||||
import { useComprehensiveSessionStore } from '@/modules/comprehensive/stores/session'
|
||||
import { useShare } from '@/utils/share'
|
||||
|
||||
const session = useComprehensiveSessionStore()
|
||||
const type = ref('')
|
||||
const itemId = ref(null)
|
||||
const item = ref(null)
|
||||
|
||||
useShare(() => {
|
||||
const data = item.value
|
||||
if (!data) return null
|
||||
return {
|
||||
title: data.name,
|
||||
path: `/pages/comprehensive/mall/detail?type=${type.value}&id=${data.id}`,
|
||||
timelineQuery: `type=${type.value}&id=${data.id}`
|
||||
}
|
||||
})
|
||||
const isLoading = ref(false)
|
||||
const submitting = ref(false)
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||
import { getStoredVenue } from '@/utils/venue'
|
||||
import { useVenueRouteQuery } from '@/utils/venue'
|
||||
import ComprehensiveCourses from '@/pages/comprehensive/courses/index.vue'
|
||||
import IceCourses from '@/pages/ice/courses/index.vue'
|
||||
|
||||
const isComprehensive = getStoredVenue() === 'comprehensive'
|
||||
const { isComprehensive } = useVenueRouteQuery()
|
||||
const contentRef = ref()
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onPullDownRefresh } from '@dcloudio/uni-app'
|
||||
import { getStoredVenue } from '@/utils/venue'
|
||||
import { useVenueRouteQuery } from '@/utils/venue'
|
||||
import ComprehensiveHome from '@/pages/comprehensive/home/index.vue'
|
||||
import IceHome from '@/pages/ice/home/index.vue'
|
||||
|
||||
const venue = getStoredVenue()
|
||||
const isComprehensive = venue === 'comprehensive'
|
||||
const { isComprehensive } = useVenueRouteQuery()
|
||||
const contentRef = ref()
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
|
||||
@@ -47,6 +47,7 @@ import { ref, onMounted } from 'vue'
|
||||
import { contentApi } from '@/modules/ice/api/content'
|
||||
import { errorMessage } from '@/modules/ice/api/session'
|
||||
import StatePanel from '@/components/ice/StatePanel.vue'
|
||||
import { useShare } from '@/utils/share'
|
||||
|
||||
const activity = ref({
|
||||
id: null,
|
||||
@@ -59,6 +60,17 @@ const pageState = ref('loading')
|
||||
const pageMessage = ref('')
|
||||
const currentActivityId = ref('')
|
||||
|
||||
useShare(() => {
|
||||
const data = activity.value
|
||||
if (!data || !data.id) return null
|
||||
return {
|
||||
title: data.title,
|
||||
path: `/pages/ice/activities/detail?id=${data.id}`,
|
||||
imageUrl: data.cover || '',
|
||||
timelineQuery: `id=${data.id}`
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
|
||||
@@ -71,6 +71,7 @@ import { ref, onMounted } from 'vue'
|
||||
import { courseApi } from '@/modules/ice/api/course'
|
||||
import { errorMessage } from '@/modules/ice/api/session'
|
||||
import StatePanel from '@/components/ice/StatePanel.vue'
|
||||
import { useShare } from '@/utils/share'
|
||||
|
||||
const course = ref({
|
||||
id: null,
|
||||
@@ -85,6 +86,17 @@ const course = ref({
|
||||
coach: { name: '' },
|
||||
detail_html: '',
|
||||
})
|
||||
|
||||
useShare(() => {
|
||||
const data = course.value
|
||||
if (!data || !data.id) return null
|
||||
return {
|
||||
title: data.title,
|
||||
path: `/pages/ice/courses/detail?id=${data.id}`,
|
||||
imageUrl: data.cover || '',
|
||||
timelineQuery: `id=${data.id}`
|
||||
}
|
||||
})
|
||||
const pageState = ref('loading')
|
||||
const pageMessage = ref('')
|
||||
const currentCourseId = ref('')
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onPullDownRefresh, onShow } from '@dcloudio/uni-app'
|
||||
import { getStoredVenue } from '@/utils/venue'
|
||||
import { useVenueRouteQuery } from '@/utils/venue'
|
||||
import ComprehensiveMall from '@/pages/comprehensive/mall/index.vue'
|
||||
import IceMall from '@/pages/ice/mall/index.vue'
|
||||
|
||||
const isComprehensive = getStoredVenue() === 'comprehensive'
|
||||
const { isComprehensive } = useVenueRouteQuery()
|
||||
const contentRef = ref()
|
||||
let isFirstShow = true
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onShow, onHide } from '@dcloudio/uni-app'
|
||||
import { getStoredVenue } from '@/utils/venue'
|
||||
import { useVenueRouteQuery } from '@/utils/venue'
|
||||
import ComprehensivePrivate from '@/pages/comprehensive/private/index.vue'
|
||||
import IcePrivate from '@/pages/ice/private/index.vue'
|
||||
|
||||
const isComprehensive = getStoredVenue() === 'comprehensive'
|
||||
const { isComprehensive } = useVenueRouteQuery()
|
||||
const contentRef = ref()
|
||||
let isFirstShow = true
|
||||
let autoRefreshTimer = null
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onShow, onPullDownRefresh } from '@dcloudio/uni-app'
|
||||
import { getStoredVenue } from '@/utils/venue'
|
||||
import { useVenueRouteQuery } from '@/utils/venue'
|
||||
import ComprehensiveProfile from '@/pages/comprehensive/profile/index.vue'
|
||||
import IceProfile from '@/pages/ice/profile/index.vue'
|
||||
|
||||
const isComprehensive = getStoredVenue() === 'comprehensive'
|
||||
const { isComprehensive } = useVenueRouteQuery()
|
||||
const contentRef = ref()
|
||||
|
||||
onShow(() => {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { getCurrentInstance } from 'vue'
|
||||
import { getStoredVenue } from '@/utils/venue'
|
||||
|
||||
export const SHARE_DEFAULT_TITLE = '订场约课,一起来运动'
|
||||
|
||||
const EXCLUDED_ROUTES = [
|
||||
'/pages/venue-select/index',
|
||||
'/pages/comprehensive/pay/index',
|
||||
'/pages/comprehensive/profile/login',
|
||||
'/pages/comprehensive/private/confirm',
|
||||
'/pages/comprehensive/courses/confirm',
|
||||
'/pages/comprehensive/orders/detail',
|
||||
'/pages/comprehensive/bookings/index',
|
||||
'/pages/comprehensive/bookings/course-detail',
|
||||
'/pages/comprehensive/bookings/private-detail',
|
||||
'/pages/comprehensive/membership/cards',
|
||||
'/pages/comprehensive/membership/card-detail',
|
||||
'/pages/comprehensive/membership/available-sessions',
|
||||
'/pages/comprehensive/membership/booking-detail',
|
||||
'/pages/comprehensive/profile/balance',
|
||||
'/pages/comprehensive/profile/tickets',
|
||||
'/pages/comprehensive/profile/orders',
|
||||
'/pages/comprehensive/profile/detail',
|
||||
'/pages/ice/bookings/index',
|
||||
'/pages/ice/bookings/detail',
|
||||
'/pages/ice/profile/cards',
|
||||
'/pages/ice/profile/card-history',
|
||||
'/pages/ice/profile/detail'
|
||||
]
|
||||
|
||||
const getCurrentRoute = () => {
|
||||
const pages = getCurrentPages()
|
||||
return pages.length ? `/${pages[pages.length - 1].route}` : ''
|
||||
}
|
||||
|
||||
const isExcludedRoute = () => EXCLUDED_ROUTES.includes(getCurrentRoute())
|
||||
|
||||
export const shareMixin = {
|
||||
onShow() {
|
||||
if (isExcludedRoute()) {
|
||||
uni.hideShareMenu()
|
||||
}
|
||||
},
|
||||
onShareAppMessage() {
|
||||
if (isExcludedRoute()) return
|
||||
const shareConfig = this.shareConfig
|
||||
if (shareConfig && shareConfig.path) {
|
||||
return {
|
||||
title: shareConfig.title || SHARE_DEFAULT_TITLE,
|
||||
path: shareConfig.path,
|
||||
imageUrl: shareConfig.imageUrl || ''
|
||||
}
|
||||
}
|
||||
const venue = getStoredVenue()
|
||||
return {
|
||||
title: SHARE_DEFAULT_TITLE,
|
||||
path: `/pages/home/index?venue=${venue}`
|
||||
}
|
||||
},
|
||||
onShareTimeline() {
|
||||
if (isExcludedRoute()) return
|
||||
const shareConfig = this.shareConfig
|
||||
if (shareConfig) {
|
||||
return {
|
||||
title: shareConfig.title || SHARE_DEFAULT_TITLE,
|
||||
query: shareConfig.timelineQuery || ''
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: SHARE_DEFAULT_TITLE,
|
||||
query: `venue=${getStoredVenue()}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const useShare = (getConfig) => {
|
||||
const instance = getCurrentInstance()
|
||||
if (!instance) return null
|
||||
const apply = () => {
|
||||
const config = getConfig ? getConfig() : null
|
||||
if (config) {
|
||||
instance.proxy.shareConfig = config
|
||||
}
|
||||
}
|
||||
apply()
|
||||
return { update: apply }
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
|
||||
export const CURRENT_VENUE_KEY = 'CURRENT_VENUE'
|
||||
|
||||
export const VENUE_KEYS = Object.freeze({
|
||||
@@ -35,3 +38,17 @@ export const navigateToVenueHome = (venueKey) => {
|
||||
}
|
||||
uni.reLaunch({ url: '/pages/home/index' })
|
||||
}
|
||||
|
||||
export const useVenueRouteQuery = () => {
|
||||
const venue = ref(getStoredVenue())
|
||||
const isComprehensive = computed(() => venue.value === VENUE_KEYS.COMPREHENSIVE)
|
||||
|
||||
onLoad((query) => {
|
||||
if (query && isVenueKey(query.venue) && query.venue !== venue.value) {
|
||||
setStoredVenue(query.venue)
|
||||
venue.value = query.venue
|
||||
}
|
||||
})
|
||||
|
||||
return { venue, isComprehensive }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user