zhangwei
2025-08-27 dade6a8b4772abc113383246d05ab59162630e7c
src/views/system/dept/uploadform.vue
@@ -19,6 +19,8 @@
const props = withDefaults(defineProps<TenderProps>(), {
  formInline: () => ({
    id: "", // 主键Id(必填)
    tenderId: "",
    higherDeptOptions: [],
    projectName: "",
    toubiaoStartDate: "", // 投标报名开始时间(必填,格式:yyyy-MM-dd HH:mm:ss)
    toubiaoEndDate: "", // 投标报名结束时间(必填,格式:yyyy-MM-dd HH:mm:ss)
@@ -26,7 +28,9 @@
    zhaobiaowenjian: "", // 招标文件(必填,长度1-512字符)
    zhaobiaowenjianName: "",
    biangengwenjian: "",
    biangengwenjianName: "",
    fujian: "", // 附件(可选,最大长度512字符,可为空)
    fujianName: "", // 附件(可选,最大长度512字符,可为空)
    kaibiaodidian: "" // 开标地点(必填,长度1-250字符)
  }),
  isChange: null,
@@ -116,6 +120,7 @@
const newFormInline = ref(props.formInline);
const validateForm = reactive({
  fileList: [],
  fileListFile: [],
  date: ""
});
const upload = ref<UploadInstance>();
@@ -159,22 +164,41 @@
  fetchCredentials(file);
  // upload.value!.submit();
};
const handleChangeFile = file => {
  console.log(file);
const handleChangeFile = async file => {
  if (file.status !== "ready") return;
  // let suffName = file.name.substring(file.name.lastIndexOf(".") + 1);
  // const extension = suffName === "pdf";
  // // const isLt10M = file.size / 1024 / 1024 < 10;
  // if (!extension) {
  //   message(`仅支持pdf格式,请上传pdf`, {
  //     type: "error"
  //   });
  //   validateForm.fileList = [];
  //   return false;
  // }
  // const isLt10M = file.size / 1024 / 1024 < 10;
  // fetchCredentials(file);
  // upload.value!.submit();
  // 这里应调用你自己的后端接口获取临时凭证
  let res = await getUploadToken();
  if (res.code == 200) {
    let keyVal = generateTimestampWithRandom(res.result.DirPath, file.name);
    let upUrl = res.result.url;
    let upPath = res.result.DirPath;
    let formData = new FormData();
    formData.append("policy", res.result.policy);
    formData.append(
      "x-oss-signature-version",
      res.result.x_oss_signature_version
    );
    formData.append("x-oss-credential", res.result.x_oss_credential);
    formData.append("x-oss-date", res.result.x_oss_date);
    // formData.append("Signature", res.result.signature);
    formData.append("x-oss-signature", res.result.signature);
    formData.append("x-oss-security-token", res.result.security_token);
    // formData.append("x-oss-content-type", "application/pdf");
    formData.append("success_action_status", "200");
    formData.append("key", keyVal); // 文件名
    formData.append("file", file.raw); // file 必须为最后一个表单域
    uploadFileAli(formData, res.result.url).then(res => {
      let path = `${upUrl}${keyVal}`;
      newFormInline.value.fujian += newFormInline.value.fujian
        ? `,${path}`
        : path;
      newFormInline.value.fujianName += newFormInline.value.fujianName
        ? `,${file.name}`
        : file.name;
    });
  }
};
// state.formDataNew = {
//   policy: res.result.policy, //表单域
@@ -244,7 +268,16 @@
  upload.value!.handleStart(file);
};
defineExpose({ getRef });
onMounted(async () => {});
onMounted(async () => {
  if (props.formInline.biangengwenjianName) {
    validateForm.fileList = [
      {
        name: props.formInline.biangengwenjianName,
        url: props.formInline.biangengwenjian
      }
    ];
  }
});
</script>
<template>
@@ -362,7 +395,7 @@
        <el-form-item label="附件" prop="">
          <el-upload
            ref="upload"
            v-model:file-list="validateForm.fileList"
            v-model:file-list="validateForm.fileListFile"
            multiple
            :on-exceed="handleExceed"
            :auto-upload="false"
@@ -393,6 +426,7 @@
.el-date-editor.el-input__wrapper {
  width: 100%;
}
.upload__tip {
  width: 100%;
}