|
@@ -6,27 +6,32 @@
|
|
|
import Vue from "vue";
|
|
|
import appUpdate from "common/util/appUpdate.js";
|
|
|
import configService from "@/common/service/config.service.js";
|
|
|
+import { connectWebSocket, sendWebSocketMessage, closeWebSocket } from '@/common/util/websocket'
|
|
|
export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ socketTask: null,//websocket对象
|
|
|
+ }
|
|
|
+ },
|
|
|
onLaunch: function () {
|
|
|
//消息推送
|
|
|
- uni.getPushClientId({
|
|
|
- //获取客户端推送标识
|
|
|
- success: (res) => {
|
|
|
- console.log(res.cid,'cid---');
|
|
|
- uni.setStorageSync('push_cid', res.cid); // 存储CID供后续使用
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- console.log(err)
|
|
|
- }
|
|
|
- });
|
|
|
- uni.onPushMessage((res) => {
|
|
|
- //客户端监听推送消息
|
|
|
- console.log("收到推送消息:",res) //监听推送消息
|
|
|
- if(res.data){
|
|
|
- console.log(res.data)
|
|
|
- uni.createPushMessage(res.data) //收到消息推送,创建系统状态栏及锁屏通 知
|
|
|
- }
|
|
|
- })
|
|
|
+ uni.getPushClientId({
|
|
|
+ //获取客户端推送标识
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res.cid, 'cid---');
|
|
|
+ uni.setStorageSync('push_cid', res.cid); // 存储CID供后续使用
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ uni.onPushMessage((res) => {
|
|
|
+ //客户端监听推送消息
|
|
|
+ console.log("收到推送消息:", res) //监听推送消息
|
|
|
+ if (res.data) {
|
|
|
+ uni.createPushMessage(res.data) //收到消息推送,创建系统状态栏及锁屏通 知
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
const savedIP = uni.getStorageSync("selectedIP");
|
|
|
if (configService.apiUrl !== "") {
|
|
@@ -298,23 +303,22 @@ export default {
|
|
|
},
|
|
|
onShow: function () {
|
|
|
console.log("App Show");
|
|
|
- this.times= setInterval(()=>this.getInfoInit(),10000)
|
|
|
+ this.getConnect()
|
|
|
},
|
|
|
onHide: function () {
|
|
|
console.log("App Hide");
|
|
|
clearInterval(this.$store.state.timer); // 假设定时器存储在 Vuex 的状态管理中
|
|
|
},
|
|
|
- methods:{
|
|
|
+ methods: {
|
|
|
+
|
|
|
//获取推送消息,标题
|
|
|
- getInfoInit(){
|
|
|
- console.log('获取推送消息,标题---')
|
|
|
- console.log(uni.getStorageSync('push_cid'), '111')
|
|
|
- uni.request({
|
|
|
+ getInfoInit(title, message) {
|
|
|
+ uni.request({
|
|
|
url: 'https://fc-mp-2578c13f-eaaa-45e9-a01e-6a48b45fb7a0.next.bspapp.com/testPush', //云函数url
|
|
|
data: {
|
|
|
cid: uni.getStorageSync('push_cid'),
|
|
|
- title: '报警信息通知', //可按需传入动态参数,在云函数index.js接收参数
|
|
|
- content: '测试通知信息',
|
|
|
+ title: title, //可按需传入动态参数,在云函数index.js接收参数
|
|
|
+ content: message,
|
|
|
},
|
|
|
method: 'get',
|
|
|
success(result) {
|
|
@@ -324,7 +328,26 @@ export default {
|
|
|
console.log('request fail', errMsg)
|
|
|
}
|
|
|
})
|
|
|
- }
|
|
|
+ },
|
|
|
+
|
|
|
+ //连接websocket
|
|
|
+ async getConnect() {
|
|
|
+ let that = this
|
|
|
+ try {
|
|
|
+ that.socketTask = await connectWebSocket();
|
|
|
+ that.socketTask.onMessage((res) => {
|
|
|
+ console.log('收到消息:websocket已连接 ', res)
|
|
|
+ let message = JSON.parse(res.data)
|
|
|
+ //报警信息推送
|
|
|
+ if (message.warndata) {
|
|
|
+ that.getInfoInit(message.msgTitle, message.warndata)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (err) {
|
|
|
+ console.log('连接失败: ' + err)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
@@ -333,6 +356,7 @@ export default {
|
|
|
@import "plugin/colorui/main.css";
|
|
|
@import "plugin/colorui/icon.css";
|
|
|
@import "plugin/colorui/animation.css";
|
|
|
+
|
|
|
.nav-list {
|
|
|
display: flex;
|
|
|
flex-wrap: wrap;
|