feat(mp): 微信模板消息订阅统一封装
- 新增 requestSubscribe() 统一订阅函数,消除页面内类型断言重复
- 用药页面新增 requestSubscribeMessage 订阅(MEDICATION_REMINDER 模板)
- 告警页面改用 requestSubscribe('CRITICAL_HEALTH_ALERT')
- wechat-templates 新增 MEDICATION_REMINDER 模板 ID 环境变量
This commit is contained in:
@@ -4,6 +4,7 @@ import Taro from '@tarojs/taro';
|
||||
import { safeNavigateTo } from '@/utils/navigate';
|
||||
import { usePageData } from '@/hooks/usePageData';
|
||||
import { listPatientAlerts, type Alert } from '@/services/alert';
|
||||
import { requestSubscribe } from '@/services/wechat-templates';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import Loading from '@/components/Loading';
|
||||
import ErrorState from '@/components/ErrorState';
|
||||
@@ -73,14 +74,7 @@ export default function PatientAlerts() {
|
||||
Taro.setNavigationBarTitle({ title: '健康告警' });
|
||||
await fetchAlerts(1, status, true);
|
||||
// 请求 critical 告警推送订阅
|
||||
try {
|
||||
const tmplId = process.env.TARO_APP_WX_TEMPLATE_CRITICAL_ALERT || '';
|
||||
if (tmplId) {
|
||||
await (Taro.requestSubscribeMessage as (option: { tmplIds: string[] }) => Promise<unknown>)({ tmplIds: [tmplId] });
|
||||
}
|
||||
} catch {
|
||||
// 用户拒绝或已订阅,不阻塞页面
|
||||
}
|
||||
requestSubscribe('CRITICAL_HEALTH_ALERT');
|
||||
},
|
||||
{ throttleMs: 10000, enablePullDown: true },
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { View, Text, Input, Picker } from '@tarojs/components';
|
||||
import Taro from '@tarojs/taro';
|
||||
import { usePageData } from '@/hooks/usePageData';
|
||||
import { getCachedPatientId } from '@/services/request';
|
||||
import { requestSubscribe } from '@/services/wechat-templates';
|
||||
import EmptyState from '../../../components/EmptyState';
|
||||
import {
|
||||
listReminders,
|
||||
@@ -36,7 +37,14 @@ export default function MedicationReminder() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
usePageData(fetchReminders, { throttleMs: 5000, enablePullDown: true });
|
||||
usePageData(
|
||||
async () => {
|
||||
await fetchReminders();
|
||||
// 请求用药提醒推送订阅
|
||||
requestSubscribe('MEDICATION_REMINDER');
|
||||
},
|
||||
{ throttleMs: 5000, enablePullDown: true },
|
||||
);
|
||||
|
||||
const handleToggle = async (r: MedicationReminder) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user