index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. required: true
  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. let real_src = this.src.split(",")[0];
  34. if (isExternal(real_src)) {
  35. return real_src;
  36. }
  37. return process.env.VUE_APP_BASE_API + real_src;
  38. },
  39. realSrcList() {
  40. let real_src_list = this.src.split(",");
  41. let srcList = [];
  42. real_src_list.forEach(item => {
  43. if (isExternal(item)) {
  44. return srcList.push(item);
  45. }
  46. return srcList.push(process.env.VUE_APP_BASE_API + item);
  47. });
  48. return srcList;
  49. },
  50. realWidth() {
  51. return typeof this.width == "string" ? this.width : `${this.width}px`;
  52. },
  53. realHeight() {
  54. return typeof this.height == "string" ? this.height : `${this.height}px`;
  55. }
  56. },
  57. };
  58. </script>
  59. <style lang="scss" scoped>
  60. .el-image {
  61. border-radius: 5px;
  62. background-color: #ebeef5;
  63. box-shadow: 0 0 5px 1px #ccc;
  64. ::v-deep .el-image__inner {
  65. transition: all 0.3s;
  66. cursor: pointer;
  67. &:hover {
  68. transform: scale(1.2);
  69. }
  70. }
  71. ::v-deep .image-slot {
  72. display: flex;
  73. justify-content: center;
  74. align-items: center;
  75. width: 100%;
  76. height: 100%;
  77. color: #909399;
  78. font-size: 30px;
  79. }
  80. }
  81. </style>