接入服务号模板推送通知

This commit is contained in:
stu2not
2026-06-22 14:34:20 +08:00
parent 8aeb813a68
commit 0fb4ebee8a
16 changed files with 1025 additions and 3 deletions
+72
View File
@@ -36,6 +36,7 @@ import {
startDeviceFirmwareUpdate,
updateDeviceRole,
} from '@/services/device'
import { getWechatMpBindStatus, startWechatMpBind, WechatMpBindStatus } from '@/services/wechat-mp'
import { useSystemBanner } from '@/components/system-banner/use-system-banner'
import './index.scss'
@@ -104,6 +105,9 @@ export default function Sleep() {
const [editingFamilyMember, setEditingFamilyMember] = useState<FamilyMember | null>(null)
const [familyMemberDisplayName, setFamilyMemberDisplayName] = useState('')
const [parentInfo, setParentInfo] = useState<Parent | null>(null)
const [wechatMpStatus, setWechatMpStatus] = useState<WechatMpBindStatus | null>(null)
const [isLoadingWechatMp, setIsLoadingWechatMp] = useState(false)
const [isStartingWechatMpBind, setIsStartingWechatMpBind] = useState(false)
const [isAuthorizingPhone, setIsAuthorizingPhone] = useState(false)
const firmwareStatusPollTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const firmwareStatusPollDeviceIdRef = useRef('')
@@ -150,6 +154,7 @@ export default function Sleep() {
void loadRoleData(nextBinding?.device_id)
void loadFamilyData(nextBinding?.device_id)
void loadCurrentDeviceCards(nextBinding?.device_id)
void loadWechatMpStatus()
} catch (error: any) {
console.error('[manage] load failed:', error)
Taro.showToast({
@@ -161,6 +166,18 @@ export default function Sleep() {
}
}
const loadWechatMpStatus = async () => {
setIsLoadingWechatMp(true)
try {
setWechatMpStatus(await getWechatMpBindStatus())
} catch (error) {
console.warn('[manage] wechat mp bind status load failed:', error)
setWechatMpStatus(null)
} finally {
setIsLoadingWechatMp(false)
}
}
const loadCurrentParent = async (userId: number): Promise<Parent | null> => {
try {
return await getParent(userId)
@@ -825,6 +842,41 @@ export default function Sleep() {
}
}
const handleStartWechatMpBind = async () => {
if (isStartingWechatMpBind) return
setIsStartingWechatMpBind(true)
try {
const result = await startWechatMpBind()
const bindUrl = String(result.url || '').trim()
if (!bindUrl) {
throw new Error('未获取到服务号绑定链接')
}
Taro.navigateTo({
url: `/pages/webview/index?url=${encodeURIComponent(bindUrl)}`,
fail: () => {
Taro.setClipboardData({
data: bindUrl,
success: () => {
Taro.showModal({
title: '服务号通知',
content: '绑定链接已复制,请在微信里打开完成授权。',
showCancel: false,
})
},
})
},
})
} catch (error: any) {
Taro.showToast({
title: error?.message || '服务号绑定失败',
icon: 'none',
})
} finally {
setIsStartingWechatMpBind(false)
}
}
const handleMenuClick = (item: MenuItem) => {
if (item.disabled) return
@@ -878,6 +930,11 @@ export default function Sleep() {
return
}
if (item.name === '服务号通知') {
handleStartWechatMpBind()
return
}
if (item.name === '解除设备绑定') {
handleUnbind()
}
@@ -937,6 +994,13 @@ export default function Sleep() {
: isLoadingFamily
? '查询中'
: `${familyInfo?.total || 1}/4 人`
const wechatMpValue = isStartingWechatMpBind
? '打开中'
: isLoadingWechatMp
? '查询中'
: wechatMpStatus?.bound
? '已开启'
: '未绑定'
const firmwareSubtitle = !binding?.device_id
? '绑定设备后可查看系统版本'
: isLoadingFirmware
@@ -1018,6 +1082,14 @@ export default function Sleep() {
arrow: true,
disabled: !binding,
},
{
icon: require('../../assets/tab-icons/rings.png'),
iconBgClass: 'green',
name: '服务号通知',
value: wechatMpValue,
arrow: true,
disabled: isStartingWechatMpBind,
},
{
icon: require('../../assets/tab-icons/broken-rings.png'),
iconBgClass: 'red',