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