From c1660fdb3f8cef30b41705cfbd08e6ef5e95b3bf Mon Sep 17 00:00:00 2001 From: wyx Date: Sat, 18 Feb 2023 09:35:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=B8=8A=E4=BC=A0=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drawers/project/AddCertificate.vue | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/components/drawers/project/AddCertificate.vue b/src/components/drawers/project/AddCertificate.vue index 71698ba6..c9744a9c 100644 --- a/src/components/drawers/project/AddCertificate.vue +++ b/src/components/drawers/project/AddCertificate.vue @@ -372,6 +372,7 @@ import { reactive, toRefs } from "vue"; import CreateCertificate from "../../../components/drawers/project/CreateCertificate"; import { message } from "ant-design-vue"; import * as api from "@/api/index1"; +import { fileUp } from "../../../api/indexEval"; export default { name: "AddCertificate", components: { @@ -587,12 +588,43 @@ export default { } }; - function beforeUpload(file) { - if (!state.fileType.includes(file.name.split(".").slice(-1).join(""))) { - message.error("不支持该格式"); + const beforeUpload = (file) => { + const isJpgOrPng = + file.type === "image/jpg" || + file.type === "image/jpeg" || + file.type === "image/png" || + file.type === "image/svg" || + file.type === "image/bmp" || + file.type === "image/gif"; + if (!isJpgOrPng) { + message.error("仅支持jpg、gif、png、jpeg、svg、bmp格式!"); return false; } - } + + let isLt1M = file.size / 10240 / 10240 <= 1; + if (!isLt1M) { + this.$message.error("图片大小超过10MB!"); + return false; + } + + const formDatas = new FormData(); + formDatas.append("file", file); + fileUp(formDatas).then((res) => { + if (res.data.code === 200) { + console.log(file) + state.imageUrl = res.data.data; + state.imageName = file.name; + } + }); + return false; + }; + + // function beforeUpload(file) { + // if (!state.fileType.includes(file.name.split(".").slice(-1).join(""))) { + // message.error("不支持该格式"); + // return false; + // } + // } //查看证书 const getcertificate = () => {