gaoluyang
2025-11-07 5d397555769c6f7f2c86a2a2d7b56727422eb160
src/views/personnelManagement/contractManagement/index.vue
@@ -70,14 +70,15 @@
</template>
<script setup>
import { Search } from "@element-plus/icons-vue";
import { onMounted, ref } from "vue";
import { Search, UploadFilled } from "@element-plus/icons-vue";
import { onMounted, ref, reactive, toRefs, getCurrentInstance, nextTick } from "vue";
import FormDia from "@/views/personnelManagement/contractManagement/components/formDia.vue";
import { ElMessageBox } from "element-plus";
import { staffOnJobListPage } from "@/api/personnelManagement/employeeRecord.js";
import { staffOnJobListPage, staffOnJobExportCopy } from "@/api/personnelManagement/employeeRecord.js";
import dayjs from "dayjs";
import { getToken } from "@/utils/auth.js";
import FilesDia from "./filesDia.vue";
import axios from "axios";
const data = reactive({
  searchForm: {
    staffName: "",
@@ -183,7 +184,7 @@
    label: "操作",
    align: "center",
    fixed: 'right',
    width: 120,
    width: 180,
    operation: [
      {
        name: "详情",
@@ -197,6 +198,13 @@
        type: "text",
        clickFun: (row) => {
          openFilesFormDia(row);
        },
      },
      {
        name: "下载合同",
        type: "text",
        clickFun: (row) => {
          handleDownloadContract(row);
        },
      },
    ],
@@ -278,6 +286,48 @@
      proxy.$modal.msg("已取消");
    });
};
// 下载合同
const handleDownloadContract = (row) => {
  const fileName = `${row.staffName || "合同"}劳动合同.docx`;
  proxy.$modal?.loading?.("正在生成合同,请稍候...");
  staffOnJobExportCopy({ ...row })
    .then((res) => {
      proxy.$modal?.closeLoading?.();
      if (res?.code === 200 && res?.msg) {
        const javaApi = proxy.javaApi || import.meta.env.VITE_JAVA_API || "";
        const downloadPath = res.msg.startsWith("/") ? res.msg : `/${res.msg}`;
        const downloadUrl = `${javaApi}${downloadPath}`;
        axios({
          url: downloadUrl,
          method: "get",
          responseType: "blob",
          headers: { Authorization: "Bearer " + getToken() }
        })
          .then((resp) => {
            const blob = new Blob([resp.data], {
              type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            });
            const url = window.URL.createObjectURL(blob);
            const link = document.createElement("a");
            link.href = url;
            link.download = fileName;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            window.URL.revokeObjectURL(url);
          })
          .catch(() => {
            proxy.$modal.msgError("合同下载失败,请稍后重试");
          });
      } else {
        proxy.$modal.msgError(res?.msg || "合同生成失败");
      }
    })
    .catch(() => {
      proxy.$modal?.closeLoading?.();
      proxy.$modal.msgError("合同生成失败,请稍后重试");
    });
};
const upload = reactive({
  // 是否显示弹出层(合同导入)
  open: false,