<script>
|
import Vue from 'vue'
|
|
export default {
|
globalData: {
|
token: ""
|
},
|
onLaunch: function() {
|
|
|
|
//此处为unipush2.0的推送方法
|
// uni-app客户端获取push客户端标记
|
// uni.getPushClientId({
|
// success: (res) => {
|
// let push_clientid = res.cid
|
// console.log('客户端推送标识:', push_clientid)
|
// },
|
// fail(err) {
|
// console.log(err)
|
// }
|
// })
|
// uni.onPushMessage((res) => {
|
// console.log("收到推送消息:", res) //监听推送消息
|
// })
|
|
|
//推送仅支持Android ios原生平台
|
// #ifdef APP-PLUS
|
console.log('APP-PLUS:')
|
// 此处为unipush1.0的推送方法
|
plus.push.getClientInfoAsync((info) => {
|
let cid = info["clientid"];
|
console.log('客户端推送标识:', cid)
|
this.$store.dispatch('setCid', cid); // 使用 action 更新 cid
|
});
|
// #endif
|
uni.onPushMessage((res) => {
|
console.log("收到推送消息:", res) //监听推送消息
|
})
|
|
|
|
uni.getSystemInfo({
|
success: function(e) {
|
// #ifndef MP
|
Vue.prototype.StatusBar = e.statusBarHeight;
|
if (e.platform == 'android') {
|
Vue.prototype.CustomBar = e.statusBarHeight + 50;
|
} else {
|
Vue.prototype.CustomBar = e.statusBarHeight + 45;
|
};
|
// #endif
|
|
// #ifdef MP-WEIXIN
|
Vue.prototype.StatusBar = e.statusBarHeight;
|
let custom = wx.getMenuButtonBoundingClientRect();
|
Vue.prototype.Custom = custom;
|
Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight + 4;
|
// #endif
|
|
// #ifdef MP-ALIPAY
|
Vue.prototype.StatusBar = e.statusBarHeight;
|
Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
|
// #endif
|
}
|
});
|
console.log('App Launch')
|
},
|
onShow: function() {
|
console.log('App Show')
|
// this.conn()
|
|
|
},
|
onHide: function() {
|
console.log('App Hide')
|
// this.disconn()
|
},
|
methods: {
|
//处理掉线重连
|
conn() {
|
console.log(this.$mqttTool.client)
|
if (this.$mqttTool.client) {
|
console.log(this.$mqttTool.client.connected)
|
}
|
if (this.$mqttTool.client && !this.$mqttTool.client.connected) {
|
console.info("开始重连")
|
this.$mqttTool.reconnect()
|
} else {
|
|
}
|
},
|
disconn() {
|
console.log(this.$mqttTool.client)
|
if (this.$mqttTool.client) {
|
console.log(this.$mqttTool.client.connected)
|
}
|
// if(this.$mqttTool.client){
|
// this.$mqttTool.end().then(res =>{
|
// console.log('终止:')
|
// })
|
|
// }
|
}
|
|
},
|
mounted() {
|
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
/*每个页面公共css */
|
@import "colorui/main.css";
|
@import "colorui/icon.css";
|
@import "uview-ui/index.scss";
|
</style>
|