Opc.vue 7.2 KB

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