فهرست منبع

增加485调试功能

wennn 3 سال پیش
والد
کامیت
f163f261d2
5فایلهای تغییر یافته به همراه258 افزوده شده و 3 حذف شده
  1. 4 2
      languages/zh-CN.js
  2. 8 0
      src/api/ncs_device.js
  3. 12 0
      src/router/index.js
  4. 0 1
      src/utils/request.js
  5. 234 0
      src/views/ncs-485/index.vue

+ 4 - 2
languages/zh-CN.js

@@ -1,4 +1,4 @@
-const i18n = require("@/utils/i18n");
+const i18n = require('@/utils/i18n')
 module.exports = {
   action: {
     home: '首页',
@@ -62,6 +62,7 @@ module.exports = {
     minute: '分钟',
     minute2: '分',
     second: '秒',
+    millisecond: '毫秒',
     oneSecond: '1秒内',
     Monday: '周一',
     Tuesday: '周二',
@@ -772,7 +773,8 @@ module.exports = {
     shopSetting: '系统设置',
     menuManage: '菜单管理',
     organization: '组织机构',
-    roleManage: '角色管理'
+    roleManage: '角色管理',
+    debugging485: '485调试'
   },
   deviceType: {
     NURSE_HOST: '护士主机',

+ 8 - 0
src/api/ncs_device.js

@@ -186,3 +186,11 @@ export function getManageHostDeviceByHospitalId(hospitalId) {
   })
 }
 
+export function get485DeviceAndFrame(partId, tid) {
+  return request({
+    url: `/ncs/device/get_485_device_and_frame/${partId}/${tid}`,
+    method: 'GET',
+    loading: false
+  })
+}
+

+ 12 - 0
src/router/index.js

@@ -628,6 +628,18 @@ export const adminRoutes = [
       }
     ]
   },
+  {
+    path: '/ncs-485',
+    component: Layout,
+    children: [
+      {
+        path: 'index',
+        component: () => import('@/views/ncs-485/index'),
+        name: 'rolemanager',
+        meta: { title: i18n.t('tab.debugging485'), icon: 'authen', noCache: true }
+      }
+    ]
+  },
 
   { path: '*', redirect: '/404', hidden: true }
 ]

+ 0 - 1
src/utils/request.js

