瀏覽代碼

预览组件支持多图显示

RuoYi 4 年之前
父節點
當前提交
db07f4a354
共有 1 個文件被更改,包括 62 次插入53 次删除
  1. 62 53
      ruoyi-ui/src/components/ImagePreview/index.vue

+ 62 - 53
ruoyi-ui/src/components/ImagePreview/index.vue

@@ -1,67 +1,76 @@
1 1
 <template>
2
-    <el-image :src="`${realSrc}`" fit="cover" :style="`width:${realWidth};height:${realHeight};`" :preview-src-list="[`${realSrc}`]">
3
-        <div slot="error" class="image-slot">
4
-          <i class="el-icon-picture-outline"></i>
5
-        </div>
6
-    </el-image>
2
+  <el-image
3
+    :src="`${realSrc}`"
4
+    fit="cover"
5
+    :style="`width:${realWidth};height:${realHeight};`"
6
+    :preview-src-list="realSrcList"
7
+  >
8
+    <div slot="error" class="image-slot">
9
+      <i class="el-icon-picture-outline"></i>
10
+    </div>
11
+  </el-image>
7 12
 </template>
8 13
 
9 14
 <script>
10
-import { isExternal } from '@/utils/validate'
11
-
12 15
 export default {
13
-    name: 'ImagePreview',
14
-    props: {
15
-        src: {
16
-            type: String,
17
-            required: true
18
-        },
19
-        width: {
20
-            type: [Number, String],
21
-            default: ''
22
-        },
23
-        height: {
24
-            type: [Number, String],
25
-            default: ''
26
-        }
16
+  name: "ImagePreview",
17
+  props: {
18
+    src: {
19
+      type: String,
20
+      required: true
21
+    },
22
+    width: {
23
+      type: [Number, String],
24
+      default: ""
27 25
     },
28
-    computed: {
29
-        realSrc() {
30
-            if (isExternal(this.src)) {
31
-                return this.src
32
-            }
33
-            return process.env.VUE_APP_BASE_API + this.src
34
-        },
35
-        realWidth() {
36
-            return typeof this.width == 'string' ? this.width : `${this.width}px`
37
-        },
38
-        realHeight() {
39
-            return typeof this.height == 'string' ? this.height : `${this.height}px`
40
-        }
26
+    height: {
27
+      type: [Number, String],
28
+      default: ""
41 29
     }
42
-}
30
+  },
31
+  computed: {
32
+    realSrc() {
33
+      let real_src = this.src.split(",")[0];
34
+      return real_src;
35
+    },
36
+    realSrcList() {
37
+      let real_src_list = this.src.split(",");
38
+      let srcList = [];
39
+      real_src_list.forEach(item => {
40
+        return srcList.push(item);
41
+      });
42
+      return srcList;
43
+    },
44
+    realWidth() {
45
+      return typeof this.width == "string" ? this.width : `${this.width}px`;
46
+    },
47
+    realHeight() {
48
+      return typeof this.height == "string" ? this.height : `${this.height}px`;
49
+    }
50
+  },
51
+};
43 52
 </script>
44 53
 
45 54
 <style lang="scss" scoped>
46 55
 .el-image {
47
-    border-radius: 5px;
48
-    background-color: #ebeef5;
49
-    box-shadow: 0 0 5px 1px #ccc;
50
-    ::v-deep .el-image__inner {
51
-        transition: all 0.3s;
52
-        cursor: pointer;
53
-        &:hover {
54
-            transform: scale(1.2);
55
-        }
56
-    }
57
-    ::v-deep .image-slot {
58
-        display: flex;
59
-        justify-content: center;
60
-        align-items: center;
61
-        width: 100%;
62
-        height: 100%;
63
-        color: #909399;
64
-        font-size: 30px;
56
+  border-radius: 5px;
57
+  background-color: #ebeef5;
58
+  box-shadow: 0 0 5px 1px #ccc;
59
+  ::v-deep .el-image__inner {
60
+    transition: all 0.3s;
61
+    cursor: pointer;
62
+    &:hover {
63
+      transform: scale(1.2);
65 64
     }
65
+  }
66
+  ::v-deep .image-slot {
67
+    display: flex;
68
+    justify-content: center;
69
+    align-items: center;
70
+    width: 100%;
71
+    height: 100%;
72
+    color: #909399;
73
+    font-size: 30px;
74
+  }
66 75
 }
67 76
 </style>