bindDev.vue 4.42 KB
<template>
    <el-dialog :title="$t('button.positionCalibration')" width="80%" class="manage-dialog" v-if="bindVisible" :visible.sync="bindVisible" :close-on-click-modal="false" @close="closeBindDialog">
        <div class="draw_desks">
            <div class="gateWrap" id="gateManageChannel">
                <img :src="floorImg" class="fimg" @load="loadGateData">
                <div class="grender" ref="gRender"></div>
            </div>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" class="dialog-btn dialog-confirm-btn" @click="bindVisible = false">
                {{$t('button.closed')}}
            </el-button>
        </div>
    </el-dialog>
</template>

<script>
    import drawUtils from './drawUtils';
    import _ from 'underscore';
    export default {
        extends:drawUtils, 
        data() {
            return {
                bindVisible: false,
                floorImg: '',
                width:0,
                height:0,
                groupList:[],
                // zr:'',
                areaId:'',
                areaObj:{}
            }
        },
        methods: {
            dialogInit(row) {
                this.areaObj = {...row}
                this.areaId = row.id
                this.floorImg = window._vionConfig.picUrl+row.pic
                this.bindVisible = true;
            },
            loadGateData() {
                let {width,height} = document.getElementById('gateManageChannel').getBoundingClientRect();
                this.width = width;
                this.height = height;
                this.groupList = [];
                this.zr = zrender.init(this.$refs.gRender, {
                    renderer: 'canvas',
                    devicePixelRatio: 2,
                    width: width,
                    height: height
                });
                window.zr = this.zr;
                this.$api.queueManagementApi.getDevices({
                    areaId: this.areaId
                }).then(res=>{
                    let data = res.data.data
                    data.forEach(item=>{
                        item.name = this.areaObj.name;
                        // item.id = this.areaObj.id;
                        item.id = item.serialnum;
                        item.picUrl = window._vionConfig.picUrl + "/snapshot/real/" + item.serialnum + "-01.jpg?t=" + Date.parse(new Date()) / 1000;
                        item.coordinate&&(item.coordinate=JSON.parse(item.coordinate))
                    })
                    this.gateList =data;
                    this.drawJoinMap()
                });
            },
            drawJoinMap(){
                let that = this;
                console.log(this.gateList)
                _.each(this.gateList,(item,index)=>{
                    if(item.picUrl){
                      let img = new Image();
                      img.src = item.picUrl;
                      img.onload = function(){
                          item.width = this.width;
                          item.height = this.height;
                          that.createGroup(item,index+1);
                      }
                    }
                })
            },
            createGroup(data,index){
                let left = 0;
                let top = 0;
                let that = this;
                let group = new zrender.Group({
                  z:1,
                  draggable:true,
                  gateId:data.id,
                  gateName:data.name,
                  picUrl:data.picUrl,
                  position:[left,top]
                }).on('mouseup', function (evt) {
                    that.saveGateData(data.id);
                })
                this.groupList.push(group);
                this.zr.add(group);
                window.group = group;
                this.drawPolyImage(data,group);  
            },
            closeBindDialog() {
                this.bindVisible = false
            },
        }
    }
</script>
<style lang="less" scoped="scoped">
    .draw_desks {
        position: relative;
        width: 100%;
        height: 700px;
    }
    .gateWrap{
        position: relative;
        width: 100%;
        box-shadow: 0px 3px 12px 0px rgba(196, 200, 207, 0.8);
    }
    .gateWrap .fimg{
        display: block;
        width: 100%;
    }
    .gateWrap .grender{
       position: absolute;
       left: 0;
       top: 0;
       width:100%;
       height: 100%;
       opacity: 0.7;
    }
</style>