|
@@ -2,22 +2,22 @@
|
|
<div id="rtone">
|
|
<div id="rtone">
|
|
<ul>
|
|
<ul>
|
|
<li>
|
|
<li>
|
|
- 累计完成进尺 :<span>{{one}}</span>m
|
|
|
|
|
|
+ 累计完成进尺 :<span>{{data.leijijinchi}}</span>m
|
|
</li>
|
|
</li>
|
|
<li>
|
|
<li>
|
|
- 月 完 成 进尺 :<span>{{two}}</span> m
|
|
|
|
|
|
+ 月 完 成 进尺 :<span>{{data.yuejinchi}}</span> m
|
|
</li>
|
|
</li>
|
|
<li>
|
|
<li>
|
|
- 日 平 均 进尺 :<span>{{three}}</span> m
|
|
|
|
|
|
+ 日 平 均 进尺 :<span>{{data.rizuigaojinchi}}</span> m
|
|
</li>
|
|
</li>
|
|
<li>
|
|
<li>
|
|
- 班 最 高 进尺 :<span>{{four}}</span> m
|
|
|
|
|
|
+ 班 最 高 进尺 :<span>{{data.banzuigaojinchi}}</span> m
|
|
</li>
|
|
</li>
|
|
<li>
|
|
<li>
|
|
- 日 最 高 进尺 :<span>{{five}}</span> m
|
|
|
|
|
|
+ 日 最 高 进尺 :<span>{{data.rizuigaojinchi}}</span> m
|
|
</li>
|
|
</li>
|
|
<li>
|
|
<li>
|
|
- 当 前___人 员 :<span id="six">{{six}}</span>
|
|
|
|
|
|
+ 当 前___人 员 :<span id="six">{{data.dangqianrenyuan}}</span>
|
|
</li>
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
</ul>
|
|
@@ -25,81 +25,74 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
+import { mapState } from "vuex";
|
|
export default {
|
|
export default {
|
|
- data(){
|
|
|
|
|
|
+ data(){
|
|
return {
|
|
return {
|
|
- // showValue:'',
|
|
|
|
- one:'',
|
|
|
|
- two:'',
|
|
|
|
- three:'',
|
|
|
|
- four:'',
|
|
|
|
- five:'',
|
|
|
|
- six:'',
|
|
|
|
- allData:null, // 服务器返回的数据
|
|
|
|
-
|
|
|
|
- currentPage: 1, //当前显示的页数, 当修改页数时, 数据动态刷新
|
|
|
|
|
|
|
|
- totalPage: 0, //一共多少也
|
|
|
|
- timerId:null, //定时器
|
|
|
|
|
|
+ data: {
|
|
|
|
+ dangqianrenyuan: "0",
|
|
|
|
+ qnm:"0",
|
|
|
|
+ banzuigaojinchi:"0",
|
|
|
|
+ rizuigaojinchi:"0",
|
|
|
|
+ leijijinchi:"0",
|
|
|
|
+ yuejinchi:"0",
|
|
|
|
+ rijinchi:"0"
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
mounted() {
|
|
mounted() {
|
|
- this.getData()
|
|
|
|
- // 对窗口大小变化的事件进行监听
|
|
|
|
- // window.addEventListener('resize', this.screenAdapter)
|
|
|
|
- },
|
|
|
|
- destroyed(){
|
|
|
|
- clearInterval(this.timerId)
|
|
|
|
- // 在组件销毁的时候, 需要将监听器取消掉
|
|
|
|
- // window.removeEventListener('resize', this.screenAdapter)
|
|
|
|
|
|
+ this.websocket = new WebSocket(
|
|
|
|
+ `ws://${this.websocketIP}/hbase/ws/belt/53`
|
|
|
|
+ );
|
|
|
|
+ this.initWebSocket();
|
|
},
|
|
},
|
|
- methods: {
|
|
|
|
- async getData(){
|
|
|
|
- // 请求数据 allData
|
|
|
|
- const { data: ret } = await this.$http.get('hbase/getJSON')
|
|
|
|
- this.allData = ret
|
|
|
|
- // 对数据排序
|
|
|
|
- this.allData.sort((a,b) => {{
|
|
|
|
- return a.value-b.value //从小到大排序
|
|
|
|
- }})
|
|
|
|
- // 每1个元素显示一页
|
|
|
|
- this.totalPage = this.allData.length % 1 ===0 ? this.allData.length /1 : this.allData.length / 1 +1
|
|
|
|
-
|
|
|
|
- // 获取完数据, 更新图标
|
|
|
|
- this.updateData()
|
|
|
|
-
|
|
|
|
- // 启动定时器, 每隔三秒改变currentPage, 进而更新图表
|
|
|
|
- this.startInterval()
|
|
|
|
|
|
+ methods:{
|
|
|
|
+ initWebSocket() {
|
|
|
|
+ // 连接错误
|
|
|
|
+ this.websocket.onerror = () => {
|
|
|
|
+ console.log(
|
|
|
|
+ "WebSocket连接发生错误 状态码:" + this.websocket.readyState
|
|
|
|
+ );
|
|
|
|
+ };
|
|
|
|
+ // 连接成功
|
|
|
|
+ this.websocket.onopen = () => {
|
|
|
|
+ console.log(
|
|
|
|
+ "WebSocket连接成功 状态码:" + this.websocket.readyState
|
|
|
|
+ );
|
|
|
|
+ };
|
|
|
|
+ // 收到消息的回调
|
|
|
|
+ this.websocket.onmessage = (event) => {
|
|
|
|
+ if (JSON.parse(event.data).length) {
|
|
|
|
+ this.changeState(JSON.parse(event.data));
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ // 连接关闭的回调
|
|
|
|
+ this.websocket.onclose = () => {
|
|
|
|
+ console.log(
|
|
|
|
+ "WebSocket连接关闭 状态码:" + this.websocket.readyState
|
|
|
|
+ );
|
|
|
|
+ };
|
|
|
|
+ // 通过$once来监听定时器,在beforeDestroy钩子可以被清除。
|
|
|
|
+ this.$once("hook:beforeDestroy", () => {
|
|
|
|
+ this.websocket.close();
|
|
|
|
+ });
|
|
},
|
|
},
|
|
- updateData() {
|
|
|
|
-
|
|
|
|
- const start = (this.currentPage - 1) * 1
|
|
|
|
- const end = this.currentPage * 1
|
|
|
|
- const showData = this.allData.slice(start, end)
|
|
|
|
- this.one = showData[0].leijiwanchengjinchi
|
|
|
|
- this.two = showData[0].benyuewanchengjinchi
|
|
|
|
- this.three = showData[0].ripingjunjinchi
|
|
|
|
- this.four = showData[0].banzuigaojinchi
|
|
|
|
- this.five = showData[0].rizuigaojinchi
|
|
|
|
- this.six = showData[0].dangqianrenyuan
|
|
|
|
|
|
+ changeState(data) {
|
|
|
|
+ this.data = data[0]
|
|
|
|
+ },
|
|
|
|
+ close() {
|
|
|
|
+ this.websocket.close();
|
|
|
|
+ console.log(123);
|
|
},
|
|
},
|
|
- startInterval () {
|
|
|
|
- // 每个3秒执行一次
|
|
|
|
- setInterval(() => {
|
|
|
|
- // 保险操作
|
|
|
|
- if(this.timeId){
|
|
|
|
- clearInterval(this.timerId)
|
|
|
|
- }
|
|
|
|
- this.currentPage++
|
|
|
|
- // 当页数超过总页数是, 从头开始
|
|
|
|
- if(this.currentPage > this.totalPage){
|
|
|
|
- this.currentPage = 1
|
|
|
|
- }
|
|
|
|
- this.updateData()
|
|
|
|
- },3000)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ ...mapState(["websocketIP"]),
|
|
|
|
+ },
|
|
|
|
+
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|