index.vue 1.8 KB

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