Blame view

src/components/owner/viewImage.vue 1.42 KB
b25b036d   wuxw   v1.9 优化日期
1
  <template>
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
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
    <div class="image-viewer">
      <el-dialog 
        :visible.sync="dialogVisible" 
        fullscreen 
        :show-close="false"
        @close="closeDialog">
        <div class="image-container">
          <el-image 
            :src="imageUrl" 
            fit="contain"
            :style="{ width: imageWidth + 'px', height: imageHeight + 'px' }">
          </el-image>
          <i class="el-icon-close close-icon" @click="closeDialog"></i>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  export default {
    name: 'ViewImage',
    data() {
      return {
        dialogVisible: false,
        imageUrl: '',
        imageWidth: 800,
        imageHeight: 800
      }
    },
    methods: {
      open(url) {
        this.imageUrl = url
        this.dialogVisible = true
        
        // 计算图片宽高比例
        const img = new Image()
        img.src = url
        img.onload = () => {
          const ratio = img.width / img.height
          this.imageWidth = 800
          this.imageHeight = 800 / ratio
        }
      },
      closeDialog() {
        this.dialogVisible = false
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .image-viewer {
    .image-container {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: #fff;
      padding: 20px;
      
      .close-icon {
        position: absolute;
        right: 20px;
        top: 20px;
        font-size: 24px;
        color: #F56C6C;
        cursor: pointer;
      }
    }
  }
  </style>