浏览代码

图片组件添加预览功能

RuoYi 4 年之前
父节点
当前提交
3cd886785b
共有 1 个文件被更改,包括 8 次插入5 次删除
  1. 8 5
      ruoyi-ui/src/components/ImageUpload/index.vue

+ 8 - 5
ruoyi-ui/src/components/ImageUpload/index.vue

@@ -17,9 +17,12 @@
         </div>
       </el-image>
       <div v-else class="image">
-        <el-image :src="value" />
+        <el-image :src="value" :style="`width:150px;height:150px;`" fit="fill"/>
         <div class="mask">
           <div class="actions">
+            <span title="预览" @click.stop="dialogVisible = true">
+              <i class="el-icon-zoom-in" />
+            </span>
             <span title="移除" @click.stop="removeImage">
               <i class="el-icon-delete" />
             </span>
@@ -27,6 +30,9 @@
         </div>
       </div>
     </el-upload>
+    <el-dialog :visible.sync="dialogVisible" title="预览" width="800" append-to-body>
+      <img :src="value" style="display: block; max-width: 100%; margin: 0 auto;">
+    </el-dialog>
   </div>
 </template>
 
@@ -36,6 +42,7 @@ import { getToken } from "@/utils/auth";
 export default {
   data() {
     return {
+      dialogVisible: false,
       uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
       headers: {
         Authorization: "Bearer " + getToken(),
@@ -76,10 +83,6 @@ export default {
 </script>
 
 <style scoped lang="scss">
-.avatar {
-  width: 100%;
-  height: 100%;
-}
 .image {
   position: relative;
   .mask {