Blame view

src/components/fee/viewImage.vue 2.34 KB
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
1
  <template>
43eaaadb   wuxw   开发房屋优惠折扣
2
3
4
5
6
7
8
9
10
11
12
    <div v-show="visible" class="image-viewer-wrapper">
      <div class="image-viewer-mask" @click="close"></div>
      <div class="image-viewer-content">
        <img 
          :src="imageUrl" 
          :style="imageStyle"
          @error="handleImageError"
        />
        <span class="image-viewer-close" @click="close">
          <i class="el-icon-close"></i>
        </span>
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
13
14
15
16
17
18
19
20
21
      </div>
    </div>
  </template>
  
  <script>
  export default {
    name: 'ViewImage',
    data() {
      return {
43eaaadb   wuxw   开发房屋优惠折扣
22
23
24
25
        visible: false,
        imageUrl: '',
        imageWidth: 0,
        imageHeight: 0
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
26
27
28
      }
    },
    computed: {
43eaaadb   wuxw   开发房屋优惠折扣
29
      imageStyle() {
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
30
        return {
43eaaadb   wuxw   开发房屋优惠折扣
31
32
33
34
          width: this.imageWidth ? `${this.imageWidth}px` : 'auto',
          height: this.imageHeight ? `${this.imageHeight}px` : 'auto',
          maxWidth: '90vw',
          maxHeight: '90vh'
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
35
36
37
38
39
        }
      }
    },
    methods: {
      open(url) {
43eaaadb   wuxw   开发房屋优惠折扣
40
41
42
43
44
        this.imageUrl = url
        this.visible = true
        this.$nextTick(() => {
          this.calculateImageSize(url)
        })
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
45
46
      },
      close() {
43eaaadb   wuxw   开发房屋优惠折扣
47
48
49
50
        this.visible = false
        this.imageUrl = ''
        this.imageWidth = 0
        this.imageHeight = 0
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
51
      },
43eaaadb   wuxw   开发房屋优惠折扣
52
53
54
55
      handleImageError(e) {
        e.target.src = '/img/noPhoto.jpg'
      },
      calculateImageSize(url) {
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
56
57
58
        const img = new Image()
        img.src = url
        img.onload = () => {
43eaaadb   wuxw   开发房屋优惠折扣
59
60
61
62
63
          const maxWidth = window.innerWidth * 0.8
          const maxHeight = window.innerHeight * 0.8
          const ratio = Math.min(maxWidth / img.width, maxHeight / img.height, 1)
          this.imageWidth = img.width * ratio
          this.imageHeight = img.height * ratio
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
64
        }
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
65
66
67
68
69
      }
    }
  }
  </script>
  
43eaaadb   wuxw   开发房屋优惠折扣
70
71
  <style lang="scss" scoped>
  .image-viewer-wrapper {
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
72
73
74
75
76
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
77
78
79
80
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
81
  
43eaaadb   wuxw   开发房屋优惠折扣
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    .image-viewer-mask {
      position: absolute;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.7);
    }
  
    .image-viewer-content {
      position: relative;
      z-index: 1;
      padding: 20px;
      background-color: #fff;
      border-radius: 4px;
      text-align: center;
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
96
  
43eaaadb   wuxw   开发房屋优惠折扣
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
      img {
        display: block;
        margin: 0 auto;
        object-fit: contain;
      }
    }
  
    .image-viewer-close {
      position: absolute;
      top: 10px;
      right: 10px;
      font-size: 24px;
      color: #f56c6c;
      cursor: pointer;
      z-index: 2;
  
      &:hover {
        color: #f78989;
      }
    }
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
117
118
  }
  </style>