| | |
| | | <!-- |
| | | * @Date: 2024-01-05 23:47:53 |
| | | * @LastEditors: Sneed |
| | | * @LastEditTime: 2024-01-16 22:37:15 |
| | | * @LastEditTime: 2024-01-20 17:05:37 |
| | | * @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/container/mapPreview/Map.vue |
| | | --> |
| | | <template> |
| | |
| | | :rowspan="v.rowspan" :colspan="v.colspan" :key="v.rowIndex + '-' + v.colIndex"> |
| | | <img @click="addDevice($event,v)" @mousedown="e => e.stopPropagation()" v-if="v.type ===2 && status!==2 && !v.id" src="./img/+.png" alt=""> |
| | | <!-- <Device v-if="v.id" :id="v.id" style="width: 100%;height: 100%;"></Device> --> |
| | | <Device v-if="v.id" :id="v.id" style="width: 100%;height: 100%;" :deviceList="deviceList" |
| | | <Device @click.native="toDetail(v)" v-if="v.id" :id="v.id" style="width: 100%;height: 100%;" :deviceList="deviceList" |
| | | :plantDeviceList="plantDeviceList" ::info="info"></Device> |
| | | </td> |
| | | </tr> |
| | |
| | | } |
| | | } |
| | | import mixins from '@/mixins/index' |
| | | import AddMachine from './addMachine.vue' |
| | | import Device from '../workshop/device.vue' |
| | | import {mapGetters} from 'vuex' |
| | | export default { |
| | | mixins: [mixins], |
| | | components: { |
| | | AddMachine, |
| | | Device |
| | | }, |
| | | props: { |
| | |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.$el.querySelector('table').addEventListener('contextmenu', this.contextmenu) |
| | | this.$el.addEventListener('mouseup',e => { |
| | | if(this.status ===2) return |
| | | this.tdMounseDown = false |
| | | }) |
| | | try { |
| | | this.height = (document.querySelector('.table').getBoundingClientRect().height - 30) / 20 |
| | | } catch (error) { |
| | | } |
| | | console.log(this.$route.name) |
| | | }, |
| | | beforeUpdate() { |
| | | try { |
| | | this.$el.querySelector('table').removeEventListener('contextmenu', this.contextmenu) |
| | | } catch (error) { |
| | | |
| | | } |
| | | |
| | | }, |
| | | updated() { |
| | | try { |
| | | this.$el.querySelector('table').addEventListener('contextmenu', this.contextmenu) |
| | | } catch (error) { |
| | | |
| | | } |
| | | }, |
| | | methods: { |
| | | createMap() { |
| | | let data = [] |
| | | for (var i = 0; i < this.rows; i++) { |
| | | let arr = [] |
| | | for (var j = 0; j < this.cols; j++) { |
| | | arr.push({ |
| | | rowspan: 1, |
| | | colspan: 1, |
| | | rowIndex: i, |
| | | colIndex: j, |
| | | type: '' |
| | | }) |
| | | toDetail (v) { |
| | | alert(1) |
| | | this.$router.push({ |
| | | name: 'mapPreviewDetail', |
| | | query: { |
| | | id: v.id |
| | | } |
| | | data.push(arr) |
| | | } |
| | | this.map = data |
| | | }, |
| | | contextmenu(e) { |
| | | console.log(e) |
| | | if(this.status ===2) return |
| | | if (!this.range.x) return |
| | | // if (this.range.x !=='') return |
| | | e.preventDefault() |
| | | e.stopPropagation() |
| | | let { pageX: left, pageY: top } = e |
| | | this.showAction = true |
| | | let { top: t } = document.querySelector('.table').getBoundingClientRect() |
| | | if (window.innerWidth - left < 100) { |
| | | this.position = { |
| | | right: 0, |
| | | top: top + 10 + 'px' |
| | | } |
| | | } else { |
| | | this.position = { |
| | | left: left + 'px', |
| | | top: top + 10 + 'px' |
| | | } |
| | | } |
| | | |
| | | }, |
| | | onMousedown(e, v) { |
| | | if(this.status ===2) return |
| | | if (e.button !== 0) return |
| | | this.tdMounseDown = true |
| | | this.showAction = false |
| | | this.selection = [v] |
| | | }, |
| | | onMouseMove(e,v) { |
| | | if(this.status ===2) return |
| | | if(!this.tdMounseDown) return |
| | | this.$set(this.selection,1,v) |
| | | }, |
| | | merge(e) { |
| | | const { x, x1, y, y1 } = this.range |
| | | for (var i = x; i <= x1; i++) { |
| | | for (var j = y; j <= y1; j++) { |
| | | if (i == x && j == y) { |
| | | let arr = [...(this.map[i])] |
| | | arr[j].rowspan = x1 - x + 1 |
| | | arr[j].colspan = y1 - y + 1 |
| | | this.$set(this.map,i,arr) |
| | | } else { |
| | | let arr = [...(this.map[i])] |
| | | arr[j].rowspan = 0 |
| | | arr[j].colspan = 0 |
| | | arr[j].parent = [x, y] |
| | | this.$set(this.map,i,arr) |
| | | } |
| | | } |
| | | } |
| | | this.$set(this.range,'x',this.range.x) |
| | | this.$set(this.range,'x1',this.range.x) |
| | | this.$set(this.range,'y',this.range.y) |
| | | this.$set(this.range,'y1',this.range.y) |
| | | this.showAction = false |
| | | }, |
| | | split () { |
| | | const { x, x1, y, y1 } = this.range |
| | | for(var i=x;i<=x1;i++) { |
| | | for(var j=y;j<=y1;j++) { |
| | | if (i==x && j==y) { |
| | | let arr = [...(this.map[i])] |
| | | arr[j].rowspan = 1 |
| | | arr[j].colspan = 1 |
| | | this.$set(this.map,i,arr) |
| | | } else { |
| | | let arr = [...(this.map[i])] |
| | | arr[j].rowspan = 1 |
| | | arr[j].colspan = 1 |
| | | arr[j].parent = '' |
| | | this.$set(this.map,i,arr) |
| | | } |
| | | } |
| | | } |
| | | this.showAction = false |
| | | // setData(layoutNew) |
| | | // setRange({x,y,x1:x,y1: y}) |
| | | // setShowMenu(false) |
| | | }, |
| | | sign (type) { |
| | | const { x, x1, y, y1 } = this.range |
| | | for(var i=x;i<=x1;i++) { |
| | | for(var j=y;j<=y1;j++) { |
| | | let arr = [...(this.map[i])] |
| | | arr[j].type = type |
| | | this.$set(this.map,i,arr) |
| | | } |
| | | } |
| | | this.showAction = false |
| | | this.$forceUpdate() |
| | | }, |
| | | addDevice (e,v) { |
| | | if(this.status ===2) return |
| | | e.stopPropagation() |
| | | this.addStatus = true |
| | | this.currentAdd = v |
| | | }, |
| | | save () { |
| | | if (this.status === 0) { |
| | | this.$http.postJson('/plant/save',{ |
| | | name: this.plantName, |
| | | gridSetting: JSON.stringify(this.map) |
| | | }).then(res => { |
| | | this.$emit('out') |
| | | console.log(res) |
| | | }) |
| | | } else if(this.status === 1) { |
| | | this.$http.postJson('/plant/modify',{ |
| | | name: this.plantName, |
| | | gridSetting: JSON.stringify(this.map), |
| | | id: this.id |
| | | }).then(res => { |
| | | this.$emit('out') |
| | | console.log(res) |
| | | }) |
| | | } |
| | | |
| | | }) |
| | | }, |
| | | out () { |
| | | this.$emit('out') |
| | | }, |
| | | close () { |
| | | this.addStatus = false |
| | | }, |
| | | edit (e) { |
| | | if(this.status ===2) return |
| | | e.stopPropagation() |
| | | this.addStatus = true |
| | | }, |
| | | setmachineId (id) { |
| | | console.log(id) |
| | | if (!id) return |
| | | let i = this.currentAdd.rowIndex |
| | | let j = this.currentAdd.colIndex |
| | | let arr = [...(this.map[i])]; |
| | | arr[j].id = id |
| | | this.$set(this.map,i,arr) |
| | | this.close() |
| | | } |
| | | }, |
| | | } |