ZZJ
2022-07-27 f358f667a292973618199b51552d61179181cf1d
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
<template>
  <div class="imgBox">
    <img
      :src="'http://' + url"
      class="cursor-pointer"
      v-if="isPreview"
      preview
    />
    <img :src="'http://' + url" v-if="!isPreview" />
    <el-button class="btn" @click="downloadIamge('http://' + url)">
      <i class="iconfont iconxiazai"></i>
    </el-button>
  </div>
</template>
<script>
import axios from "axios";
export default {
  props: {
    url: {
      default: "",
      type: String,
    },
    isPreview: {
      default: true,
      type: Boolean,
    },
  },
  methods: {
    downloadIamge(url) {
      axios({
        method: "get",
        url: url,
        responseType: "blob",
      })
        .then((res) => {
          if (res.status == 200) {
            var a = document.createElement("a");
            var strs = url.split("/");
            var href = new Blob([res.data], { type: "image/jpeg" });
            a.href = URL.createObjectURL(href);
            a.download = strs[strs.length - 1] + ".jpg";
            a.click();
          }
        })
        .catch((err) => {
          if (err && err.status == 401) {
            return;
          }
          this.$notify({
            type: "error",
            message: "下载失败," + err + "请重试!",
            duration: 2500,
            offset: 57,
          });
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.imgBox {
  width: 100%;
  height: 100%;
  position: relative;
  img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  .btn {
    width: 30px;
    height: 30px;
    position: absolute;
    padding: 0;
    right: 20%;
    opacity: 1;
    bottom: 10px;
    animation: fadenum 0.7s ease;
    -webkit-animation: fadenum 0.7s ease;
    display: none;
    i {
      font-size: 20px;
    }
  }
}
.imgBox:hover .btn {
  display: inline;
}
@keyframes fadenum {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@-webkit-keyframes fadenum {
  /*设置内容由显示变为隐藏*/
 
  0% {
    opacity: 0;
  }
 
  100% {
    opacity: 1;
  }
}
</style>