OpcInfo.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. </div>
  100. </template>
  101. <script>
  102. import VueDragResize from 'vue-drag-resize'
  103. import { getSbPositionTree, fetchSbPosition, querySbPosition } from '@/api/sb/position'
  104. import {
  105. updateRemoteOpc,
  106. fetchRemoteOpc, queryRemoteOpc, queryRemoteOpcFromRedis
  107. } from '@/api/remote/opc'
  108. import Detail from '@/views/remote/opc/modules/Detail.vue'
  109. import DetailLog from '@/views/remote/opc-log/modules/Detail.vue'
  110. export default {
  111. name: 'Opc',
  112. components: {
  113. VueDragResize,
  114. Detail,
  115. DetailLog
  116. },
  117. data () {
  118. return {
  119. visibleRight: false,
  120. positionId: '',
  121. treeData: [],
  122. parentId: '',
  123. list: [],
  124. optDot: null,
  125. imgUrl: '',
  126. dotList: [],
  127. timer: null,
  128. columns: [
  129. {
  130. title: '位号',
  131. dataIndex: 'positionNum',
  132. key: 'positionNum'
  133. },
  134. {
  135. title: '操作',
  136. key: 'action',
  137. scopedSlots: { customRender: 'action' }
  138. }
  139. ]
  140. }
  141. },
  142. created () {
  143. this.parentId = this.$route.query.parentId
  144. this.positionId = this.$route.query.line
  145. this.getOpcInfo(this.positionId)
  146. querySbPosition({ parentId: this.parentId }).then(res => {
  147. this.list = res.data
  148. this.getOpcInfoFromRedis(this.positionId)
  149. })
  150. this.getImg()
  151. getSbPositionTree({ opcFlag: 1 }).then(res => {
  152. this.treeData = res.data
  153. })
  154. this.timer = setInterval(() => {
  155. this.getOpcInfoFromRedis(this.positionId)
  156. }, 5000)
  157. },
  158. destroyed () {
  159. clearInterval(this.timer)
  160. },
  161. methods: {
  162. resize (newRect) {
  163. console.log(newRect)
  164. const params = {
  165. ...this.dotList[this.optDot],
  166. height: newRect.height,
  167. width: newRect.width,
  168. xposition: newRect.left,
  169. yposition: newRect.top
  170. }
  171. updateRemoteOpc(params).then(res => {
  172. console.log(res)
  173. this.dotList[this.optDot].isActive = false
  174. })
  175. },
  176. onCloseRight () {
  177. this.visibleRight = false
  178. },
  179. disposition (val, i) {
  180. val.isActive = true
  181. val.positionFlag = 1
  182. this.optDot = i
  183. this.visibleRight = false
  184. },
  185. handleShow (val, key) {
  186. this.dotList[val].positionFlag = key
  187. },
  188. getOpcInfo (positionId) {
  189. this.positionId = positionId
  190. queryRemoteOpc({ line: this.positionId })
  191. .then((res) => {
  192. this.dotList = res.data
  193. this.dotList.forEach(item => {
  194. item.isActive = false
  195. if (item.result == null) {
  196. item.result = '-'
  197. }
  198. })
  199. })
  200. this.getImg()
  201. },
  202. getOpcInfoFromRedis (positionId) {
  203. this.positionId = positionId
  204. queryRemoteOpcFromRedis({ line: this.positionId })
  205. .then((res) => {
  206. this.dotList.forEach(item => {
  207. item.isActive = false
  208. res.data.forEach(data => {
  209. if (item.positionNum === data.positionNum) {
  210. item.result = data.result
  211. item.time = data.time
  212. }
  213. })
  214. })
  215. })
  216. this.getImg()
  217. },
  218. getImg () {
  219. fetchSbPosition({ id: this.positionId }).then(res => {
  220. this.imgUrl = res.data.opcImg
  221. })
  222. },
  223. handleChange () {
  224. this.getOpcInfo(this.positionId)
  225. this.getImg()
  226. },
  227. /*handleInfo (remoteOpc) {
  228. const model = this.$refs.detailLogModal
  229. model.base(null, { positionNum: remoteOpc.positionNum })
  230. },*/
  231. handleInfo (remoteOpc) {
  232. const model = this.$refs.detailLogModal
  233. model.base(remoteOpc)
  234. },
  235. handleView (record) {
  236. fetchRemoteOpc({ id: record.id }).then(res => {
  237. const modal = this.$refs.detailModal
  238. modal.base(res.data)
  239. })
  240. },
  241. handleOk () {
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="less" scoped>
  247. .main{
  248. position: relative;
  249. }
  250. .info{
  251. font-size: 14px;
  252. font-weight: bold;
  253. color: black;
  254. padding:0 2px;
  255. // transform: scale(0.5);
  256. }
  257. .icon{
  258. font-size: 30px;
  259. color: #fff;
  260. position: absolute;
  261. top:20px;
  262. }
  263. .btn{
  264. position: fixed;
  265. bottom: 10px;
  266. left:50%;
  267. transform: translateX(-50%);
  268. }
  269. </style>