Newer
Older
smart-metering-front / src / views / system / tool / showPhoto.vue
<script lang="ts" setup name="showPhoto">
import { getPhotoUrl } from '@/api/system/tool'
const props = defineProps({
  minioFileName: {
    type: String,
    required: true,
  },
  // title: {
  //   type: String,
  //   required: true,
  // },
})
const isPhoto = computed(() => {
  return props.minioFileName.split('.')[1] === 'png' || props.minioFileName.split('.')[1] === 'jpg' || props.minioFileName.split('.')[1] === 'jpeg'
})
const url = ref('')
const getPhoto = () => {
  if (props.minioFileName) {
    getPhotoUrl(props.minioFileName).then((res) => {
      url.value = res.data
    })
  }
}
onMounted(() => {
  getPhoto()
})
onUpdated(() => {
  getPhoto()
})
</script>

<template>
  <div class="container">
    <el-image
      v-if="props.minioFileName && isPhoto"
      style="width: 100px; height: 100px;margin-right: 10px;"
      :src="url"
      :preview-src-list="[url]"
      fit="cover"
    />
    <el-link
      v-else :href="url" type="primary"
      style="margin-right: 10px;"
      target="_blank"
    >
      {{ props.minioFileName }}
    </el-link>
  </div>
</template>

<style lang="scss" scoped>
.container {
  ::v-deep {
    .el-link::after {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      height: 0;
      bottom: 0;
      border-bottom: 1px solid var(--el-link-hover-text-color);
    }
  }
}
</style>