zhangwencui
7 天以前 8a89df99fb5d566ee72d27163cd7338948fd1b0a
测试推送
已修改2个文件
83 ■■■■ 文件已修改
src/App.vue 77 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/manifest.json 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/App.vue
@@ -1,22 +1,71 @@
<template>
    <Splash v-if="showSplash" />
    <div v-else>
        <router-view />
    </div>
  <Splash v-if="showSplash" />
  <div v-else>
    <router-view />
  </div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import Splash from './components/Splash.vue'
  import { ref, onMounted } from "vue";
  import Splash from "./components/Splash.vue";
const showSplash = ref(true)
onMounted(() => {
    setTimeout(() => {
        showSplash.value = false
    }, 5000)
})
  const showSplash = ref(true);
  onMounted(() => {
    setTimeout(() => {
      showSplash.value = false;
    }, 5000);
    // 初始化推送服务
    initPushService();
  });
  // 初始化推送服务(uni-push 1.0)
  const initPushService = () => {
    // #ifdef APP-PLUS
    console.log("开始初始化推送服务(uni-push 1.0)");
    if (typeof plus !== "undefined" && plus.push) {
      console.log("plus.push 存在:", plus.push);
      // 获取客户端推送标识
      console.log("使用 plus.push.getClientInfo 获取客户端标识");
      plus.push.getClientInfoAsync(info => {
        console.log("客户端推送标识:", info);
        // 这里可以将客户端标识发送到服务器
      });
      setTimeout(() => {
        console.log("使用 plus.push.getClientInfoAsync 获取客户端标识");
        plus.push.getClientInfoAsync(info => {
          console.log("客户端推送标识:", info);
          // 这里可以将客户端标识发送到服务器
        });
      }, 1000);
      // 监听推送消息点击事件
      plus.push.addEventListener("click", handlePushClick, false);
      // 监听推送消息接收事件
      plus.push.addEventListener("receive", handlePushReceive, false);
      console.log("推送服务注册成功");
    } else {
      console.log("推送服务不可用");
    }
    // #endif
  };
  // 处理推送消息点击事件
  const handlePushClick = msg => {
    console.log("点击推送消息:", msg);
    uni.navigateTo({
      url: msg.payload.pagePath,
    });
    // 解析并处理推送消息...
  };
  // 处理推送消息接收事件
  const handlePushReceive = msg => {
    console.log("收到推送消息:", msg);
    // 处理接收的推送消息...
  };
</script>
<style lang="scss">
@import "uview-plus/index.scss";
@import '@/static/scss/index.scss';
  @import "uview-plus/index.scss";
  @import "@/static/scss/index.scss";
</style>
src/manifest.json
@@ -23,7 +23,8 @@
        /* 模块配置 */
        "modules": {
            "Camera": {},
            "Barcode": {}
            "Barcode": {},
            "Push": {}
        },
        /* 应用发布信息 */
        "distribute": {
@@ -69,7 +70,8 @@
                            "small": {
                                "ldpi": "D:/xindao/wenjian/img/logo/app.png"
                            }
                        }
                        },
                        "offline": false
                    }
                }
            },