【sgFileLink】自定义组件:基于el-link、el-icon标签构建文件超链接组件,支持垃圾桶删除、点击预览视频/音频/图片/PDF格式文件

sgFileLink源代码

html 复制代码
<template>
  <div :class="$options.name">
    <el-link @click.stop="clickFile(data)">
      <img :src="getSrc(data)" /><span>{{ getBannerFileName(data) }}</span></el-link
    >
    <el-link
      class="remove-btn"
      v-if="clearable_"
      icon="el-icon-delete"
      :underline="false"
      @click.stop="remove(data)"
    />

    <el-image ref="image" style="display: none" src="" :preview-src-list="[previewSrc]" />
    <sgVideoDialog :data="data_sgVideoDialog" v-model="show_sgVideoDialog" />
    <sgAudioDialog :data="data_sgAudioDialog" v-model="show_sgAudioDialog" />
  </div>
</template>
<script>
import sgVideoDialog from "@/vue/components/admin/sgVideoDialog";
import sgAudioDialog from "@/vue/components/admin/sgAudioDialog";
import $com from "@/js/com";
export default {
  name: "sgFileLink",
  components: { sgVideoDialog, sgAudioDialog },
  data() {
    return {
      data_sgVideoDialog: {},
      show_sgVideoDialog: false,
      data_sgAudioDialog: {},
      show_sgAudioDialog: false,

      previewSrc: null,
      clearable_: null,
    };
  },
  props: ["data", "clearable"],
  computed: {},
  watch: {
    clearable: {
      handler(newValue, oldValue) {
        this.clearable_ = newValue === "" || newValue;
      },
      deep: true, //深度监听
      immediate: true, //立即执行
    },
  },
  created() {},
  mounted() {},
  destroyed() {},
  methods: {
    remove(data) {
      this.$emit(`remove`, data);
    },
    clickFile(d) {
      $com.clickFile(d, this);
    },
    getSrc(d) {
      typeof d === `string` && (d = JSON.parse(d));
      let fileName = d.name;
      let suffix = fileName.split(".").slice(-1)[0];
      return $com.getFlieThumbSrc({ suffix });
    },
    getBannerFileName(d) {
      return $com.getBannerFileName(d);
    },
  },
};
</script>
<style lang="scss" scoped>
.sgFileLink {
  >>> .el-link {
    transition: 0.2s;
    line-height: normal;

    img {
      width: 16px;
      height: 16px;
      object-position: center;
      object-fit: contain;
      transform: translateY(2px);
    }
    span {
      word-wrap: break-word;
      word-break: break-all;
      white-space: break-spaces;
    }
  }
  .remove-btn {
    transition: 0.382s;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-100%);
  }
  &:hover {
    .remove-btn {
      opacity: 1;
      pointer-events: auto;
      transform: translateX(0%);
    }
  }
}
</style>

应用

html 复制代码
<sgFileLink :data="{ ...scope.row, clearable: true }" @remove="remove(scope.row, scope.$index)" />
相关推荐
sqmeeting1 小时前
Linux NUC小主机化身视频会议服务器: 技术优势与部署实战
linux·服务器·windows·音视频·实时音视频
记得早睡~2 小时前
leetcode51-N皇后
javascript·算法·leetcode·typescript
乘风!3 小时前
Java导出excel,表格插入pdf附件,以及实现过程中遇见的坑
java·pdf·excel
拉不动的猪3 小时前
vue自定义指令的几个注意点
前端·javascript·vue.js
yanyu-yaya3 小时前
react redux的学习,单个reducer
前端·javascript·react.js
ElasticPDF-新国产PDF编辑器4 小时前
Uni-app PDF Annotation plugin library online API examples
pdf·uni-app
加瓦点灯4 小时前
观察者模式:解耦对象间的依赖关系
开发语言·javascript·观察者模式
z_mazin4 小时前
Chrome开发者工具实战:调试三剑客
前端·javascript·chrome·网络爬虫
sen_shan6 小时前
Vue3+Vite+TypeScript+Element Plus开发-04.静态菜单设计
前端·javascript·typescript·vue3·element·element plus·vue 动态菜单
旧识君6 小时前
移动端1px终极解决方案:Sass混合宏工程化实践
开发语言·前端·javascript·前端框架·less·sass·scss