123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <script>
- export default {
- data(){
- return{
- lastTapTime: 0, // 记录上次点击的时间
- }
- },
- onLaunch: function() {
- console.log('App Launch');
- //#ifdef APP-PLUS
- var info = plus.push.getClientInfo();
- console.log(JSON.stringify(info));
- uni.setStorageSync('clientid', info.clientid); //记住cid
- //收到透传消息
- //只有APP在线时,才会触发receive事件,透传消息不会触发系统消息,需要创建本地消息
- plus.push.addEventListener("receive", function(msg) {
- console.log("(receive):" + JSON.stringify(msg));
- // 播报 start
- // const innerAudioContext = uni.createInnerAudioContext();
- // innerAudioContext.autoplay = true;
- // innerAudioContext.src = 'http://fanyi.baidu.com/gettts?lan=zh&text=' + msg.content + '&spd=5&source=web';
- // 播报 end
- // if (app.isIOS()) { //如果是IOS
- // var payload = msg.payload;
- // //【APP离线】收到消息,但没有提醒(发生在一次收到多个离线消息时,只有一个有提醒,但其他的没有提醒)
- // //【APP在线】收到消息,不会触发系统消息,需要创建本地消息,但不能重复创建。必须加msg.type验证去除死循环
- // if (msg.aps == null && msg.type == "receive") {
- // var messageTitle = payload.messageTitle;
- // var messageContent = payload.messageContent;
- // //创建本地消息,发送的本地消息也会被receive方法接收到,但没有type属性,且aps是null
- // plus.push.createMessage(messageContent, JSON.stringify(payload), {
- // title: messageTitle
- // });
- // }
- // }
- // if (app.isAndroid()) { //如果是Android,当APP在线时,收到透传消息不会进入系统消息,需要发送本地提醒。
- // var payload = JSON.parse(msg.payload);
- // var messageTitle = payload.messageTitle;
- // var messageContent = payload.messageContent;
- // plus.push.createMessage(messageContent, msg.payload, {
- // title: messageTitle
- // });
- // }
- }, false);
- //消息点击事件
- //【APP在线】,收到透传消息通过,不会提醒至通知栏目,需要发送本地消息,再进行点击触发的点击事件。
- //【APP离线】,收到离线透传消息,必须通过Java后台的Intent字符串携带payload,且符合格式才能触发click事件,格式不符合不会触发。
- plus.push.addEventListener("click", function(msg) {
- console.log("(click):" + JSON.stringify(msg));
- // if (app.isIOS()) { //如果是IOS
- // var payload;
- // if (msg.type == "click") { //APP离线点击包含click属性,这时payload是JSON对象
- // payload = msg.payload;
- // } else { //APP在线,收到消息不会包含type属性,这时的payload是JSON字符串,需要转为JSON对象
- // payload = JSON.parse(msg.payload);
- // }
- // if (payload != null || payload != undefined) {
- // var messageType = payload.messageType;
- // messageClick(messageType, payload);
- // }
- // }
- // if (app.isAndroid()) { //如果是Android,收到playload均是是JSON字符串,需要转为JSON对象
- // var payload = JSON.parse(msg.payload);
- // if (payload != null || payload != undefined) {
- // var messageType = payload.messageType;
- // messageClick(messageType, payload);
- // }
- // }
- }, false);
- //#endif
- },
- onShow: function() {
- console.log('App Show');
- let that = this
- // #ifdef APP-PLUS
- plus.key.addEventListener('backbutton', that.handleBackButton)
- // #endif
- // uni.redirectTo({
- // url: "../mypage/mypage",
- // });
- },
- onHide: function() {
- console.log('App Hide');
- let that = this
- // #ifdef APP-PLUS
- plus.key.removeEventListener('backbutton', that.handleBackButton)
- // #endif
- // uni.closeSocket();
- // uni.onSocketClose(function(res) {
- // console.log('WebSocket 已关闭!');
- // });
- },
- methods: {
- handleBackButton() {
- let currentTime = new Date().getTime(); // 获取当前点击时间
- if (currentTime - this.lastTapTime < 500) { // 如果两次点击间隔在500毫秒以内,认为是双击
- // 双击事件处理逻辑
- console.log('双击了返回键');
- // 你的双击事件处理代码
- plus.runtime.quit(); // 示例:用户双击返回键时,执行页面返回操作
- }
- this.lastTapTime = currentTime; // 更新最后点击时间
- }
- }
- }
- </script>
- <style>
- @import url("./static/font/iconfont.css");
- @import url("/node_modules/spinkit/spinkit.css");
- /*每个页面公共css */
- html {
- width: 100%;
- height: 100%;
- background: #f9fafb;
- --sk-size: 20rpx !important;
- --sk-color: #49b856 !important;
- }
- body {
- height: 100%;
- box-sizing: border-box;
- /* padding-top: 96rpx; */
- font-family: "Helvetica Neue";
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- }
- #app {
- margin: 0px;
- padding: 0px;
- text-align: center;
- font-size: 14px;
- color: rgb(51, 51, 51);
- width: 100%;
- height: 100%;
- }
- /* 按钮点击态 */
- .seimin-btn-hover {
- box-shadow: 0px 0px 8px rgba(0, 0, 0, .1) inset !important;
- }
- .uni-picker-action-confirm {
- color: #49b856 !important;
- }
-
- .selected-item-active{
- border-color: #49b856 !important;;
- }
-
- .footerPadding {
- padding-bottom: 50rpx !important;
- }
- .footerOtherMargin {
- padding-bottom: 174rpx !important;
- }
- .red {
- color: red !important;
- }
- .fweight {
- font-weight: bold !important;
- }
- .f30 {
- font-size: 30rpx !important;
- }
- .mt8{
- margin-top: 16rpx !important;
- }
- .check{
- border-color:#49b856 !important;
- }
- </style>
|