2023-01-11 16:33:13 +08:00
|
|
|
<script>
|
2023-03-16 15:26:25 +08:00
|
|
|
import encrypt from './common/js/aes.js'
|
2023-03-30 09:04:07 +08:00
|
|
|
import {
|
|
|
|
|
MQTT_IP,
|
|
|
|
|
MQTT_OPTIONS
|
|
|
|
|
} from './common/js/mqtt.js';
|
|
|
|
|
import mqtt from 'mqtt/dist/mqtt.js'
|
2023-01-11 16:33:13 +08:00
|
|
|
export default {
|
2023-03-30 09:04:07 +08:00
|
|
|
methods: {
|
|
|
|
|
connect () {
|
|
|
|
|
MQTT_OPTIONS.clientId = uni.getStorageSync('cidAES')
|
|
|
|
|
var that = this
|
|
|
|
|
let client = mqtt.connect('ws://' + MQTT_IP, MQTT_OPTIONS)
|
|
|
|
|
client.on('connect', function () {
|
|
|
|
|
console.log('连接成功')
|
|
|
|
|
client.subscribe(that.topic, function (err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
console.log('订阅成功')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}).on('reconnect', function (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
console.log('正在重连...', that.topic)
|
|
|
|
|
}).on('error', function (error) {
|
|
|
|
|
console.log('连接失败...', error)
|
|
|
|
|
}).on('end', function () {
|
|
|
|
|
console.log('连接断开')
|
|
|
|
|
}).on('message', function (topic, message) {
|
|
|
|
|
console.log('接收推送信息:', message.toString())
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-01-11 16:33:13 +08:00
|
|
|
onLaunch: function () {
|
2023-03-30 09:04:07 +08:00
|
|
|
// this.connect()
|
2023-03-20 08:51:21 +08:00
|
|
|
let cidAES = uni.getStorageSync('cidAES') || 'nnvmhMk8626D8QHhJefm+W9rTAJWuBPRxcnRm4+9bWXdSLRIyTnTruoYfLxGK3Oy'
|
|
|
|
|
uni.setStorageSync('cidAES', cidAES);
|
2023-03-16 15:26:25 +08:00
|
|
|
if (!cidAES) {
|
2023-03-20 08:51:21 +08:00
|
|
|
document.addEventListener('plusready', () => {
|
|
|
|
|
// 页面加载时触发
|
|
|
|
|
let pinf = plus.push.getClientInfo();
|
|
|
|
|
let cid = pinf.clientid;//客户端标识
|
|
|
|
|
cidAES = encrypt.Encrypt(cid, this.$config.key);
|
|
|
|
|
uni.setStorageSync('cidAES', cidAES);
|
|
|
|
|
}, false);
|
2023-03-16 15:26:25 +08:00
|
|
|
}
|
2023-03-30 09:04:07 +08:00
|
|
|
|
2023-01-11 16:33:13 +08:00
|
|
|
},
|
|
|
|
|
onShow: function () {
|
|
|
|
|
console.log('App Show')
|
|
|
|
|
},
|
|
|
|
|
onHide: function () {
|
|
|
|
|
console.log('App Hide')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
/*每个页面公共css */
|
|
|
|
|
@import './common/css/base.scss';
|
2023-03-16 15:26:25 +08:00
|
|
|
|
|
|
|
|
/deep/ uni-tabbar .uni-tabbar__badge {
|
2023-02-09 08:50:01 +08:00
|
|
|
width: auto;
|
|
|
|
|
height: 28rpx;
|
|
|
|
|
line-height: 28rpx;
|
|
|
|
|
border-radius: 28rpx;
|
|
|
|
|
min-width: 28rpx;
|
|
|
|
|
font-size: 20rpx;
|
|
|
|
|
padding: 0 8rpx;
|
|
|
|
|
}
|
2023-01-11 16:33:13 +08:00
|
|
|
</style>
|