From e0f9517f4b60d253b46abb20feb15d23ebaf32bc Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Wed, 22 Mar 2023 16:31:34 +0800
Subject: [PATCH] 添加断开连接的按钮
---
src/views/funcView.vue | 258 +++++++++++++++++++++++++++++++++++++++------------
1 files changed, 195 insertions(+), 63 deletions(-)
diff --git a/src/views/funcView.vue b/src/views/funcView.vue
index 16e85c9..5d322f2 100644
--- a/src/views/funcView.vue
+++ b/src/views/funcView.vue
@@ -3,9 +3,13 @@
<el-row>
<el-col :span="4">
<div class="search">
- <avue-form :option="option" v-model="form" @submit="handleSubmit">
- <template slot-scope="{}" slot="modulesIdLabel">
+ <avue-form ref="form" :option="option" v-model="form" @submit="connect">
+ <template slot-scope="{}" slot="equipmentCodeLabel">
<span></span>
+ </template>
+ <template slot-scope="{size}" slot="menuForm">
+ <el-button v-if="!socketIoClient" type="primary" :size="size" @click="$refs.form.submit()">连 接</el-button>
+ <el-button v-if="socketIoClient" type="danger" :size="size" @click="disconnect">断 开</el-button>
</template>
</avue-form>
</div>
@@ -28,38 +32,50 @@
</el-col>
<el-col :span="20">
<div class="show">
- <Flipbook v-if="viewType == 2" class="flipbook"
- :pages="flipConfig.pages"
- :startPage="flipConfig.pageNum"
- v-slot="flipbook"
- ref="flipbook">
- <div class="action-bar">
- <left-icon
- class="btn left"
- :class="{ disabled: !flipbook.canFlipLeft }"
- @click="flipbook.flipLeft"
- />
- <plus-icon
- class="btn plus"
- :class="{ disabled: !flipbook.canZoomIn }"
- @click="flipbook.zoomIn"
- />
- <span class="page-num">
+
+ <div v-if="menu.property == 1">
+ <img :src="menu.fileUrl[0].value"/>
+ </div>
+
+ <div v-if="menu.property == 2">
+ <Flipbook v-if="menu.type == 2" class="flipbook"
+ :pages="flipConfig.pages"
+ :startPage="flipConfig.pageNum"
+ v-slot="flipbook"
+ ref="flipbook">
+ <div class="action-bar">
+ <left-icon
+ class="btn left"
+ :class="{ disabled: !flipbook.canFlipLeft }"
+ @click="left"
+ />
+ <plus-icon
+ class="btn plus"
+ :class="{ disabled: !flipbook.canZoomIn }"
+ @click="flipbook.zoomIn"
+ />
+ <span class="page-num">
Page {{ flipbook.page }} of {{ flipbook.numPages }}
</span>
- <minus-icon
- class="btn minus"
- :class="{ disabled: !flipbook.canZoomOut }"
- @click="flipbook.zoomOut"
- />
- <right-icon
- class="btn right"
- :class="{ disabled: !flipbook.canFlipRight }"
- @click="flipbook.flipRight"
- />
- </div>
- </Flipbook>
- <iframe v-if="viewType == 3" class="view-iframe" :src="path"/>
+ <minus-icon
+ class="btn minus"
+ :class="{ disabled: !flipbook.canZoomOut }"
+ @click="flipbook.zoomOut"
+ />
+ <right-icon
+ class="btn right"
+ :class="{ disabled: !flipbook.canFlipRight }"
+ @click="right"
+ />
+ </div>
+ </Flipbook>
+ <iframe v-if="menu.type == 3" class="view-iframe" :src="path"/>
+ </div>
+
+ <div v-if="menu.property == 3">
+ <img :src="menu.fileUrl[0].value"/>
+ </div>
+
</div>
</el-col>
@@ -74,59 +90,78 @@
import RightIcon from 'vue-material-design-icons/ChevronRightCircle'
import PlusIcon from 'vue-material-design-icons/PlusCircle'
import MinusIcon from 'vue-material-design-icons/MinusCircle'
+import io from "socket.io-client";
+import {getDetail} from "@/api/modules/modules";
+import {getAllEq} from "@/api/equipment/equipment";
export default {
name: "funcView",
components: {Flipbook, LeftIcon, RightIcon, PlusIcon, MinusIcon},
data() {
+ //设备编码校验
+ var equipmentList = []
+ getAllEq().then(res=>{
+ equipmentList = res.data.data
+ })
+ let validateEquipment = (rule, value, callback) => {
+ if (value) {
+ let filterArray = equipmentList.filter(e=>{
+ return e.code == value && e.type == 2
+ })
+ if (filterArray.length>0){
+ callback()
+ }else {
+ callback(new Error("请输入正确的显示器设备码"))
+ }
+ } else {
+ callback(new Error('请输入设备码'));
+ }
+ };
return {
form: {},
option: {
menuSpan: 6,
emptyBtn: false,
submitText: '连接',
+ submitBtn:false,
column: [
{
- label: "模块id",
+ label: "显示设备",
labelWidth: 15,
- prop: "modulesId",
+ prop: "equipmentCode",
type: "input",
span: 16,
labelslot: true,
rules: [{
required: true,
- message: "请输入模块id",
- trigger: "blur"
+ trigger: "blur",
+ validator:validateEquipment,
}],
},
]
},
defaultActive: "",
+ //菜单列表
menuList: [],
+ //iframe路径
path: "",
- imgPages: [],
- viewType: "",
-
+ //所选菜单
+ menu: "",
+ //图册翻页配置
flipConfig: {
pages: [],
pagesHiRes: [],
hasMouse: true,
pageNum: null,
- }
+ },
+ socketIoClient: null,
}
+ },
+ created() {
},
mounted() {
},
methods: {
- handleSubmit(form, done) {
- getAll(form).then(res => {
- if (res.data.code == 200) {
- let data = res.data.data
- this.menuList = data
- done()
- }
- })
- },
handleSelect(index) {
let selectData = this.menuList.filter(e => {
return e.id == index
@@ -135,31 +170,128 @@
},
//文件预览
viewFile(data) {
- this.viewType = data.type
+ this.menu = data
let url
- if (data.type == 2) {
- let fileArray = data.fileUrl
- fileArray.forEach(e => {
- this.flipConfig.pages.push(e.value)
- })
- } else if (data.type == 3) {
- url = data.fileUrl[0].value
- this.path = 'http://192.168.0.200:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(url))
- }else if (data.type == 1){
- url = data.fileUrl[0].value
- this.path = 'http://192.168.0.200:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(url))
+ if (data.property == 1) {
+
+ } else if (data.property == 2) {
+ if (data.type == 2) {
+ let fileArray = data.fileUrl
+ this.flipConfig.pages = []
+ if (fileArray.length>0 && fileArray){
+ fileArray.forEach(e => {
+ this.flipConfig.pages.push(e.value)
+ })
+ }
+ } else if (data.type == 3) {
+ if (data.fileUrl&&data.fileUrl.length>0){
+ url = data.fileUrl[0].value
+ this.path = 'http://192.168.0.200:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(url))
+ }
+ } else if (data.type == 1) {
+ if (data.fileUrl&&data.fileUrl.length>0){
+ url = data.fileUrl[0].value
+ this.path = 'http://192.168.0.200:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(url))
+ }
+ }
+ } else if (data.property == 3) {
+
}
+ },
+ connect(form,done) {
+
+ // if (this.socketIoClient !=null ){
+ // this.socketIoClient.disconnect()
+ // }
+
+ let serveUri = 'http://192.168.0.200:10246'
+ let params = {
+ current :form.equipmentCode
+ }
+ this.socketIoClient = io.connect(serveUri, {
+ 'force new connection': true,
+ 'query': 'connectInfo=' + JSON.stringify(params)
+ });
+ //监听与服务器的连接状态
+ this.socketIoClient.on("connect", () => {
+ done()
+ })
+ //监听服务器发回的消息
+ //连接成功
+ this.socketIoClient.on("connectOk", (res) => {
+ if (res.code == 200){
+ let params = {
+ equipmentCode :form.equipmentCode
+ }
+ getAll(params).then(res=>{
+ if (res.data.code == 200){
+ this.menuList = res.data.data
+ this.$notify.success({title:"连接成功"})
+ }
+ })
+ }
+ });
+
+ //连接失败
+ this.socketIoClient.on("connectError", (res) => {
+ this.$notify.error({
+ title: res.msg,
+ });
+ });
+
+ this.socketIoClient.on("menuChange", (res) => {
+ this.handleSelect(res)
+ });
+
+ //上一页
+ this.socketIoClient.on("previousPage", (res) => {
+ this.left()
+ });
+
+ //下一页
+ this.socketIoClient.on("nextPage", (res) => {
+ this.right()
+ });
},
+ disconnect() {
+ console.log(this.socketIoClient)
+ if (this.socketIoClient != null){
+ this.socketIoClient.disconnect()
+ this.menuList = []
+ if (this.socketIoClient.disconnected){
+ this.socketIoClient = null
+ this.$notify.success({title:"断开成功"})
+ }else {
+ this.$notify.error({title:"断开失败"})
+ }
+ }
+ },
+ left() {
+ this.$refs.flipbook.flipLeft()
+ },
+ right() {
+ this.$refs.flipbook.flipRight()
+ }
}
}
</script>
<style scoped>
-.show{
+.show {
background: #404040;
width: 100%;
height: 100vh;
+}
+
+.show > div {
+ width: 100%;
+ height: 100%;
+}
+
+img {
+ width: 100%;
+ height: 100%;
}
.el-select {
@@ -184,7 +316,7 @@
height: 100vh;
}
-.page-num{
+.page-num {
color: white;
}
--
Gitblit v1.9.3