OpcInfo.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="main">
  3. <img :src="imgUrl" width="1920px" alt="">
  4. <!-- <div class="icon" style="right:20px">
  5. <a-button type="primary" icon="appstore" size="large" @click="visibleRight=true" />
  6. </div>-->
  7. <div v-if="dotList !=null && dotList.length>0">
  8. <div v-for="item in dotList" :key="item.id">
  9. <VueDragResize
  10. v-show="item.positionFlag"
  11. :isActive="item.isActive"
  12. :w="item.width"
  13. :h="item.height"
  14. :minh="20"
  15. :x="item.xposition"
  16. :y="item.yposition"
  17. :isDraggable="item.isActive"
  18. :isResizable="item.isActive"
  19. :stickSize="5"
  20. >
  21. <a-tooltip>
  22. <template slot="title">
  23. {{ item.description + '(' + item.time + ')' }}
  24. </template>
  25. <!-- <div class="info" @click="handleInfo(item)" @click.right.prevent="handleView(item)">-->
  26. <div class="info" @click="handleInfo(item)">
  27. <span :style="{'color':item.warnFirstColor}" v-if="(+item.result)<=item.warnFirst&&item.warnFirst!==null">{{ item.result }}</span>
  28. <span :style="{'color':item.warnSecondColor}" v-else-if="item.warnFirst<(+item.result)&&(+item.result)<item.warnSecond">{{ item.result }}</span>
  29. <span :style="{'color':item.warnThirdColor}" v-else-if="item.warnThird<(+item.result)&&(+item.result)<item.warnFour">{{ item.result }}</span>
  30. <span :style="{'color':item.warnFourColor}" v-else-if="(+item.result)>=item.warnFour&&item.warnFirst!==null">{{ item.result }}</span>
  31. <span v-else>{{ item.result==null?'-':item.result }}</span>
  32. </div>
  33. </a-tooltip>
  34. </VueDragResize>
  35. <VueDragResize
  36. v-if="item.type===2"
  37. v-show="item.result===0||item.result===null"
  38. :isActive="item.isActive"
  39. :w="35"
  40. :h="35"
  41. :minh="20"
  42. :x="item.imgXPosition"
  43. :y="item.imgYPosition"
  44. :isDraggable="item.isActive"
  45. :isResizable="item.isActive"
  46. :stickSize="5"
  47. >
  48. <a-tooltip>
  49. <template slot="title">
  50. {{ item.description }}
  51. </template>
  52. <img src="@/assets/stop.png" alt="" width="35px" height="35px">
  53. </a-tooltip>
  54. </VueDragResize>
  55. </div>
  56. </div>
  57. <!-- <a-drawer
  58. title="点位列表"
  59. placement="right"
  60. :closable="false"
  61. :width="350"
  62. :visible="visibleRight"
  63. @close="onCloseRight"
  64. >
  65. <div>
  66. <a-tree-select
  67. style="width: 60%;margin-right:10px;"
  68. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  69. :treeData="treeData"
  70. :treeNodeFilterProp="'title'"
  71. :showSearch="true"
  72. v-model="positionId"
  73. placeholder="请选择"
  74. @change="handleChange"
  75. >
  76. </a-tree-select>
  77. </div>
  78. <br>
  79. <a-table
  80. :columns="columns"
  81. :data-source="dotList"
  82. :pagination="{ pageSize: 100 }"
  83. :scroll="{ y: 650 }"
  84. >
  85. <span slot="action" slot-scope="text, record,index">
  86. <a @click="disposition(record,index)">配置</a>
  87. <a-button style="color:#ccc" v-show="record.positionFlag" type="link" icon="eye-invisible" @click="handleShow(index,0)" />
  88. <a-button v-show="!record.positionFlag" type="link" icon="eye" @click="handleShow(index,1)" />
  89. </span>
  90. </a-table>
  91. </a-drawer> -->
  92. <div class="btn">
  93. <a-button-group>
  94. <a-button v-for="item in list" :key="item.id" :disabled="positionId===item.id" @click="getOpcInfo(item.id)">{{ item.name }}</a-button>
  95. </a-button-group>
  96. </div>
  97. <detail ref="detailModal" @ok="handleOk" />
  98. <detail-log ref="detailLogModal" @ok="handleOk" />
  99. <remote-opc-warn></remote-opc-warn>
  100. </div>
  101. </template>
  102. <script>
  103. import VueDragResize from 'vue-drag-resize'
  104. import { getSbPositionTree, fetchSbPosition, querySbPosition } from '@/api/sb/position'
  105. import {
  106. updateRemoteOpc,
  107. fetchRemoteOpc, queryRemoteOpc, queryRemoteOpcFromRedis
  108. } from '@/api/remote/opc'
  109. import Detail from '@/views/remote/opc/modules/Detail.vue'
  110. import DetailLog from '@/views/remote/opc-log/modules/Detail.vue'
  111. import RemoteOpcWarn from '@/views/socket/RemoteOpcWarn'
  112. import RemoteOpcList from '@/views/remote/opc/RemoteOpc'
  113. export default {
  114. name: 'Opc',
  115. components: {
  116. RemoteOpcList,
  117. VueDragResize,
  118. RemoteOpcWarn,
  119. Detail,
  120. DetailLog
  121. },
  122. data () {
  123. return {
  124. visibleRight: false,
  125. positionId: '',
  126. treeData: [],
  127. parentId: '',
  128. list: [],
  129. optDot: null,
  130. imgUrl: '',
  131. dotList: [],
  132. timer: null,
  133. columns: [
  134. {
  135. title: '位号',
  136. dataIndex: 'positionNum',
  137. key: 'positionNum'
  138. },
  139. {
  140. title: '操作',
  141. key: 'action',
  142. scopedSlots: { customRender: 'action' }
  143. }
  144. ]
  145. }
  146. },
  147. created () {
  148. this.parentId = this.$route.query.parentId
  149. this.positionId = this.$route.query.line
  150. this.getOpcInfo(this.positionId)
  151. querySbPosition({ parentId: this.parentId }).then(res => {
  152. this.list = res.data
  153. this.getOpcInfoFromRedis(this.positionId)
  154. })
  155. this.getImg()
  156. getSbPositionTree({ opcFlag: 1 }).then(res => {
  157. this.treeData = res.data
  158. })
  159. this.timer = setInterval(() => {
  160. this.getOpcInfoFromRedis(this.positionId)
  161. }, 5000)
  162. },
  163. destroyed () {
  164. clearInterval(this.timer)
  165. },
  166. methods: {
  167. resize (newRect) {
  168. console.log(newRect)
  169. const params = {
  170. ...this.dotList[this.optDot],
  171. height: newRect.height,
  172. width: newRect.width,
  173. xposition: newRect.left,
  174. yposition: newRect.top
  175. }
  176. updateRemoteOpc(params).then(res => {
  177. console.log(res)
  178. this.dotList[this.optDot].isActive = false
  179. })
  180. },
  181. onCloseRight () {
  182. this.visibleRight = false
  183. },
  184. disposition (val, i) {
  185. val.isActive = true
  186. val.positionFlag = 1
  187. this.optDot = i
  188. this.visibleRight = false
  189. },
  190. handleShow (val, key) {
  191. this.dotList[val].positionFlag = key
  192. },
  193. getOpcInfo (positionId) {
  194. this.positionId = positionId
  195. queryRemoteOpc({ line: this.positionId })
  196. .then((res) => {
  197. this.dotList = res.data
  198. this.dotList.forEach(item => {
  199. item.isActive = false
  200. if (item.result == null) {
  201. item.result = '-'
  202. }
  203. })
  204. })
  205. this.getImg()
  206. },
  207. getOpcInfoFromRedis (positionId) {
  208. this.positionId = positionId
  209. queryRemoteOpcFromRedis({ line: this.positionId })
  210. .then((res) => {
  211. this.dotList.forEach(item => {
  212. item.isActive = false
  213. res.data.forEach(data => {
  214. if (item.positionNum === data.positionNum) {
  215. item.result = data.result
  216. item.time = data.time
  217. }
  218. })
  219. })
  220. })
  221. this.getImg()
  222. },
  223. getImg () {
  224. fetchSbPosition({ id: this.positionId }).then(res => {
  225. this.imgUrl = res.data.opcImg
  226. })
  227. },
  228. handleChange () {
  229. this.getOpcInfo(this.positionId)
  230. this.getImg()
  231. },
  232. /* handleInfo (remoteOpc) {
  233. const model = this.$refs.detailLogModal
  234. model.base(null, { positionNum: remoteOpc.positionNum })
  235. }, */
  236. handleInfo (remoteOpc) {
  237. const model = this.$refs.detailLogModal
  238. model.base(remoteOpc)
  239. },
  240. handleView (record) {
  241. fetchRemoteOpc({ id: record.id }).then(res => {
  242. const modal = this.$refs.detailModal
  243. modal.base(res.data)
  244. })
  245. },
  246. handleOk () {
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="less" scoped>
  252. .main{
  253. position: relative;
  254. }
  255. .info{
  256. font-size: 14px;
  257. font-weight: bold;
  258. color: black;
  259. padding:0 2px;
  260. // transform: scale(0.5);
  261. }
  262. .icon{
  263. font-size: 30px;
  264. color: #fff;
  265. position: absolute;
  266. top:20px;
  267. }
  268. .btn{
  269. position: fixed;
  270. bottom: 10px;
  271. left:50%;
  272. transform: translateX(-50%);
  273. }
  274. </style>