index.vue 1.8 KB

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