hanbaoshan
2020-10-27 da98d2a8a686cde09b20345e4a2b55a85410fde4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<template>
  <div class="right-side">
    <div class="tool-bar">
      <div>
        <!-- <input type="color" ref="colorPicker" v-model="color"> -->
        <label for>拾色器:</label>
        <el-color-picker v-model="colorPick" show-alpha size="mini"></el-color-picker>
      </div>
      <div style="width:250px;">
        <label for>笔触:</label>
        <el-slider v-model="dotSize" :min="1" :max="20"></el-slider>
      </div>
    </div>
    <div class="action-bar">
      <el-button class="drawboard-trigger" size="small" @click="isEdit=!isEdit" :icon="isEdit?'el-icon-lock':'el-icon-edit'">{{isEdit?'锁定':'编辑'}}</el-button>
    </div>
    <div class="drawboard">
      <div class="mask" :class="{'edit-status-mask':isEdit}" ref="editBoard" >
        <div class="label" @click="editLabel(item)" v-for="(item,index) in labels" :key="index" :style="{left:`${item.x}px`, top:`${item.y}px`, backgroundColor: colorPick, width: `${dotSize}px`, height: `${dotSize}px` }"></div>
      </div>
      <img :src="`/httpImage/${snapshot_url}`" alt />
      <div class="popBox" v-show="isShowPop" :style="`top:${curLabel.y + 22}px;left:${curLabel.x}px`">
        <div class="title">标注信息</div>
        <div class="details">
          <div class="detail-item">
            <div class="left">
              <label for="">平面坐标X:</label>
              <span class="fix-width">{{curLabel.x}}</span>
              <i>px</i>
            </div>
            <span class="devide"></span>
            <div class="right">
              <label for="">实际坐标X:</label>
              <el-input type="text" size="mini" style="width:90px" v-model="curLabel.posX"></el-input>
            </div>
          </div>
          <div class="detail-item">
            <div class="left">
              <label for="">平面坐标Y:</label>
              <span class="fix-width">{{curLabel.y}}</span>
              <i>px</i>
            </div>
            <span class="devide"></span>
            <div class="right">
              <label for="">实际坐标Y:</label>
              <el-input type="text" size="mini" style="width:90px" v-model="curLabel.posY"></el-input>
            </div>
          </div>
          <div class="btns">
            <el-button size="mini" type="danger" @click="deleteLabel">删除</el-button>
            <el-button size="mini" type="primary" @click="cancle">取消</el-button>
            <el-button size="mini" type="success" @click="submitInfo">确定</el-button>
          </div>
        </div>
      </div>
    </div>
    
  </div>
</template>
 
<script>
import { getCamerasByServer } from '@/api/pollConfig'
import TreeDataPool from "@/Pool/TreeData";
export default {
  data () {
    return {
      labels: [],
      colorPick: '#79f2fb',
      dotSize: 3,
      isEdit: false,
      isShowPop: false,
      isNewLabel: false,
      curLabel: {
        id:'',
        posX:'',
        posY:'',
        x:'',
        y:''
      },
      baseUrl: '',
      snapshot_url: '',
      cameraData:[],
    }
  },
  computed: {
    
  },
  mounted(){
    this.getAllCameraData();
    setTimeout(()=>{
      let mockData = [{id:'a1',x:15, y:33, posX:150, posY:330},{id:'b2',x:56, y:87, posX:560, posY:870}];
      this.labels = mockData;
    },1000);
  },
  watch:{
    'TreeDataPool.selectedNode':{
      handler(n,o){
        debugger
        let curCamera = this.cameraData.find(item => item.id==n.id);
        this.snapshot_url = curCamera.snapshot_url;
      },
      deep: true
    },
    isEdit(n,o){
      if(n){
        this.$refs['editBoard'].addEventListener('click',this.bindListen);
      }else{
        this.$refs['editBoard'].removeEventListener('click',this.bindListen);
      }
    }
  },
  methods: {
    getAllCameraData(){
      getCamerasByServer().then(res=>{
        if(res.success){
          debugger
          this.cameraData = res.data;
        }
      }).catch(e=>{
        console.log(e)
      })
    },
    bindListen(e){
      this.newLabel(e);
    },
    newLabel(e){
      console.log('点击了画板')
      if(this.isShowPop) return;
      //获取鼠标相对于画板的定位
      console.log('获取当前定位信息');
      let target = {
        id:'',
        x:e.offsetX,
        y:e.offsetY,
        posX:'',
        posY:''
      };
      this.labels.push(target);
      this.curLabel = target;
      this.isShowPop = true;
      this.isNewLabel = true;
    },
    editLabel(label){
      debugger
      if(!this.isEdit) return;
      this.isShowPop = true;
      this.curLabel = JSON.parse(JSON.stringify(label));
    },
    cancle(){
      this.isShowPop = false;
      //如果是未保存过的label直接删除(未保存的就是labels数组中最后一个)
      if(!this.curLabel.id){
        this.labels.pop();
      }
    },
    deleteLabel(){
      if(this.curLabel.id){
        //请求后台删除
      }else{
        this.labels.pop();
        this.isShowPop = false;
      }
    },
    submitInfo(){
 
    }
  }
}
</script>
 
<style lang="scss">
.right-side {
  height: 100%;
  background: #d2dcea;
  .tool-bar {
    width: 100%;
    height: 60px;
    padding: 10px 20px;
    box-sizing: border-box;
    background: rgb(250, 250, 250);
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    > div {
      cursor: pointer;
      background: rgb(245, 245, 245);
      padding: 0 5px;
      height: 40px;
      margin: 7px;
      display: flex;
      align-items: center;
      label {
        margin-right: 10px;
        color: rgb(161, 161, 161);
      }
      .el-slider {
        width: 110px;
      }
    }
  }
  .action-bar{
    width: 960px;
    margin: auto;
    margin-bottom: 20px;
    text-align: right;
    .drawboard-trigger{
      background: transparent;
      color: #fff;
      border-color: rgba(255,255,255,.3);
    }
  }
  .drawboard {
    margin: auto;
    width: 960px;
    height: 540px;
    position: relative;
    background: #fff;
    box-shadow: 3px 3px 3px 1px rgba(0, 0, 0, 0.1);
    .mask{
      position: absolute;
      background: transparent;
      width: 100%;
      height: 100%;
      overflow: hidden;
      &.edit-status-mask{
        background: rgba(20, 181, 255, 0.1);
      }
      .label{
        position: absolute;
        z-index: 2;
        border-radius: 50%;
      }
    }
    img{
      width: 960px;
      height: 540px;
      background:#f0ffca;
    }
    .popBox{
      position: absolute;
      padding: 14px;
      border-radius: 3px;
      color: #fff;
      background: rgba(0,0,0,.7);
      .title{
        font-weight: bold;
        text-align: left;
        font-size: 15px;
      }
      .details{
        .detail-item{
          display: flex;
          align-items: center;
          margin: 5px 0;
          label{
            color: #a9a9a9;
            width:65px;
            display: inline-block;
          }
          .left{
            width: 110px;
            text-align: left;
            line-height: 28px;
            .fix-width{
              display: inline-block;
              width: 23px;
            }
          }
          .right{
            width: 160px;
          }
          .devide{
            width: 10px;
            height: 1px;
            background: #a9a9a9;
            margin: 0 3px;
          }
        }
        .btns{
          margin-top: 10px;          
        }
      }
    }
  }
}
</style>