feat(miniprogram): enable sharing on all pages
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom'
|
||||
navigationStyle: 'custom',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
} from '@/services/child'
|
||||
import { useSystemBanner } from '@/components/system-banner/use-system-banner'
|
||||
import { trafficPageUrl } from '@/services/traffic-binding'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
|
||||
import './index.scss'
|
||||
|
||||
@@ -161,6 +162,7 @@ function parseBindingPayload(rawValue: string): { deviceId: string; serialNumber
|
||||
}
|
||||
|
||||
export default function Bind() {
|
||||
usePageShare()
|
||||
const router = useRouter()
|
||||
const isAssignMode = String(router.params?.mode || '').trim() === 'assign'
|
||||
const isCardMode = String(router.params?.mode || '').trim() === 'card'
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom'
|
||||
navigationStyle: 'custom',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
PeerKind,
|
||||
} from '../../../services/chat'
|
||||
import { useSystemBanner } from '@/components/system-banner/use-system-banner'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
function normalizePeerKind(value?: string): PeerKind {
|
||||
@@ -194,6 +195,7 @@ function getAudioUrlDebugInfo(rawUrl: string) {
|
||||
}
|
||||
|
||||
export default function ChatDetail() {
|
||||
usePageShare()
|
||||
const systemBanner = useSystemBanner()
|
||||
const router = useRouter()
|
||||
const params = router.params
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default {
|
||||
navigationBarTitleText: '聊天记录',
|
||||
navigationStyle: 'custom'
|
||||
}
|
||||
navigationStyle: 'custom',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import Taro, { useDidShow } from '@tarojs/taro'
|
||||
import { getToken } from '@/services/auth'
|
||||
import { getConversations, ChatConversation } from '../../services/chat'
|
||||
import { useSystemBanner } from '@/components/system-banner/use-system-banner'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
export default function Chat() {
|
||||
usePageShare()
|
||||
const systemBanner = useSystemBanner()
|
||||
const [conversations, setConversations] = useState<ChatConversation[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom'
|
||||
})
|
||||
navigationStyle: 'custom',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Binding, loadCurrentChildBindingContext } from '@/services/binding'
|
||||
import { Child } from '@/services/child'
|
||||
import { DeviceAlarmItem, DeviceStatus, getDeviceAlarms, getDeviceStatus, getDeviceVolumeCommandStatus, setDeviceRemoteSleepWake, setDeviceVolume } from '@/services/device'
|
||||
import { useSystemBanner } from '@/components/system-banner/use-system-banner'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
function formatTime(value?: string | null): string {
|
||||
@@ -119,6 +120,7 @@ function getAlarmLocationHint(alarm: DeviceAlarmItem | null): string {
|
||||
}
|
||||
|
||||
export default function Device() {
|
||||
usePageShare()
|
||||
const systemBanner = useSystemBanner()
|
||||
const [binding, setBinding] = useState<Binding | null>(null)
|
||||
const [pendingBinding, setPendingBinding] = useState<Binding | null>(null)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '家庭邀请',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -7,9 +7,11 @@ import { getToken } from '@/services/auth'
|
||||
import { setSelectedBindingDeviceId } from '@/services/binding'
|
||||
import { setSelectedChildId } from '@/services/child'
|
||||
import { acceptFamilyInvitation, FamilyInvitation, getFamilyInvitation } from '@/services/family'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
export default function FamilyInvite() {
|
||||
usePageShare()
|
||||
const router = useRouter()
|
||||
const inviteToken = String(router.params?.token || '').trim()
|
||||
const redirectUrl = `/pages/family-invite/index?token=${inviteToken}`
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom'
|
||||
})
|
||||
navigationStyle: 'custom',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
DeviceTrajectoryPoint,
|
||||
} from '@/services/location'
|
||||
import { useSystemBanner } from '@/components/system-banner/use-system-banner'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
type TrajectoryMode = 'current' | 'today' | 'recent'
|
||||
@@ -127,6 +128,7 @@ function getTrajectoryMarkerId(index: number): number {
|
||||
}
|
||||
|
||||
export default function Location() {
|
||||
usePageShare()
|
||||
const systemBanner = useSystemBanner()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [deviceLocation, setDeviceLocation] = useState<DeviceLocation | null>(null)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '微信登录',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { View, Text, Button, Checkbox, CheckboxGroup, Image } from '@tarojs/comp
|
||||
import { useEffect, useState } from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { getToken, wechatLogin } from '@/services/auth'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
const LOGIN_PAGE_URL = '/pages/login/index'
|
||||
@@ -39,6 +40,7 @@ function navigateAfterLogin(url: string): void {
|
||||
}
|
||||
|
||||
export default function Login() {
|
||||
usePageShare()
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
const [agreementAccepted, setAgreementAccepted] = useState(false)
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export default definePageConfig({
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
|
||||
import Taro, { useRouter } from '@tarojs/taro'
|
||||
import { getToken } from '@/services/auth'
|
||||
import { resolveWechatMpNotificationLink } from '@/services/notification'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
function buildQuery(params: Record<string, string | number | null | undefined>): string {
|
||||
@@ -18,6 +19,7 @@ function buildCurrentPageUrl(token: string): string {
|
||||
}
|
||||
|
||||
export default function NotificationEntry() {
|
||||
usePageShare()
|
||||
const router = useRouter()
|
||||
const token = String(router.params.token || '').trim()
|
||||
const [message, setMessage] = useState('正在打开留言...')
|
||||
|
||||
@@ -2,4 +2,5 @@ export default definePageConfig({
|
||||
navigationBarTitleText: '定时休眠',
|
||||
navigationBarBackgroundColor: '#F5F7FA',
|
||||
navigationBarTextStyle: 'black',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import { loadCurrentChildBindingContext, Binding } from '@/services/binding'
|
||||
import { Child } from '@/services/child'
|
||||
import { DeviceStatus, getDeviceStatus, setDeviceSleepSchedule } from '@/services/device'
|
||||
import { useSystemBanner } from '@/components/system-banner/use-system-banner'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
function formatSleepRange(status: DeviceStatus | null): string {
|
||||
@@ -28,6 +29,7 @@ function formatUpdatedAt(value?: string | null): string {
|
||||
}
|
||||
|
||||
export default function SleepSchedule() {
|
||||
usePageShare()
|
||||
const systemBanner = useSystemBanner()
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [isSaving, setIsSaving] = useState(false)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom'
|
||||
})
|
||||
navigationStyle: 'custom',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
export default definePageConfig({ navigationBarTitleText: '流量服务关联' })
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '流量服务关联',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -4,11 +4,13 @@ import { useRef, useState } from 'react'
|
||||
import { getToken } from '@/services/auth'
|
||||
import { clearSelectedBindingDeviceId } from '@/services/binding'
|
||||
import { getPageStyle } from '@/utils/page-style'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import { TrafficOperation, getTrafficOperation, resumeTrafficOperation,
|
||||
flushTrafficReceipt, finishTrafficUnbind, jumpTraffic } from '@/services/traffic-binding'
|
||||
import './index.scss'
|
||||
|
||||
export default function TrafficBindingPage() {
|
||||
usePageShare()
|
||||
const { params } = useRouter()
|
||||
const deviceId = String(params.device_id || '')
|
||||
const action = params.action === 'unbind' ? 'unbind' : 'bind'
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '服务号通知',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Text, View, WebView } from '@tarojs/components'
|
||||
import { useRouter } from '@tarojs/taro'
|
||||
import { usePageShare } from '@/utils/page-share'
|
||||
import './index.scss'
|
||||
|
||||
export default function WebviewPage() {
|
||||
usePageShare()
|
||||
const router = useRouter()
|
||||
const encodedUrl = String(router.params?.url || '').trim()
|
||||
const targetUrl = encodedUrl ? decodeURIComponent(encodedUrl) : ''
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useRouter, useShareAppMessage } from '@tarojs/taro'
|
||||
|
||||
const DEFAULT_SHARE_TITLES: Record<string, string> = {
|
||||
'/pages/device/index': '伴伴设备管理',
|
||||
'/pages/login/index': '登录伴伴小程序',
|
||||
'/pages/bind/index': '绑定伴伴设备',
|
||||
'/pages/traffic-binding/index': '伴伴流量服务',
|
||||
'/pages/notification/index': '查看伴伴通知',
|
||||
'/pages/chat/index': '伴伴聊天记录',
|
||||
'/pages/chat/detail/index': '查看伴伴聊天',
|
||||
'/pages/location/index': '查看设备位置',
|
||||
'/pages/sleep/index': '伴伴设备管理',
|
||||
'/pages/sleep-schedule/index': '设置设备休眠时间',
|
||||
'/pages/family-invite/index': '家庭共享邀请',
|
||||
'/pages/webview/index': '伴伴服务通知',
|
||||
}
|
||||
|
||||
function normalizePath(path: string): string {
|
||||
if (!path) return '/pages/device/index'
|
||||
return path.startsWith('/') ? path : `/${path}`
|
||||
}
|
||||
|
||||
function buildPagePath(path: string, params: Record<string, string | undefined>): string {
|
||||
const query = Object.entries(params)
|
||||
.filter(([, value]) => value !== undefined && value !== '')
|
||||
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
||||
.join('&')
|
||||
|
||||
return query ? `${path}?${query}` : path
|
||||
}
|
||||
|
||||
export function usePageShare(title?: string): void {
|
||||
const router = useRouter()
|
||||
const pagePath = normalizePath(router.path)
|
||||
|
||||
useShareAppMessage(() => ({
|
||||
title: title || DEFAULT_SHARE_TITLES[pagePath] || '伴伴小程序',
|
||||
path: buildPagePath(pagePath, router.params || {}),
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user