Commit f1f8deab authored by van.chen's avatar van.chen

更新一版

parent 2937d719
import {Component, AfterViewInit} from '@angular/core'; import {Component, AfterViewInit, OnDestroy} from '@angular/core';
import {Platform} from '@ionic/angular'; import {Platform} from '@ionic/angular';
import {SplashScreen} from '@ionic-native/splash-screen/ngx'; import {SplashScreen} from '@ionic-native/splash-screen/ngx';
import {StatusBar} from '@ionic-native/status-bar/ngx'; import {StatusBar} from '@ionic-native/status-bar/ngx';
import {Router, NavigationEnd} from '@angular/router'; import {Router, NavigationEnd} from '@angular/router';
import { AppMinimize } from '@ionic-native/app-minimize/ngx'; import { AppMinimize } from '@ionic-native/app-minimize/ngx';
declare var screen: any; declare var screen: any;
declare var mqtt: any;
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
...@@ -82,7 +84,7 @@ declare var screen: any; ...@@ -82,7 +84,7 @@ declare var screen: any;
} }
`] `]
}) })
export class AppComponent implements AfterViewInit { export class AppComponent implements AfterViewInit, OnDestroy {
constructor( constructor(
private platform: Platform, private platform: Platform,
private splashScreen: SplashScreen, private splashScreen: SplashScreen,
...@@ -96,6 +98,19 @@ export class AppComponent implements AfterViewInit { ...@@ -96,6 +98,19 @@ export class AppComponent implements AfterViewInit {
private backBtnPressed; private backBtnPressed;
private url; private url;
private flag = 0; private flag = 0;
client;
topic;
msg;
private options = {
keepalive: 10,
clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
protocolId: 'MQTT',
protocolVersion: 4,
clean: false,
connectTimeout: 60000,
username: 'pasture',
password: 'Pasture37774020',
};
initializeApp() { initializeApp() {
this.platform.ready().then(() => { this.platform.ready().then(() => {
...@@ -123,6 +138,11 @@ export class AppComponent implements AfterViewInit { ...@@ -123,6 +138,11 @@ export class AppComponent implements AfterViewInit {
this.statusBar.overlaysWebView(false); this.statusBar.overlaysWebView(false);
this.splashScreen.hide(); this.splashScreen.hide();
} }
this.initMqtt();
}
ngOnDestroy(): void {
this.endMqtt();
} }
initRouterListen() { initRouterListen() {
...@@ -153,4 +173,22 @@ export class AppComponent implements AfterViewInit { ...@@ -153,4 +173,22 @@ export class AppComponent implements AfterViewInit {
} }
}); });
} }
initMqtt() {
this.client = mqtt.connect('ws://172.16.1.24:8083/mqtt', this.options);
this.topic = 'Pasture/cy/Alarm';
this.client.on('connect', () => {
this.msg = 'mqtt连接成功';
this.client.subscribe(this.topic);
this.client.on('message', (a, b) => {
console.log(a, JSON.parse(b.toString()));
});
});
}
endMqtt() {
this.client.unsubscribe(this.topic);
this.client.disconnect();
}
} }
...@@ -4,8 +4,6 @@ import {ActivatedRoute} from '@angular/router'; ...@@ -4,8 +4,6 @@ import {ActivatedRoute} from '@angular/router';
import {Api} from '../service/api'; import {Api} from '../service/api';
import {Load} from '../service/load'; import {Load} from '../service/load';
declare var mqtt: any;
@Component({ @Component({
selector: 'v-home', selector: 'v-home',
templateUrl: 'home.page.html', templateUrl: 'home.page.html',
...@@ -17,18 +15,6 @@ export class HomePage implements OnInit, OnDestroy { ...@@ -17,18 +15,6 @@ export class HomePage implements OnInit, OnDestroy {
private api: Api, private load: Load) {} private api: Api, private load: Load) {}
@ViewChild('slide') slide; @ViewChild('slide') slide;
// client;
// topic;
// private options = {
// keepalive: 10,
// clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
// protocolId: 'MQTT',
// protocolVersion: 4,
// clean: false,
// connectTimeout: 60000,
// username: 'pasture',
// password: 'Pasture37774020',
// };
imgs = ['1.jpg', '2.jpg', '3.jpg']; imgs = ['1.jpg', '2.jpg', '3.jpg'];
...@@ -124,11 +110,9 @@ export class HomePage implements OnInit, OnDestroy { ...@@ -124,11 +110,9 @@ export class HomePage implements OnInit, OnDestroy {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.endMqtt();
} }
init() { init() {
this.initMqtt();
this.getData(1); this.getData(1);
} }
...@@ -214,24 +198,6 @@ export class HomePage implements OnInit, OnDestroy { ...@@ -214,24 +198,6 @@ export class HomePage implements OnInit, OnDestroy {
}]); }]);
} }
initMqtt() {
// this.client = mqtt.connect('ws://120.27.235.39:8083/mqtt', this.options);
// this.topic = 'topic/hello';
//
// this.client.on('connect', () => {
// this.msg = 'mqtt连接成功';
// this.client.subscribe(this.topic);
// this.client.on('message', (a, b) => {
// console.log(a, b);
// });
// });
}
endMqtt() {
// this.client.unsubscribe(this.topic);
// this.client.disconnect();
}
slideDidChange() { slideDidChange() {
this.slide.startAutoplay(); this.slide.startAutoplay();
} }
......
<div class="mainCon" style="background: url('../../assets/bg/index.jpg') 100% 100%;background-size: cover;"> <div class="mainCon" style="background: url('../../assets/bg/index.png') 100% 100%;background-size: cover;">
<div class="mainTop"> <div class="mainTop">
<div class="imgTop"> <div class="imgTop">
<img style="width: auto !important;" src="../../assets/icon/favicon.png"> <img style="width: auto !important;" src="../../assets/icon/cow.png">
</div> </div>
<div style="font-size: 35px;line-height: 55px;height: 20%;border-bottom: 2px solid #ccc;width: 65%;display: inline-block;margin-bottom: 3%;"> <div style="font-size: 35px;line-height: 55px;height: 20%;border-bottom: 2px solid #ccc;width: 65%;display: inline-block;margin-bottom: 3%;">
Welcome! Welcome!
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
.mainContent { .mainContent {
height: calc(50% - 60px); height: calc(50% - 60px);
padding: 15px 40px 45px 40px; padding: 15px 20px 45px 20px;
} }
.contentPart { .contentPart {
...@@ -22,22 +22,23 @@ ...@@ -22,22 +22,23 @@
} }
.leftPart { .leftPart {
background-color: #ffcc99; background: url("../../assets/index/left.png");
background-size: 110% 100%;
height: 100%; height: 100%;
width: calc(50% - 0.5px); width: calc(50% - 0.5px);
margin-right: 1px; margin-right: 1px;
display: inline-block; display: inline-block;
border-radius: 65px 0 0 65px; border-radius: 65px 0 0 65px;
box-shadow: #aaaaaa 2px 2px 10px;
} }
.rightPart { .rightPart {
background-color: #e58380; background: url("../../assets/index/right.png");
height: 100%; height: 100%;
width: calc(50% - 0.5px); width: calc(50% - 0.5px);
background-size: 100% 100%;
margin-left: -10px;
display: inline-block; display: inline-block;
border-radius: 0 65px 65px 0; border-radius: 0 65px 65px 0;
box-shadow: #aaaaaa 2px 2px 10px;
} }
.rightPart:active, .leftPart:active { .rightPart:active, .leftPart:active {
...@@ -46,14 +47,14 @@ ...@@ -46,14 +47,14 @@
} }
.centerPart { .centerPart {
background: url("../../assets/index/center.png") center;
background-size: 110%;
position: absolute; position: absolute;
top: calc(50% - 75px); top: calc(50% - 75px);
height: 150px; height: 150px;
width: 150px; width: 150px;
background-color: #66cccc;
left: calc(50% - 75px); left: calc(50% - 75px);
border-radius: 100%; border-radius: 100%;
box-shadow: #FFFFFF 2px 2px 10px;
} }
.centerPart:active { .centerPart:active {
background-color: #ff9933; background-color: #ff9933;
......
...@@ -7,19 +7,18 @@ export class Load { ...@@ -7,19 +7,18 @@ export class Load {
private isLoad = false; private isLoad = false;
private time = 0; private time = 0;
private _nFlag = false; // private _nFlag = false;
toLoad(msg, type) { toLoad(msg, type) {
this.isLoad = true; this.isLoad = true;
document.getElementById('v-loading').style.display = 'block'; document.getElementById('v-loading').style.display = 'block';
document.getElementById('loading-inner').innerText = msg; document.getElementById('loading-inner').innerText = msg;
if (!this._nFlag && type) { if (type) {
this.time = 0; this.time = 0;
// @ts-ignore // @ts-ignore
document.getElementsByClassName('circle_process')[0].style.display = 'block'; document.getElementsByClassName('circle_process')[0].style.display = 'block';
document.getElementById('innerNum').innerText = this.time.toString() + 's'; document.getElementById('innerNum').innerText = this.time.toString() + 's';
this.addNum(); this.addNum();
this._nFlag = true;
} }
} }
...@@ -35,12 +34,12 @@ export class Load { ...@@ -35,12 +34,12 @@ export class Load {
offLoad() { offLoad() {
this.isLoad = false; this.isLoad = false;
if (this._nFlag) { // if (this._nFlag) {
this._nFlag = false; // this._nFlag = false;
// @ts-ignore // // @ts-ignore
document.getElementsByClassName('circle_process')[0].style.display = 'none'; // document.getElementsByClassName('circle_process')[0].style.display = 'none';
document.getElementById('innerNum').style.display = 'none'; // document.getElementById('innerNum').style.display = 'none';
} // }
document.getElementById('v-loading').style.display = 'none'; document.getElementById('v-loading').style.display = 'none';
document.getElementById('loading-inner').innerText = ''; document.getElementById('loading-inner').innerText = '';
document.getElementById('innerNum').innerText = '0s'; document.getElementById('innerNum').innerText = '0s';
......
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {NavController} from '@ionic/angular';
@Injectable() @Injectable()
export class Transfer { export class Transfer {
constructor(private router: Router) {} constructor(private router: Router, private nc: NavController) {}
transfer(req) { transfer(req) {
// 此处为ionic4路由跳转的时候不清空之前的页面组件造成的页面短暂交叠 // 此处为ionic4路由跳转的时候不清空之前的页面组件造成的页面短暂交叠
// ionic4在发生路由跳转的时候是先进行新组件的加载再进行旧组件的隐藏 // ionic4在发生路由跳转的时候是先进行新组件的加载再进行旧组件的隐藏
// 我没有找到相关的api以及解决办法,如果后面的人找到了的话麻烦将这个麻烦的方法给解决掉 // 我没有找到相关的api以及解决办法,如果后面的人找到了的话麻烦将这个麻烦的方法给解决掉
if (document.getElementsByTagName('v' + req.url.replace(/\//, '-')).length > 0) { // if (document.getElementsByTagName('v' + req.url.replace(/\//, '-')).length > 0) {
const y = <HTMLBodyElement>document.getElementsByTagName('v' + req.url.replace(/\//, '-'))[0]; // const y = <HTMLBodyElement>document.getElementsByTagName('v' + req.url.replace(/\//, '-'))[0];
y.style.visibility = 'visible'; // y.style.visibility = 'visible';
} // }
req.query = req.query ? req.query : {}; // req.query = req.query ? req.query : {};
req.query.refresh = + new Date(); // req.query.refresh = + new Date();
this.router.navigate([req.url], {queryParams: req.query, fragment: req.hash}); // this.router.navigate([req.url], {queryParams: req.query, fragment: req.hash});
if (document.getElementsByTagName('v' + window.location.pathname.replace(/\//, '-')).length > 0) { // if (document.getElementsByTagName('v' + window.location.pathname.replace(/\//, '-')).length > 0) {
const x = <HTMLBodyElement>document.getElementsByTagName('v' + window.location.pathname.replace(/\//, '-'))[0]; // const x = <HTMLBodyElement>document.getElementsByTagName('v' + window.location.pathname.replace(/\//, '-'))[0];
x.style.visibility = 'hidden'; // x.style.visibility = 'hidden';
setTimeout(() => { // setTimeout(() => {
// 此处是防止移动端自己的back button跳转导致页面空白 // // 此处是防止移动端自己的back button跳转导致页面空白
x.style.visibility = 'visible'; // x.style.visibility = 'visible';
}, 1000); // }, 1000);
} // }
if (!req.query) { req.query = ''; }
this.nc.navigateRoot(req.url + req.query);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment