【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)" />
相关推荐
羊小猪~~1 小时前
前端入门之VUE--vue组件化编程
前端·javascript·css·vue.js·vscode·vue·html
阿智@111 小时前
跨域 Cookie 共享
java·开发语言·javascript
Afanda…1 小时前
JS API&日期对象
前端·javascript
web150850966411 小时前
前端小练习——星辰宇宙(JS没有上限!!!)
开发语言·前端·javascript
Loong_DQX1 小时前
【vue】 vue实现前端拖拽div位置交换
前端·javascript·vue.js
m0_748239834 小时前
一款免费、简单、快速的JS打印插件,web 打印组件,基于JavaScript开发,支持数据分组,快速分页批量预览,打印,转pdf,移动端,PC端
前端·javascript·pdf
m0_748254664 小时前
iOS中使用WKWebView加载和显示PDF文档实战
ios·pdf·cocoa
一个W牛5 小时前
导入excel动态生成海报
前端·javascript·excel·贴图
不学习何以强国6 小时前
uni-app 个人课程表页面
前端·javascript·uni-app
Yui_NIE7 小时前
解决core-js报错:These dependencies were not found: core-js/modules/es.array.push.js
开发语言·前端·javascript