zhangzengfei
2020-08-03 1a94e4c4d56cdb04da7bab981d9389f87daa0683
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<template>
  <div class="s-upload-img">
    <div class="upload-area">
      <h2 class="title">
        数据源
        <i
          class="iconfont iconchushaixuanxiang close"
          style="margin-left:200px;cursor:pointer;color:#ccc"
          @click="VideoPhotoData.uploadDiaplay = false"
        ></i>
      </h2>
      <p class="compearValue">
        <span
          style="font-family: PingFangSC-Regular;font-size: 13px;color: #333333;letter-spacing: 0.28px;margin-right:10px"
        >对比阈值</span>
        <el-input-number
          size="mini"
          v-model="VideoPhotoData.threshold"
          controls-position="right"
          :min="1"
          :max="100"
        ></el-input-number>
      </p>
      <div class="upload-img-box">
        <img :src="'/httpImage/'+tempUploadImg" alt="临时测试" v-show="!displayUpload" class="bigPhoto" />
        <el-upload
          ref="upload"
          :list-type="'picture-card'"
          action
          :http-request="uploadImg"
          v-show="displayUpload"
          accept="image/*"
          :limit="1"
          :on-remove="removeImg"
          :on-success="uploadSuccess"
          :on-error="uploadError"
          :before-upload="beforeUpload"
        >
          <i
            ref="uploadIcon"
            class="el-icon-upload"
            style="color:#3D68E1;font-size:60px;position:relative;left:50px"
          ></i>
          <span
            class="el-upload__text"
            style="font-size:12px;color:#3D68E1;position:relative;top:25px;left:-30px"
          >
            <em>点击选择上传图片</em>
          </span>
          <!-- <i class="el-icon-upload" style="color:#3D68E1"></i>
          <div class="el-upload__text" style="font-size:12px;color:#3D68E1">将文件拖到此处,或<em>点击上传</em></div>-->
        </el-upload>
        <!-- <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt />
        </el-dialog>-->
      </div>
      <div class="res-img-box" v-if="resReady" :style="oneLine? 'height:95px':'height:185px'">
        <div class="single-box fl" v-for="(item, index) in realSmallPath" :key="index">
          <img
            :src="item
              ? '/httpImage/'+item
              : tempImg
          "
            @click="selected($event,index)"
            style="max-height:100%"
            :style="index == clickNum ? 'border:1px solid #FF7733':''"
          />
          <img class="select" v-show="index == clickNum" :src="selectedIcon" alt />
        </div>
        <div class="single-box fl" v-for="(item, index) in unrealSmallPath" :key="index+'t'">
          <img :src="item
                ? item
                : tempImg
            " />
        </div>
      </div>
      <el-select
        v-if="resReady"
        v-model="compareTabs"
        multiple
        collapse-tags
        @change="selectChange"
        style="margin: 15px 0;width: 100%"
        placeholder="请选择"
      >
        <el-option
          v-for="item in VideoPhotoData.tabsForUploadImg"
          :key="item.key+'p'"
          :label="item.title"
          :disabled="item.disabled"
          :value="item.key"
        ></el-option>
      </el-select>
      <el-button-group v-if="resReady" style="margin-top:10px;">
        <el-button type="info" size="small" @click="reUpload">重新上传</el-button>
        <el-button type="primary" size="small" style="margin-left:10px" @click="searchStart">开始检索</el-button>
      </el-button-group>
    </div>
  </div>
</template>
 