@@ -163,7 +163,6 @@ const closeLoading = (target) => {
 }
 
 export default function request(options) {
-  console.log(options.url.toLocaleLowerCase())
   // 如果是请求【刷新token、登录、退出】不需要检查token,直接请求。
   if (/mgr\/refresh_token|mgr\/login|mgr\/logout|care/.test(options.url.toLocaleLowerCase())) {
     return service(options)

+ 234 - 0
src/views/ncs-485/index.vue

@@ -0,0 +1,234 @@
+<template>
+  <div class="container">
+    <div style="margin: 10px">
+      <el-select v-model="shopId" @change="changeShop" filterable>
+        <el-option v-for="(item, index) in partList" :key="index" :label="item.shop_name" :value="item.shop_id" />
+      </el-select>
+    </div>
+    <el-tabs v-if="zhhList.length > 0" v-model="activeName" type="card" @tab-click="handleClick">
+      <el-tab-pane name="id-0" label="无转换盒"></el-tab-pane>
+      <el-tab-pane v-for="(item, index) in zhhList" :key="index" :name="item.eth_mac+ '-' + item.id" :label="item.name"></el-tab-pane>
+    </el-tabs>
+    <div class="table-wrapper" style="padding-bottom: 10px;padding-left: 10px">
+      <div style="padding: 5px;">
+        <el-button v-if="tid !== '0'" :disabled="multipleSelection.length === 0" type="success" @click="sendAll">
+          批量发送
+        </el-button>
+      </div>
+      <el-table :data="deviceList" stripe border style="width: 100%" @selection-change="selectFun" height="520">
+        <el-table-column type="selection" width="55"></el-table-column>
+        <el-table-column prop="full_name" min-width="100" label="位置" align="center" />
+        <el-table-column prop="name" label="设备名" min-width="130" align="center" />
+        <el-table-column prop="sip_id" label="485地址" width="130" align="center" />
+<!--        <el-table-column prop="send_time" label="发送时间" min-width="130" align="center" />-->
+        <el-table-column prop="receive_time" label="流程耗时" width="130" align="center" />
+        <el-table-column prop="state" label="状态" width="140" align="center">
+          <template slot-scope="scope">
+            <el-tag v-if="scope.row.state === 0" type="warning" disable-transitions>等待发送</el-tag>
+            <el-tag v-if="scope.row.state === 1" type="primary" disable-transitions>发送成功等待返回</el-tag>
+            <el-tag v-if="scope.row.state === 2" type="success" disable-transitions>已返回完成流程</el-tag>
+            <el-tag v-if="scope.row.state === -1" type="danger" disable-transitions>发送失败</el-tag>
+            <el-tag v-if="scope.row.state === -2" type="danger" disable-transitions>返回超时</el-tag>
+          </template>
+        </el-table-column>
+        <el-table-column style="text-align: left;" label="操作" width="120" fixed="right">
+          <template slot-scope="scope">
+            <el-button v-if="tid !== '0'" type="success" size="mini" @click="handlerEdit(scope.$index, scope.row, 1)">
+              发送
+            </el-button>
+<!--            <el-button type="info" size="mini" @click="handlerEdit(scope.$index, scope.row, 2)">-->
+<!--              设置转换盒-->
+<!--            </el-button>-->
+          </template>
+        </el-table-column>
+      </el-table>
+    </div>
+    <div style="height: 500px;overflow:auto;margin: 10px;padding: 10px;" v-infinite-scroll>
+      <el-card class="box-card">
+        <div slot="header" class="clearfix">
+          <span>日志消息</span>
+          <el-button style="float: right; padding: 3px 0" type="text" @click="closeLog">清空日志</el-button>
+        </div>
+        <div>
+          <el-timeline :reverse="true">
+            <el-timeline-item
+                v-for="(activity, index) in activities"
+                :key="index"
+                :type="activity.type"
+                :icon="activity.icon"
+                :timestamp="unixDateFormatter(activity.timestamp)">
+              {{activity.content}}
+            </el-timeline-item>
+          </el-timeline>
+        </div>
+      </el-card>
+    </div>
+  </div>
+</template>
+
+<script>
+import { listByType } from '@/api/ncs_partInfo'
+import { get485DeviceAndFrame, getDeviceByType } from '@/api/ncs_device'
+import { unix2Date } from '@/utils/Foundation'
+const DeviceUrl = domain.DeviceUrl
+export default {
+  name: "index",
+  data() {
+    return {
+      partList: [],
+      zhhList: [],
+      shopId: null,
+      activeName: null,
+      deviceList: [],
+      tid: null,
+      activities: [],
+      multipleSelection: []
+    }
+  },
+  mounted() {
+    this.initWebSocket()
+    this.API_getPartList()
+  },
+  methods: {
+    initWebSocket: function() {
+      let stockbase = DeviceUrl.replace('http', 'ws')
+      this.websock = new WebSocket(stockbase + '/device485/listening/485Id')
+      this.websock.onopen = this.websocketonopen
+      this.websock.onerror = this.websocketonerror
+      this.websock.onmessage = this.websocketonmessage
+      this.websock.onclose = this.websocketclose
+    },
+    websocketonopen: function() {
+      console.log(this.$t('deviceManage.webSocketSuccess'))
+    },
+    websocketonerror: function(e) {
+      console.log(this.$t('deviceManage.webSocketError'))
+    },
+    websocketonmessage: function(e) {
+      // console.log('收到消息:', e)
+      const data = JSON.parse(e.data)
+      const index = this.deviceList.findIndex(p => p.sip_id.toLowerCase() === data.rs485mac.toLowerCase())
+      if (index === -1) {
+        return
+      }
+      const time = (new Date()).valueOf()
+      const item = this.deviceList[index]
+      let active = {
+        content: '设备:' + data.rs485mac  + '----' + data.rs485msg,
+        timestamp: time,
+        // type: 'primary'
+      }
+      if (data.type === 1) { // 发送
+        // this.$set(this.deviceList[index], 'send_time', time)
+        item.send_time = time
+        active.icon = 'el-icon-more'
+      } else if (data.type === 2) { // 有返回
+        item.receive_time = this.formateSeconds(item.send_time, time)
+        active.type = 'success'
+        active.icon = 'el-icon-check'
+      } else { // 发送失败
+        item.receive_time = this.formateSeconds(item.send_time, time)
+        active.type = 'danger'
+        active.icon = 'el-icon-close'
+      }
+
+      this.activities.push(active)
+      item.state = data.type
+      this.$set(this.deviceList, index, item)
+    },
+    websocketclose: function(e) {
+      console.log('connection closed (' + e.code + ')')
+      const _this = this
+      this.$alert('连接断开,是否重连', '提示', {
+        confirmButtonText: '确定',
+        callback: action => {
+          _this.initWebSocket()
+        }
+      })
+    },
+    API_getPartList() {
+      const _this = this
+      listByType(5).then(res => {
+        _this.partList = res
+        if (res.length > 0) {
+          _this.shopId = res[0].shop_id
+          _this.API_getZhhList()
+        }
+      })
+    },
+    API_getZhhList() {
+      const _this = this
+      this.deviceList = []
+      getDeviceByType(this.shopId, 20).then(res => {
+        _this.zhhList = res
+        if (res.length > 0) {
+          _this.activeName = 'id-0'
+          _this.tid =  '0'
+          _this.API_get485DeviceAndFrame()
+        }
+      })
+    },
+    API_get485DeviceAndFrame() {
+      const _this = this
+      get485DeviceAndFrame(this.shopId,  this.tid).then(res => {
+        _this.deviceList = res
+      })
+    },
+    changeShop() {
+      this.API_getZhhList()
+    },
+    handleClick() {
+      console.log(this.activeName)
+      this.tid = this.activeName.split('-')[1]
+      this.API_get485DeviceAndFrame()
+    },
+    handlerEdit(index, row, type) {
+      if (type === 1) {
+        row.state = 0
+        row.send_time = row.receive_time = ''
+        this.$set(this.deviceList, index, row)
+        this.websock.send(row.sip_id + '-' + this.activeName.split('-')[0])
+      }
+    },
+    unixDateFormatter(value) {
+      return unix2Date(value)
+    },
+    closeLog() {
+      this.activities = []
+    },
+    selectFun(val) {
+      this.multipleSelection = val
+    },
+    sendAll() {
+      let list = []
+      this.multipleSelection.forEach(item => {
+        const index = this.deviceList.indexOf(item)
+        item.state = 0
+        item.send_time = item.receive_time = ''
+        this.$set(this.deviceList, index, item)
+        list.push(item.sip_id + '-' + this.activeName.split('-')[0])
+      })
+      this.multipleSelection = []
+      this.websock.send(list.join(','))
+    },
+    //将秒转化为时分秒
+    formateSeconds(startTime, endTime){
+      if (!startTime) {
+        return 0
+      }
+      let secondTime = endTime - startTime//将传入的秒的值转化为Number
+      let min = 0// 初始化分
+      if(secondTime>1000){//如果秒数大于60,将秒数转换成整数
+        min=parseInt(secondTime/1000)//获取秒,除以1000取整数,得到整数秒
+        return min + this.$t('action.second')
+      } else {
+        return secondTime + this.$t('action.millisecond')
+      }
+    }
+  }
+}
+</script>
+
+<style scoped>
+
+</style>