ToB企服应用市场:ToB评测及商务社交产业平台

标题: 【sgFileLink】自界说组件:基于el-link、el-icon标签构建文件超链接组件, [打印本页]

作者: 科技颠覆者    时间: 2024-12-11 17:55
标题: 【sgFileLink】自界说组件:基于el-link、el-icon标签构建文件超链接组件,


sgFileLink源代码

  1. <template>
  2.   <div :class="$options.name">
  3.     <el-link @click.stop="clickFile(data)">
  4.       <img :src="getSrc(data)" /><span>{{ getBannerFileName(data) }}</span></el-link
  5.     >
  6.     <el-link
  7.       class="remove-btn"
  8.       v-if="clearable_"
  9.       icon="el-icon-delete"
  10.       :underline="false"
  11.       @click.stop="remove(data)"
  12.     />
  13.     <el-image ref="image" style="display: none" src="" :preview-src-list="[previewSrc]" />
  14.     <sgVideoDialog :data="data_sgVideoDialog" v-model="show_sgVideoDialog" />
  15.     <sgAudioDialog :data="data_sgAudioDialog" v-model="show_sgAudioDialog" />
  16.   </div>
  17. </template>
  18. <script>
  19. import sgVideoDialog from "@/vue/components/admin/sgVideoDialog";
  20. import sgAudioDialog from "@/vue/components/admin/sgAudioDialog";
  21. import $com from "@/js/com";
  22. export default {
  23.   name: "sgFileLink",
  24.   components: { sgVideoDialog, sgAudioDialog },
  25.   data() {
  26.     return {
  27.       data_sgVideoDialog: {},
  28.       show_sgVideoDialog: false,
  29.       data_sgAudioDialog: {},
  30.       show_sgAudioDialog: false,
  31.       previewSrc: null,
  32.       clearable_: null,
  33.     };
  34.   },
  35.   props: ["data", "clearable"],
  36.   computed: {},
  37.   watch: {
  38.     clearable: {
  39.       handler(newValue, oldValue) {
  40.         this.clearable_ = newValue === "" || newValue;
  41.       },
  42.       deep: true, //深度监听
  43.       immediate: true, //立即执行
  44.     },
  45.   },
  46.   created() {},
  47.   mounted() {},
  48.   destroyed() {},
  49.   methods: {
  50.     remove(data) {
  51.       this.$emit(`remove`, data);
  52.     },
  53.     clickFile(d) {
  54.       $com.clickFile(d, this);
  55.     },
  56.     getSrc(d) {
  57.       typeof d === `string` && (d = JSON.parse(d));
  58.       let fileName = d.name;
  59.       let suffix = fileName.split(".").slice(-1)[0];
  60.       return $com.getFlieThumbSrc({ suffix });
  61.     },
  62.     getBannerFileName(d) {
  63.       return $com.getBannerFileName(d);
  64.     },
  65.   },
  66. };
  67. </script>
  68. <style lang="scss" scoped>
  69. .sgFileLink {
  70.   >>> .el-link {
  71.     transition: 0.2s;
  72.     line-height: normal;
  73.     img {
  74.       width: 16px;
  75.       height: 16px;
  76.       object-position: center;
  77.       object-fit: contain;
  78.       transform: translateY(2px);
  79.     }
  80.     span {
  81.       word-wrap: break-word;
  82.       word-break: break-all;
  83.       white-space: break-spaces;
  84.     }
  85.   }
  86.   .remove-btn {
  87.     transition: 0.382s;
  88.     opacity: 0;
  89.     pointer-events: none;
  90.     transform: translateX(-100%);
  91.   }
  92.   &:hover {
  93.     .remove-btn {
  94.       opacity: 1;
  95.       pointer-events: auto;
  96.       transform: translateX(0%);
  97.     }
  98.   }
  99. }
  100. </style>
复制代码
应用

  1. <sgFileLink :data="{ ...scope.row, clearable: true }" @remove="remove(scope.row, scope.$index)" />
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4