<script>
import Card from "../subComponents/Card";
import request from "@/scripts/httpRequest"
export default {
  watch: {
    "VideoPhotoData.tabsForUploadImg": function (value) {
      this.selectChange()
    },
    "VideoPhotoData.uploadImg": {
      handler(val) {
        // console.log('val:::', val)
        if (val !== "") {
          this.tempUploadImg = val
          this.realSmallPath = [val]
          this.unrealSmallPath = [this.tempImg, this.tempImg]
          this.resReady = true
          this.displayUpload = false
        }
      },
      immediate: true,
      deep: true
    }
  },
  computed: {
    getResImg() {
      let arr = this.realSmallPath;
      // let str =
      //   "http://hbimg.b0.upaiyun.com/56ce44d4d6746ef6c88de4d241f76713fc67cf13b05b-ejL0af_fw658";
      // let time = parseInt(Math.random() * 10);
      // for (let i = 0; i < time; i++) {
      //   arr.push(str);
      // }
      if (arr.length <= 3) {
        arr.length = 3;
      } else if (arr.length <= 6) {
        arr.length = 6;
      } else if (arr.length <= 9) {
        arr.length = 9;
      }
      return arr;
    }
  },
  data() {
    return {
      tempUploadImg: "",
      tempImg: "/images/search/nobody.png",
      selectedIcon: "/images/search/duihao.png",
      bigPhoto: [],
      displayUpload: true,
      clickNum: 0,
      picQuality: 60,
      dialogImageUrl: "",
      dialogVisible: false,
      resReady: false,
      rightSectionDisplay: true,
      value: "",
      compareTabs: ["esData"],
      realSmallPath: [],
      unrealSmallPath: [],
      oneLine: true,
      multiSelect: false
    };
  },
  mounted() {
    this.selectChange()
    this.$nextTick(() => {
      let scrollContain = this.$refs.rightSection
      console.log("赋值容器:", scrollContain)
      this.VideoPhotoData.scrollContainDom = scrollContain
    })
  },
  methods: {
    selectChange() {
      if (!this.compareTabs.includes("esData") && this.compareTabs.length > 0) {
        for (let i = 0; i < this.VideoPhotoData.tabsForUploadImg.length; i++) {
          if (this.VideoPhotoData.tabsForUploadImg[i].title === "抓拍库") {
            this.VideoPhotoData.tabsForUploadImg[i].disabled = true;
          }
        }
        this.$emit('labelDisabled', true)
        return;
      }
      if (this.compareTabs.includes("esData")) {
        for (let i = 0; i < this.VideoPhotoData.tabsForUploadImg.length; i++) {
          if (this.VideoPhotoData.tabsForUploadImg[i].title !== "抓拍库") {
            this.VideoPhotoData.tabsForUploadImg[i].disabled = true;
          }
        }
        this.$emit('labelDisabled', false)
      } else {
        for (let i = 0; i < this.VideoPhotoData.tabsForUploadImg.length; i++) {
          this.VideoPhotoData.tabsForUploadImg[i].disabled = false;
        }
      }
    },
    selected(e, index) {
      this.clickNum = index
    },
    async uploadImg(param) {
      const fd = new FormData()
      fd.append('file', param.file)
      fd.append('picQuality', this.VideoPhotoData.threshold)
      let res = await request({
        method: 'post',
        url: `/data/api-v/dbperson/faceExtract`,
        data: fd
      })
      this.unrealSmallPath.length = 0
      console.log("切图返回:", res)
      if (res.success) {
        document.querySelector(".el-upload-list").querySelector("img").src = "/httpImage/" + res.data.uploadImage
        this.resReady = true;
        this.realSmallPath = res.data.smImage
        this.VideoPhotoData.isHaveRealSmallImg = res.data.smImage.length > 0 ? true : false
        if (res.data.smImage.length > 3) {
          this.oneLine = false
        } else {
          this.oneLine = true
        }
        if (res.data.smImage.length % 3 !== 0) {
          // 用虚拟人像补全整行
          const length = res.data.smImage.length % 3
          console.log("看看length的值", length)
          this.unrealSmallPath.length = 0
          for (var i = 0; i < 3 - length; i++) {
            this.unrealSmallPath.push(this.tempImg)
          }
        }
      }
    },
    uploadSuccess(resp, file, fileList) {
      this.$notify({
        title: "成功",
        message: "图片上传成功!",
        type: "success"
      });
      this.resReady = true;
      console.log("文件列表:", file, fileList)
      console.log("上传的文件:", this.bigPhoto)
    },
    beforeUpload() {
      this.$refs.uploadIcon.parentNode.classList.add("s-display");
      console.log("上传之前文件:", this.bigPhoto)
    },
    uploadError(err) {
      this.$notify({
        title: "失败",
        message: "图片上传失败!" + err.data,
        type: "error"
      });
      console.log("上传失败", err)
      this.dialogImageUrl = "";
      this.dialogVisible = false;
      this.$refs.uploadIcon.parentNode.classList.remove("s-display");
    },
    toAdd(item) {
      this.CardList.addBaseList.push(item)
    },
    removeImg() {
      this.resReady = false;
      this.$refs.uploadIcon.parentNode.classList.remove("s-display");
    },
    reUpload() {
      this.displayUpload = true
      this.$refs.upload.clearFiles();
      // this.dialogImageUrl = "";
      // this.dialogVisible = false;
      this.resReady = false;
      this.$refs.uploadIcon.parentNode.classList.remove("s-display");
    },
    searchStart() {
      if (this.compareTabs.length == 0) {
        this.$notify({
          title: "警告",
          type: "warning",
          message: "您还没有选择要比对的目标库",
        })
        return
      }
      this.rightSectionDisplay = true;
      this.VideoPhotoData.uploadType = true;
      this.VideoPhotoData.picUrl = this.realSmallPath[this.clickNum]
      this.VideoPhotoData.compareTabs = this.compareTabs
      console.log("选的库:", this.compareTabs)
      this.VideoPhotoData.showType = "findByPic"
      if (this.displayUpload) {
        this.VideoPhotoData.findPerson()
      } else {
        this.VideoPhotoData.findPerson2()
      }
    },
    getDetails(ev, index) {
      this.CardList.datalist = this.VideoPhotoData.persons
      let obj = this.CardList.datalist[index];
      this.CardList.details = Array.from(
        new Set([...this.CardList.details, ...[obj]])
      );
      this.VideoPhotoData.activeCard = obj.activeObject.id
    }
  }
};
</script>
<style lang="scss">
.s-upload-img {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 5px;
  .upload-area {
    width: 300px;
    height: 100%;
    //border: 1px solid #ccc;
    box-sizing: border-box;
    background: #fff;
    padding: 15px;
    // .el-upload-dragger {
    //   display:none!important
    // }
    .el-upload--picture-card {
      width: 260px !important;
    }
    .el-upload-list--picture-card {
      width: 260px !important;
      .el-upload-list__item {
        width: 260px !important;
        img {
          width: 260px;
          height: 148px;
          object-fit: contain;
        }
      }
    }
    .title {
      text-align: left;
    }
    .compearValue {
      text-align: left;
      padding: 15px 0px;
    }
  }
  .res-img-box {
    width: 100%;
    overflow: auto;
    //height: 95px;
    margin-top: 10px;
    text-align: left;
    .single-box {
      //border: 1px solid #ccc;
      width: 33%;
      height: 90px;
      padding: 5px;
      box-sizing: border-box;
      position: relative;
      img {
        object-fit: contain;
        cursor: pointer;
        border-radius: 3px;
      }
      .select {
        position: absolute;
        width: 20px;
        height: 20px;
        bottom: 5px;
        right: 5px;
      }
    }
  }
}
.s-display {
  display: none !important;
}
 
.bigPhoto {
  width: 148px;
  height: 148px;
  border-radius: 4px;
}
.el-upload-list__item {
  transition: none !important;
}
.close:hover {
  color: #3d68e1 !important;
}
</style>