【sgSelectExportDocumentType】自定义组件:弹窗dialog选择导出文件格式word、pdf,支持配置图标和格式名称,触发导出事件

html 复制代码
<template>
  <div :class="$options.name" v-if="visible">
    <!-- 如果不加v-if="visible"弹窗中使用el-tabs组件就会死循环卡死,这个是elementUI的bug -->
    <el-dialog
      :append-to-body="true"
      :close-on-click-modal="true"
      :close-on-press-escape="true"
      :custom-class="`${$options.name}-el-dialog radius`"
      :destroy-on-close="true"
      :fullscreen="false"
      :show-close="true"
      :title="title"
      :width="`280px`"
      :visible.sync="visible"
      style="animation: none"
      :top="`calc(50vh - 150px)`"
    >
      <div
        style="margin: -20px 0px -10px; max-height: 500px"
        v-loading="loading"
        :element-loading-text="elementLoadingText"
      >
        <!-- 弹窗内容 -->
        <div class="form-body">
          <div class="container">
            <div v-for="(a, i) in list" :key="i" class="btn" @click="exportData(a)">
              <div class="icon">
                <img :src="a.icon" draggable="false" />
              </div>
              <p>{{ a.label }}</p>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: `sgSelectExportDocumentType`,
  components: {},
  data() {
    return {
      title: `选择导出文档格式`,
      loading: false, //加载状态
      elementLoadingText: ``, //加载提示文字

      visible: false,
      form: {},
      disabled: false, //是否只读

      list: [
        { label: `WORD`, icon: `~@/../static/img/fileType/doc.svg` },
        { label: `PDF`, icon: `~@/../static/img/fileType/pdf.svg` },
      ],
    };
  },
  props: [`value`, `data`],

  watch: {
    loading(newValue, oldValue) {
      newValue || (this.elementLoadingText = ``);
    },

    value: {
      handler(d) {
        this.visible = d;
      },
      deep: true,
      immediate: true,
    },
    visible(d) {
      this.$emit("input", d);
    },

    data: {
      handler(newValue, oldValue) {
        //console.log(`深度监听${this.$options.name}:`, newValue, oldValue);
        if (Object.keys(newValue || {}).length) {
          this.form = this.$g.deepCopy(newValue);
          this.$g.cF2CP(`disabled`, this);
          this.$g.cF2CP(`title`, this);
          this.$g.cF2CP(`list`, this);
        }
      },
      deep: true, //深度监听
      immediate: true, //立即执行
    },
  },
  methods: {
    exportData(d) {
      this.$emit(`exportData`, d);
      this.cancel();
    },
    cancel() {
      this.visible = false;
    },
  },
};
</script>
<style lang="scss" scoped>
.sgSelectExportDocumentType {
}

>>> .sgSelectExportDocumentType-el-dialog {
  .container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    text-align: center;
    .btn {
      /*禁止选中文本*/
      user-select: none;
      margin: 0 10px;
      box-sizing: border-box;
      border: 1px solid transparent;
      border-radius: 11px;
      padding: 10px 10px 20px;
      cursor: pointer;
      transition: 0.2s;
      p {
        transition: 0.2s;
      }
      &:hover {
        filter: brightness(1.1);
        border-color: #409eff;
        background-color: #409eff11;
        p {
          color: #409eff;
        }
      }
      &:active {
        transform: translate(1px, 1px);
        opacity: 0.618;
      }

      .icon {
        box-sizing: border-box;
        padding: 20px;
        box-sizing: border-box;
        padding: 10px;
        img {
          object-position: center;
          object-fit: contain;
        }
        i {
          width: 64px;
          height: 64px;
          font-size: 60px;
          color: #409eff;
        }
      }
    }
  }
}
</style>
相关推荐
计算机学姐2 分钟前
基于SpringBoot的汉服租赁系统【颜色尺码套装+个性化推荐算法+数据可视化统计】
java·vue.js·spring boot·后端·mysql·信息可视化·推荐算法
+VX:Fegn08953 分钟前
计算机毕业设计|基于springboot + vue建筑材料管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
雪碧聊技术11 分钟前
ElementPlus徽章组件:展示日期面板每天未完成的待办数量
vue.js·日期选择器·elementplus·el-badge徽章组件
bu_shuo1 小时前
将AI生成的数学公式正确复制到word中
人工智能·chatgpt·word·latex
沐墨染2 小时前
敏感词智能检索前端组件设计:树形组织过滤与多维数据分析
前端·javascript·vue.js·ui·数据挖掘·数据分析
为自己_带盐2 小时前
在 Blazor Server 中集成 docx-preview.js 实现高保真 Word 预览
javascript·c#·word
xkxnq2 小时前
第二阶段:Vue 组件化开发(第 18天)
前端·javascript·vue.js
WebGISer_白茶乌龙桃2 小时前
Cesium实现“悬浮岛”式,三维立体的行政区划
javascript·vue.js·3d·web3·html5·webgl
计算机学姐2 小时前
基于SpringBoot的汽车租赁系统【个性化推荐算法+数据可视化统计】
java·vue.js·spring boot·后端·spring·汽车·推荐算法
不一样的少年_2 小时前
产品催: 1 天优化 Vue 官网 SEO?我用这个插件半天搞定(不重构 Nuxt)
前端·javascript·vue.js