LandingPage.vue 7.94 KB
<template>
  <div class="main">
    <div class="main-form">
      <el-form
        :model="emailForm"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        class="demo-ruleForm"
      >
        <el-form-item label="邮件标题" prop="title">
          <el-input v-model="emailForm.title"></el-input>
        </el-form-item>
        <el-form-item label="授权码" prop="pass">
          <el-input v-model="emailForm.pass"></el-input>
        </el-form-item>
        <el-form-item label="发送人" prop="fromPeople">
          <el-input v-model="emailForm.fromPeople"></el-input>
        </el-form-item>
        <el-form-item label="收件人" prop="toPeople">
          <el-input v-model="emailForm.toPeople"></el-input>
        </el-form-item>
        <el-form-item label="抄送人" prop="ccPeople">
          <el-input
            type="textarea"
            :rows="3"
            v-model="emailForm.ccPeople"
          ></el-input>
        </el-form-item>
        <el-form-item label="携带附件">
          <el-radio-group v-model="emailForm.isFile">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <div class="file-panel" v-if="emailForm.isFile == 1">
          <div
            class="file-panel-item"
            v-for="(item, index) in emailForm.fileInfo"
            :key="index"
          >
            <i class="el-icon-close" @click="removeFile(index)"></i>
            <el-form-item
              label="项目路径"
              :prop="`fileInfo[${index}].path`"
              :rules="{
                required: true,
                message: '请输入项目路径',
                trigger: 'blur',
              }"
            >
              <el-input v-model="item.path"></el-input>
            </el-form-item>
            <el-form-item
              label="附件路径"
              :prop="`fileInfo[${index}].filePath`"
              :rules="{
                required: true,
                message: '请输入附件路径',
                trigger: 'blur',
              }"
            >
              <el-input v-model="item.filePath"></el-input>
            </el-form-item>
          </div>
          <div class="add-item">
            <el-button @click="addFile">添加</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <div
      class="textarea-content"
      contenteditable="true"
      v-html="emailForm.htmlContent"
    ></div>
    <div class="add-item">
      <el-button @click="submitForm">发送</el-button>
    </div>
    <div class="loading-containner" v-if="loading">
      <div class="loading-box">打包中</div>
    </div>
  </div>
</template>

<script>
import { util } from "../../utils/util";
export default {
  name: "HelloWorld",
  data() {
    return {
      loading: false,
      emailForm: {
        title: "【提测】【SCRM-V2.0.0-0330】 嘀加企微管家前端第二轮提测",
        pass: "xqGTv2AXbyEPJkKm",
        fromPeople: "yangming@didihu.com.cn",
        toPeople: "yangming@didihu.com.cn",
        ccPeople: util.ccPeople,
        fileInfo: [
          {
            path: "D:\\project\\git\\scrm-micro-drainage1.0.2\\scrm-micro-drainage",
            filePath:
              "D:\\project\\git\\scrm-micro-drainage1.0.2\\dist\\drainage.zip",
          },
        ],
        htmlContent: util.htmlContent,
        isFile: "1",
      },
      rules: {
        pass: [{ required: true, message: "请输入授权码", trigger: "blur" }],
        path: [{ required: true, message: "请输入项目路径", trigger: "blur" }],
        fromPeople: [
          { required: true, message: "请输入发送人", trigger: "blur" },
        ],
        toPeople: [
          { required: true, message: "请输入收件人", trigger: "blur" },
        ],
        ccPeople: [
          { required: true, message: "请输入抄送人", trigger: "blur" },
        ],
        title: [{ required: true, message: "请输入邮件标配", trigger: "blur" }],
      },
    };
  },
  mounted() {
    const text = JSON.parse(localStorage.getItem("text"));
    if (text) {
      this.emailForm = JSON.parse(localStorage.getItem("text"));
    }
  },
  watch: {
    emailForm: {
      handler(val) {
        const { fromPeople, toPeople, ccPeople } = util.deepClone(
          this.emailForm
        );
        this.emailForm.fromPeople = util.regexEmail(fromPeople);
        this.emailForm.toPeople = util.regexEmail(toPeople);
        this.emailForm.ccPeople = util.regexEmail(ccPeople);
      },
      deep: true,
    },
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.handleBuild();
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    addFile() {
      this.emailForm.fileInfo.push({
        path: "",
        fileName: "",
        filePath: "",
      });
    },
    removeFile(index) {
      this.emailForm.fileInfo.splice(index, 1);
    },
    submit() {
      this.emailForm.htmlContent =
        document.querySelector(".textarea-content").innerHTML;
      let formData = {
        emailForm: this.emailForm,
      };
      this.$electron.ipcRenderer.send("send-email", formData);
      this.$electron.ipcRenderer.on("send-message", (event, arg) => {
        if (arg.code == 0) {
          this.$message({
            message: "发送成功",
            type: "success",
          });
          localStorage.setItem("text", JSON.stringify(this.emailForm));
        } else {
          this.$message.error("发送失败");
        }
        this.loading = false;
      });
    },
    handleBuild() {
      this.loading = true;
      let buildNum = 0;
      const fileInfo = this.emailForm.fileInfo;
      if (!fileInfo || fileInfo.length == 0 || this.emailForm.isFile == 2) {
        this.submit();
        return;
      }
      fileInfo.forEach((item) => {
        let index = item.filePath.lastIndexOf("\\") + 1;
        let fileName = item.filePath.substring(index);
        if (!fileName.includes("zip")) {
          this.$message.error("请检查附件路径");
          this.loading = false;
          return;
        }
        item.fileName = fileName;
        let formData = {
          fileInfo: item,
        };
        this.$electron.ipcRenderer.send("send-build", formData);
        this.$electron.ipcRenderer.on("build-message", (event, arg) => {
          if (arg.code == 0) {
            buildNum++;
          } else {
            this.$message.error("打包失败");
            this.loading = false;
          }
          if (buildNum == fileInfo.length) {
            this.submit();
          }
        });
      });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.main-form {
  width: 800px;
  margin: 0 auto;
}
.textarea-content {
  width: 800px;
  border: 1px solid #666666;
  margin: 0 auto;
}
.file-panel {
  box-shadow: 0px 10px 20px 0px rgba(88, 80, 255, 0.1);
  padding: 10px;
}
.file-panel-item {
  border: 1px solid #ebeef5;
  padding: 30px 20px 0px;
  margin-bottom: 10px;
  position: relative;
}
.el-icon-close {
  position: absolute;
  right: 5px;
  top: 5px;
  font-size: 20px;
  cursor: pointer;
}
.add-item {
  text-align: center;
  margin-top: 10px;
}
.loading-containner {
  top: 0px;
  left: 0px;
  position: fixed;
  width: 100%;
  background: rgba(255, 255, 255, 0.8);
  z-index: 5000;
  height: 100%;
}
.loading-box {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -28px;
  margin-left: -88px;
  width: 176px;
  font-size: 14px;
  color: #ffffff;
  line-height: 54px;
  text-align: center;
  height: 54px;
  background: #666666;
  border-radius: 2px;
}
.loading-box::after {
  content: "";
  position: absolute;
  top: 0%;
  bottom: 0;
  animation: dot 3s infinite steps(3, start);
  color: #ffffff;
}
@keyframes dot {
  33.33% {
    content: ".";
  }
  66.67% {
    content: ". .";
  }
  100% {
    content: ". . .";
  }
}
</style>