gaoluyang
3 天以前 ffb1bd190e9d4263c8c7d6c0096e0ec844cb3b52
src/views/archiveManagement/mould/archiveDialog.vue
@@ -36,10 +36,11 @@
      </el-row>
    </template>
    <fileUpload
    v-model="ruleForm.file"
    ref="fileUploadRef"
    :fileSize="1024"
    :fileType="['pdf', 'docx', 'txt', 'xlsx', 'pptx....']"
    :limit="10"
    v-model:modelValue="modelValue"
    />
  </el-dialog>
</template>
@@ -48,6 +49,7 @@
import { ref, watch } from "vue";
import { addOrEditArchive } from "@/api/archiveManagement";
import fileUpload from "@/components/FileUpload/index.vue";
import { ElMessage } from "element-plus";
const centerDialogVisible = defineModel("centerDialogVisible", {
  type: Boolean,
@@ -72,6 +74,7 @@
    name: "",
    type: "",
    status: "",
    storageBlobDTO: [], // 确保 storageBlobDTO 是一个数组
  };
};
@@ -93,13 +96,29 @@
  type: [{ required: true, message: "请选择文档类型", trigger: "blur" }],
  status: [{ required: true, message: "请选择文档状态", trigger: "blur" }],
};
const fileUploadRef = ref(null);
const initForm = () => {
  ruleForm.value = {}
  fileUploadRef.value.init()
};
const editForm = (val) => {
  ruleForm.value = copyForm.value;
  nextTick(() => {
  fileUploadRef.value.editInit(val);
  });
};
defineExpose({
  initForm,
  editForm,
});
const options = [
  { value: "有效", label: "有效" },
  { value: "无效", label: "无效" },
  { value: "作废", label: "作废" },
];
const emit = defineEmits(["submitForm"]);
const emit = defineEmits(["submitForm", "update:modelValue"]);
const modelValue = ref([]);
const submit = async () => {
  // 验证表单
  if (!ruleFormRef.value) return;
@@ -109,19 +128,31 @@
    if (!valid) {
      return;
    }
    ruleForm.value.storageBlobDTO = modelValue.value; // 确保 ruleForm 是最新的
    // 调用 API
    let res = await addOrEditArchive(ruleForm.value);
    console.log("API 响应:", res);
    try {
      const res = await addOrEditArchive(ruleForm.value);
      ElMessage({
        type: "success",
        message: res.msg || "操作成功",
      });
      emit("submitForm", res);
    } catch (error) {
      ElMessage({
        type: "error",
        message: error.msg || "操作失败",
      });
      return;
    }
    // 发送 emit 事件
    emit("submitForm", res);
    console.log("emit submitForm 已发送");
    // 关闭对话框
    centerDialogVisible.value = false;
  } catch (error) {
    console.error("表单验证失败或API调用失败:", error);
    ElMessage({
      type: "error",
      message: error.msg || "操作失败",
    });
  }
};
</script>