index.vue 1.6 KB

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