【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>
相关推荐
JoyGqz6 小时前
Vue 2 EOL 之后还在跑生产?这个开源安全分支已修主流 CVE,一行依赖即可接入
vue.js
Lkstar6 小时前
Vue 3 Composition API 进阶:自定义 Hooks 与 provide/inject 的高级玩法
vue.js·面试
前端若水7 小时前
在 Vue 2 与 Vue 3 中使用 markdown-it-vue 渲染 Markdown 和数学公式
前端·javascript·vue.js
Aolith7 小时前
用 Vue 递归组件实现嵌套回复,我的评论系统升级全记录
vue.js·全栈
wujian83118 小时前
AI表格怎么导出word
人工智能·ai·word·豆包·deepseek·ai导出鸭
zh路西法8 小时前
【Word自动目录使用指南】告别手动修改格式,一次设置成功!
word
叫我少年8 小时前
Vue3 状态管理 Pinia 入门指南
vue.js
软件富二代9 小时前
— 批量转换Word题库到Excel的小工具
电脑·word·excel·排版·软件
yqcoder10 小时前
Vue 的心脏:深度解析 Vue 2 vs Vue 3 响应式机制
前端·javascript·vue.js
wand codemonkey10 小时前
【第五步+前后分离调】最后的联动调试--java+Vue3项目
java·开发语言·vue.js