|
@@ -1,61 +1,60 @@
|
|
-
|
|
|
|
-
|
|
|
|
-import router from '@/router'
|
|
|
|
|
|
+import router, { setupRouter } from "@/router";
|
|
// 新增:Capacitor 相关导入
|
|
// 新增:Capacitor 相关导入
|
|
-import { App as CapApp } from '@capacitor/app'
|
|
|
|
-import { Browser } from '@capacitor/browser'
|
|
|
|
-
|
|
|
|
-// 推送服务
|
|
|
|
-import { pushNotificationService } from '@/services/PushNotificationService'
|
|
|
|
-
|
|
|
|
|
|
+import { App as CapApp } from "@capacitor/app";
|
|
|
|
+import { Browser } from "@capacitor/browser";
|
|
|
|
|
|
|
|
+// 推送服务
|
|
|
|
+import { pushNotificationService } from "@/services/PushNotificationService";
|
|
|
|
|
|
// 新增:Capacitor 初始化逻辑
|
|
// 新增:Capacitor 初始化逻辑
|
|
export const initCapacitor = async (app) => {
|
|
export const initCapacitor = async (app) => {
|
|
|
|
+ await setupRouter(app);
|
|
|
|
+ await router.isReady();
|
|
|
|
+
|
|
// Android 返回按钮处理
|
|
// Android 返回按钮处理
|
|
- CapApp.addListener('backButton', ({ canGoBack }) => {
|
|
|
|
- if (router.currentRoute.value.path !== '/' && canGoBack) {
|
|
|
|
- router.back()
|
|
|
|
|
|
+ CapApp.addListener("backButton", ({ canGoBack }) => {
|
|
|
|
+ if (router.currentRoute.value.path !== "/" && canGoBack) {
|
|
|
|
+ router.back();
|
|
} else {
|
|
} else {
|
|
- CapApp.exitApp()
|
|
|
|
|
|
+ CapApp.exitApp();
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
|
|
// 全局注入 Capacitor 能力
|
|
// 全局注入 Capacitor 能力
|
|
- app.config.globalProperties.$capApp = CapApp
|
|
|
|
- app.config.globalProperties.$capBrowser = Browser
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
|
|
+ app.config.globalProperties.$capApp = CapApp;
|
|
|
|
+ app.config.globalProperties.$capBrowser = Browser;
|
|
|
|
+};
|
|
|
|
|
|
export async function setupPlugin(app) {
|
|
export async function setupPlugin(app) {
|
|
-
|
|
|
|
// 在应用挂载前初始化推送通知监听器
|
|
// 在应用挂载前初始化推送通知监听器
|
|
// 你可以在这里定义如何处理收到的通知和注册信息
|
|
// 你可以在这里定义如何处理收到的通知和注册信息
|
|
pushNotificationService.initialize(
|
|
pushNotificationService.initialize(
|
|
(token) => {
|
|
(token) => {
|
|
// 成功获取到设备 token,将其发送到你的后端服务器
|
|
// 成功获取到设备 token,将其发送到你的后端服务器
|
|
- console.log('App: Device Token for push notifications:', token.value);
|
|
|
|
|
|
+ console.log("App: Device Token for push notifications:", token.value);
|
|
// TODO: 将 token 发送到你的服务器进行注册,这是后续后端发送推送的关键
|
|
// TODO: 将 token 发送到你的服务器进行注册,这是后续后端发送推送的关键
|
|
},
|
|
},
|
|
(error) => {
|
|
(error) => {
|
|
// 处理注册错误
|
|
// 处理注册错误
|
|
- console.error('App: Push notification registration failed', error);
|
|
|
|
|
|
+ console.error("App: Push notification registration failed", error);
|
|
// TODO: 可以在 UI 中提示用户注册失败
|
|
// TODO: 可以在 UI 中提示用户注册失败
|
|
},
|
|
},
|
|
(notification) => {
|
|
(notification) => {
|
|
// 收到推送通知 (应用在前台或后台)
|
|
// 收到推送通知 (应用在前台或后台)
|
|
- console.log('App: Push notification received in app:', notification);
|
|
|
|
|
|
+ console.log("App: Push notification received in app:", notification);
|
|
// TODO: 根据通知内容更新 UI 或显示提示
|
|
// TODO: 根据通知内容更新 UI 或显示提示
|
|
- alert(`收到消息: ${notification.title || ''} - ${notification.body || ''}`);
|
|
|
|
|
|
+ alert(
|
|
|
|
+ `收到消息: ${notification.title || ""} - ${notification.body || ""}`
|
|
|
|
+ );
|
|
},
|
|
},
|
|
(notification) => {
|
|
(notification) => {
|
|
// 用户点击了推送通知 (应用被打开或从后台唤醒)
|
|
// 用户点击了推送通知 (应用被打开或从后台唤醒)
|
|
- console.log('App: Push notification action performed:', notification);
|
|
|
|
|
|
+ console.log("App: Push notification action performed:", notification);
|
|
// TODO: 根据 notification.actionId 和 notification.data 进行路由跳转或执行特定操作
|
|
// TODO: 根据 notification.actionId 和 notification.data 进行路由跳转或执行特定操作
|
|
alert(`用户点击通知: ${notification.notification.title}`);
|
|
alert(`用户点击通知: ${notification.notification.title}`);
|
|
if (notification.notification.data?.route) {
|
|
if (notification.notification.data?.route) {
|
|
- // 示例:如果通知数据中包含 'route' 字段,则进行路由跳转
|
|
|
|
- router.push(notification.notification.data.route);
|
|
|
|
|
|
+ // 示例:如果通知数据中包含 'route' 字段,则进行路由跳转
|
|
|
|
+ router.push(notification.notification.data.route);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
);
|