【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>
相关推荐
Lanwarf-前端开发1 小时前
Vue3 + Canvas/WebGL 雷达扫描可视化实战:PPI、RHI、VOL、SVOL 四种模式原理与实现
前端·javascript·vue.js·webgl
ComPDFKit1 小时前
RAG 回答只显示 PDF 文件名?用 Python 保留引用页码
开发语言·python·pdf·rag
FRing032 小时前
vue3干货总结2(vue3生命周期、父子通信、模版引用、provide和inject)
开发语言·前端·vue.js·vue3
科研邪修法4 小时前
固定列宽PDF表格改字:文本边界、单位字段与修改前后复核
pdf
Frag0ut4 小时前
Chrome 2026打印与PDF处理全攻略:网页存证与文档输出实战进阶指南
chrome·pdf·批量打印·打印设置·网页存证·打印排版
小码哥0686 小时前
智慧物业系统源码定制:公告发布范围与住户阅读记录设计
前端·javascript·vue.js·物业管理·物业系统·物业软件
码云社区10 小时前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案
java·vue.js·vr·租房小程序·在线租房·看房租房
cc.ChenLy10 小时前
无法修改 el-dialog 样式原因及解决办法
javascript·vue.js·elementui
AI开源软件11 小时前
Vue3+SpringBoot3 业务配置统一管理:接管、保存与回退怎样保留有效值
java·前端·vue.js·spring boot·vue·ruoyi office
1-1=011 小时前
Vue 脚手架
前端·javascript·vue.js