12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- var alog = uni.requireNativePlugin("AndroidLog")
- let speaker = uni.requireNativePlugin("SpeechPlug");
- const _handlePush = function(message) {
- //{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
- try {
- alog.info({msg: '接收到消息:' + message});
- const value = uni.getStorageSync('pushreg_switch');
- if (value) {
- return;
- }
- const roadinfoCache = uni.getStorageSync('payee_roadinfo');
- alog.info({msg: '本地路段信息:' + roadinfoCache});
- if (!roadinfoCache){
- return;
- }
- let content = JSON.parse(message.content);
- const roadinfo = JSON.parse(roadinfoCache) ;
- if(content.roadNo && roadinfo.roadNo && content.roadNo == roadinfo.roadNo){
- if (content.type === 1){
- deviceParkIn(content)
- }else if (content.type === 2){
- deviceParkOut(content)
- }
- }
- } catch(e){
-
- }
-
- };
- // content 消息格式: JSON格式
- // type: 1-设备入场 2-设备出场 3-用户已经支付
- // speakMsg: 语音播报内容
- // popNode: 弹出框内容
- // jumpTo: 页面跳转地址
- // data: {} 其他参数,JSON格式
- function deviceParkIn(content){
- //获取存储的设备入场语音播报开关状态
- uni.getStorage({
- key:'speakData',
- success: (res) => {
- let speakDeviceParkIn = res.data.switchVal1;
- },
- fail: (err) => {
- }
- })
- if(content.speakMsg&&speakDeviceParkIn==true){
- speaker.speakAction(content.speakMsg)
- }
- // const value = uni.getStorageSync('pushModel_switch');
- // if (value) {
- // return;
- // }
- // uni.setStorageSync('pushModel_switch', '1');
- // uni.showModal({
- // title: '温馨提示',
- // content: content.popNode,
- // success: (res) => {
- // if(res.confirm){
- // uni.navigateTo({
- // url: content.jumpTo
- // });
- // }
- // } ,
- // complete:()=>{
- // uni.removeStorageSync('pushModel_switch');
- // }
- // });
- }
- function deviceParkOut(content){
- //获取存储的设备出场语音播报开关状态
- uni.getStorage({
- key:'speakData',
- success: (res) => {
- let speakDeviceParkOut = res.data.switchVal2;
- },
- fail: (err) => {
- }
- })
- if(content.speakMsg&&speakDeviceParkOut==true){
- speaker.speakAction(content.speakMsg)
- }
- }
- function pushreg(vue){
-
- //添加推送开关
- uni.setStorageSync('pushreg_switch', '1');
- //监听系统通知栏消息点击事件
- plus.push.addEventListener('click', _handlePush, false);
- //监听接收透传消息事件
- plus.push.addEventListener('receive', _handlePush, false);
- }
- export default pushreg
|