|
@@ -27,48 +27,47 @@
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<!-- 更换食品经营许可证弹窗 -->
|
|
<!-- 更换食品经营许可证弹窗 -->
|
|
|
- <el-dialog v-model="replaceDialogVisible" title="更换食品经营许可证" width="600px" @close="handleReplaceDialogClose">
|
|
|
|
|
- <div class="replace-upload-area">
|
|
|
|
|
|
|
+ <el-dialog v-model="replaceDialogVisible" title="更换食品经营许可证" width="600px" :before-close="handleReplaceDialogClose">
|
|
|
|
|
+ <div class="replace-upload-area" :class="{ 'upload-full': uploadedImageCount >= 1 }">
|
|
|
<el-upload
|
|
<el-upload
|
|
|
- ref="uploadRef"
|
|
|
|
|
- action="#"
|
|
|
|
|
- :show-file-list="false"
|
|
|
|
|
- :http-request="handleHttpUpload"
|
|
|
|
|
- :before-upload="beforeUpload"
|
|
|
|
|
- drag
|
|
|
|
|
- class="upload-box"
|
|
|
|
|
|
|
+ v-model:file-list="fileList"
|
|
|
|
|
+ list-type="picture-card"
|
|
|
|
|
+ :accept="'.jpg,.png'"
|
|
|
|
|
+ :limit="1"
|
|
|
|
|
+ :auto-upload="false"
|
|
|
|
|
+ :disabled="hasUnuploadedImages"
|
|
|
|
|
+ :on-change="handleUploadChange"
|
|
|
|
|
+ :on-exceed="handleUploadExceed"
|
|
|
|
|
+ :on-preview="handlePictureCardPreview"
|
|
|
|
|
+ :before-remove="handleBeforeRemove"
|
|
|
|
|
+ :on-remove="handleRemove"
|
|
|
|
|
+ :show-file-list="true"
|
|
|
>
|
|
>
|
|
|
- <el-icon class="el-icon--upload">
|
|
|
|
|
- <upload-filled />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
|
|
|
- <template #tip>
|
|
|
|
|
- <div class="upload-tip">({{ uploadedCount }}/1)</div>
|
|
|
|
|
|
|
+ <template #trigger>
|
|
|
|
|
+ <div v-if="uploadedImageCount < 1" class="upload-trigger-card el-upload--picture-card">
|
|
|
|
|
+ <el-icon>
|
|
|
|
|
+ <Plus />
|
|
|
|
|
+ </el-icon>
|
|
|
|
|
+ <div class="upload-tip">({{ uploadedImageCount }}/1)</div>
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
</el-upload>
|
|
</el-upload>
|
|
|
- <div v-if="newLicenseUrl" class="preview-section">
|
|
|
|
|
- <div class="preview-label">预览</div>
|
|
|
|
|
- <el-image :src="newLicenseUrl" fit="contain" class="preview-image" />
|
|
|
|
|
- </div>
|
|
|
|
|
</div>
|
|
</div>
|
|
|
<template #footer>
|
|
<template #footer>
|
|
|
<div class="dialog-footer">
|
|
<div class="dialog-footer">
|
|
|
- <el-button @click="handleCancelReplace"> 取消 </el-button>
|
|
|
|
|
- <el-button type="primary" @click="handleSubmitReplace"> 去审核 </el-button>
|
|
|
|
|
|
|
+ <el-button @click="handleCancelReplace" :disabled="hasUnuploadedImages"> 取消 </el-button>
|
|
|
|
|
+ <el-button type="primary" @click="handleSubmitReplace" :disabled="hasUnuploadedImages"> 去审核 </el-button>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
</el-dialog>
|
|
</el-dialog>
|
|
|
|
|
|
|
|
- <!-- 取消确认弹窗 -->
|
|
|
|
|
- <el-dialog v-model="cancelConfirmVisible" title="提示" width="400px" :close-on-click-modal="false">
|
|
|
|
|
- <div class="confirm-text">确定要取消本次图片上传吗?已上传的图片将不保存</div>
|
|
|
|
|
- <template #footer>
|
|
|
|
|
- <div class="dialog-footer">
|
|
|
|
|
- <el-button @click="cancelConfirmVisible = false"> 取消 </el-button>
|
|
|
|
|
- <el-button type="primary" @click="handleConfirmCancel"> 确定 </el-button>
|
|
|
|
|
- </div>
|
|
|
|
|
- </template>
|
|
|
|
|
- </el-dialog>
|
|
|
|
|
|
|
+ <!-- 图片预览 -->
|
|
|
|
|
+ <el-image-viewer
|
|
|
|
|
+ v-if="imageViewerVisible"
|
|
|
|
|
+ :url-list="imageViewerUrlList"
|
|
|
|
|
+ :initial-index="imageViewerInitialIndex"
|
|
|
|
|
+ @close="imageViewerVisible = false"
|
|
|
|
|
+ />
|
|
|
|
|
|
|
|
<!-- 变更记录弹窗 -->
|
|
<!-- 变更记录弹窗 -->
|
|
|
<el-dialog v-model="changeRecordDialogVisible" title="变更记录" width="900px" :close-on-click-modal="false">
|
|
<el-dialog v-model="changeRecordDialogVisible" title="变更记录" width="900px" :close-on-click-modal="false">
|
|
@@ -77,10 +76,23 @@
|
|
|
{{ currentRecordDate }}
|
|
{{ currentRecordDate }}
|
|
|
</div>
|
|
</div>
|
|
|
<div class="record-items">
|
|
<div class="record-items">
|
|
|
- <div v-for="(item, index) in changeRecordList" :key="index" class="record-item" :class="getStatusClass(item.status)">
|
|
|
|
|
- <div class="record-status-text">
|
|
|
|
|
|
|
+ <div v-for="(item, index) in changeRecordList" :key="index" class="record-item">
|
|
|
|
|
+ <div class="record-status-badge" :class="getStatusClass(item.status)">
|
|
|
{{ getStatusText(item.status) }}
|
|
{{ getStatusText(item.status) }}
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ <el-image
|
|
|
|
|
+ :src="item.imgUrl"
|
|
|
|
|
+ fit="cover"
|
|
|
|
|
+ class="record-image"
|
|
|
|
|
+ :preview-src-list="changeRecordList.map(record => record.imgUrl)"
|
|
|
|
|
+ :initial-index="index"
|
|
|
|
|
+ >
|
|
|
|
|
+ <template #error>
|
|
|
|
|
+ <div class="image-slot">
|
|
|
|
|
+ <el-icon><Picture /></el-icon>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-image>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div v-if="rejectionReason" class="rejection-reason">拒绝原因: {{ rejectionReason }}</div>
|
|
<div v-if="rejectionReason" class="rejection-reason">拒绝原因: {{ rejectionReason }}</div>
|
|
@@ -96,31 +108,57 @@
|
|
|
|
|
|
|
|
<script setup lang="ts" name="foodBusinessLicense">
|
|
<script setup lang="ts" name="foodBusinessLicense">
|
|
|
import { ref, computed, onMounted } from "vue";
|
|
import { ref, computed, onMounted } from "vue";
|
|
|
-import { ElMessage } from "element-plus";
|
|
|
|
|
-import { Picture, UploadFilled } from "@element-plus/icons-vue";
|
|
|
|
|
-import { uploadImg } from "@/api/modules/upload";
|
|
|
|
|
-import type { UploadProps, UploadRequestOptions } from "element-plus";
|
|
|
|
|
-import { getFoodBusinessLicense } from "@/api/modules/licenseManagement";
|
|
|
|
|
|
|
+import { ElMessage, ElMessageBox } from "element-plus";
|
|
|
|
|
+import { Picture, Plus } from "@element-plus/icons-vue";
|
|
|
|
|
+import type { UploadProps, UploadFile } from "element-plus";
|
|
|
|
|
+import { getFoodBusinessLicense, uploadContractImage, submitFoodLicenseReview } from "@/api/modules/licenseManagement";
|
|
|
import { localGet } from "@/utils";
|
|
import { localGet } from "@/utils";
|
|
|
|
|
|
|
|
interface ChangeRecordItem {
|
|
interface ChangeRecordItem {
|
|
|
id: string;
|
|
id: string;
|
|
|
status: "pending" | "success" | "failed";
|
|
status: "pending" | "success" | "failed";
|
|
|
|
|
+ imgUrl: string; // 图片URL
|
|
|
rejectionReason?: string;
|
|
rejectionReason?: string;
|
|
|
}
|
|
}
|
|
|
const id = localGet("createdId");
|
|
const id = localGet("createdId");
|
|
|
|
|
|
|
|
const licenseImage = ref<string>("");
|
|
const licenseImage = ref<string>("");
|
|
|
const replaceDialogVisible = ref(false);
|
|
const replaceDialogVisible = ref(false);
|
|
|
-const cancelConfirmVisible = ref(false);
|
|
|
|
|
const changeRecordDialogVisible = ref(false);
|
|
const changeRecordDialogVisible = ref(false);
|
|
|
-const uploadRef = ref();
|
|
|
|
|
-const newLicenseUrl = ref("");
|
|
|
|
|
|
|
+const fileList = ref<UploadFile[]>([]);
|
|
|
const currentRecordDate = ref("2025.08.01 10:29");
|
|
const currentRecordDate = ref("2025.08.01 10:29");
|
|
|
const changeRecordList = ref<ChangeRecordItem[]>([]);
|
|
const changeRecordList = ref<ChangeRecordItem[]>([]);
|
|
|
const rejectionReason = ref("");
|
|
const rejectionReason = ref("");
|
|
|
|
|
|
|
|
-const uploadedCount = computed(() => (newLicenseUrl.value ? 1 : 0));
|
|
|
|
|
|
|
+// ==================== 图片上传相关变量 ====================
|
|
|
|
|
+const uploading = ref(false);
|
|
|
|
|
+const pendingUploadFiles = ref<UploadFile[]>([]);
|
|
|
|
|
+const imageUrlList = ref<string[]>([]); // 存储图片URL列表
|
|
|
|
|
+
|
|
|
|
|
+// 图片预览相关
|
|
|
|
|
+const imageViewerVisible = ref(false);
|
|
|
|
|
+const imageViewerUrlList = ref<string[]>([]);
|
|
|
|
|
+const imageViewerInitialIndex = ref(0);
|
|
|
|
|
+
|
|
|
|
|
+// 计算属性:获取已成功上传的图片数量
|
|
|
|
|
+const uploadedImageCount = computed(() => {
|
|
|
|
|
+ return fileList.value.filter((file: any) => file.status === "success" && file.url).length;
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+// 计算属性:检查是否有未上传完成的图片
|
|
|
|
|
+const hasUnuploadedImages = computed(() => {
|
|
|
|
|
+ // 检查是否有正在上传的文件
|
|
|
|
|
+ if (uploading.value || pendingUploadFiles.value.length > 0) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 检查文件列表中是否有状态为 "ready"(待上传)或 "uploading"(上传中)的图片
|
|
|
|
|
+ if (fileList.value && fileList.value.length > 0) {
|
|
|
|
|
+ return fileList.value.some((file: any) => {
|
|
|
|
|
+ return file.status === "ready" || file.status === "uploading";
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
|
await initData();
|
|
await initData();
|
|
@@ -130,14 +168,17 @@ const initData = async () => {
|
|
|
const params = {
|
|
const params = {
|
|
|
id: id
|
|
id: id
|
|
|
};
|
|
};
|
|
|
- const res = await getFoodBusinessLicense(params);
|
|
|
|
|
|
|
+ const res: any = await getFoodBusinessLicense(params);
|
|
|
if (res.code === 200) {
|
|
if (res.code === 200) {
|
|
|
licenseImage.value = res.data[0].imgUrl;
|
|
licenseImage.value = res.data[0].imgUrl;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleReplace = () => {
|
|
const handleReplace = () => {
|
|
|
- newLicenseUrl.value = "";
|
|
|
|
|
|
|
+ fileList.value = [];
|
|
|
|
|
+ imageUrlList.value = [];
|
|
|
|
|
+ pendingUploadFiles.value = [];
|
|
|
|
|
+ uploading.value = false;
|
|
|
replaceDialogVisible.value = true;
|
|
replaceDialogVisible.value = true;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -150,8 +191,12 @@ const handleViewChangeRecord = async () => {
|
|
|
// currentRecordDate.value = response.data.date;
|
|
// currentRecordDate.value = response.data.date;
|
|
|
// rejectionReason.value = response.data.rejectionReason || "";
|
|
// rejectionReason.value = response.data.rejectionReason || "";
|
|
|
// }
|
|
// }
|
|
|
- // 模拟数据 - 根据图片,可能是单个记录
|
|
|
|
|
- changeRecordList.value = [{ id: "1", status: "pending" }];
|
|
|
|
|
|
|
+ // 模拟数据(假数据)
|
|
|
|
|
+ changeRecordList.value = [
|
|
|
|
|
+ { id: "1", status: "pending", imgUrl: "https://picsum.photos/150/150?random=1" },
|
|
|
|
|
+ { id: "2", status: "success", imgUrl: "https://picsum.photos/150/150?random=2" },
|
|
|
|
|
+ { id: "3", status: "failed", imgUrl: "https://picsum.photos/150/150?random=3" }
|
|
|
|
|
+ ];
|
|
|
rejectionReason.value = "";
|
|
rejectionReason.value = "";
|
|
|
changeRecordDialogVisible.value = true;
|
|
changeRecordDialogVisible.value = true;
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -159,63 +204,330 @@ const handleViewChangeRecord = async () => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const beforeUpload: UploadProps["beforeUpload"] = rawFile => {
|
|
|
|
|
- const imgSize = rawFile.size / 1024 / 1024 < 10;
|
|
|
|
|
- const imgType = ["image/jpeg", "image/png", "image/gif"].includes(rawFile.type);
|
|
|
|
|
- if (!imgType) {
|
|
|
|
|
- ElMessage.warning("上传图片不符合所需的格式!");
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 检查文件是否在排队中(未上传)
|
|
|
|
|
+ * @param file 文件对象
|
|
|
|
|
+ * @returns 是否在排队中
|
|
|
|
|
+ */
|
|
|
|
|
+const isFilePending = (file: any): boolean => {
|
|
|
|
|
+ // 只检查 ready 状态(排队中),不包括 uploading(正在上传)
|
|
|
|
|
+ if (file.status === "ready") {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 检查是否在待上传队列中
|
|
|
|
|
+ if (pendingUploadFiles.value.some(item => item.uid === file.uid)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 图片上传 - 删除前确认
|
|
|
|
|
+ * @param uploadFile 要删除的文件对象
|
|
|
|
|
+ * @param uploadFiles 当前文件列表
|
|
|
|
|
+ * @returns Promise<boolean>,true 允许删除,false 阻止删除
|
|
|
|
|
+ */
|
|
|
|
|
+const handleBeforeRemove = async (uploadFile: any, uploadFiles: any[]): Promise<boolean> => {
|
|
|
|
|
+ // 如果文件在排队中(未上传),禁止删除
|
|
|
|
|
+ if (isFilePending(uploadFile)) {
|
|
|
|
|
+ ElMessage.warning("图片尚未上传,请等待上传完成后再删除");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- if (!imgSize) {
|
|
|
|
|
- ElMessage.warning("上传图片大小不能超过 10M!");
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ await ElMessageBox.confirm("确定要删除这张图片吗?", "提示", {
|
|
|
|
|
+ confirmButtonText: "确定",
|
|
|
|
|
+ cancelButtonText: "取消",
|
|
|
|
|
+ type: "warning"
|
|
|
|
|
+ });
|
|
|
|
|
+ // 用户确认删除,返回 true 允许删除
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // 用户取消删除,返回 false 阻止删除
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- return true;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const handleHttpUpload = async (options: UploadRequestOptions) => {
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 图片上传 - 移除图片回调(删除成功后调用)
|
|
|
|
|
+ * @param uploadFile 已删除的文件对象
|
|
|
|
|
+ * @param uploadFiles 删除后的文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+const handleRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
|
|
|
|
|
+ // 从被删除的文件对象中获取 url
|
|
|
|
|
+ const file = uploadFile as any;
|
|
|
|
|
+ const imageUrl = file.url;
|
|
|
|
|
+
|
|
|
|
|
+ if (imageUrl) {
|
|
|
|
|
+ // 从 imageUrl 数组中删除对应的 URL
|
|
|
|
|
+ const urlIndex = imageUrlList.value.indexOf(imageUrl);
|
|
|
|
|
+ if (urlIndex > -1) {
|
|
|
|
|
+ imageUrlList.value.splice(urlIndex, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (file.url && file.url.startsWith("blob:")) {
|
|
|
|
|
+ URL.revokeObjectURL(file.url);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 同步文件列表
|
|
|
|
|
+ fileList.value = [...uploadFiles];
|
|
|
|
|
+ // 删除成功后提示
|
|
|
|
|
+ ElMessage.success("图片已删除");
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 上传文件超出限制提示
|
|
|
|
|
+ */
|
|
|
|
|
+const handleUploadExceed: UploadProps["onExceed"] = () => {
|
|
|
|
|
+ ElMessage.warning("最多只能上传1张图片");
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * el-upload 文件变更(选中或移除)
|
|
|
|
|
+ */
|
|
|
|
|
+const handleUploadChange: UploadProps["onChange"] = async (uploadFile, uploadFiles) => {
|
|
|
|
|
+ // 检查文件类型,只允许 jpg 和 png
|
|
|
|
|
+ if (uploadFile.raw) {
|
|
|
|
|
+ const fileType = uploadFile.raw.type.toLowerCase();
|
|
|
|
|
+ const fileName = uploadFile.name.toLowerCase();
|
|
|
|
|
+ const validTypes = ["image/jpeg", "image/jpg", "image/png"];
|
|
|
|
|
+ const validExtensions = [".jpg", ".jpeg", ".png"];
|
|
|
|
|
+
|
|
|
|
|
+ // 检查 MIME 类型或文件扩展名
|
|
|
|
|
+ const isValidType = validTypes.includes(fileType) || validExtensions.some(ext => fileName.endsWith(ext));
|
|
|
|
|
+
|
|
|
|
|
+ if (!isValidType) {
|
|
|
|
|
+ // 从文件列表中移除不符合类型的文件
|
|
|
|
|
+ const index = fileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
|
|
|
|
|
+ if (index > -1) {
|
|
|
|
|
+ fileList.value.splice(index, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 从 uploadFiles 中移除
|
|
|
|
|
+ const uploadIndex = uploadFiles.findIndex((f: any) => f.uid === uploadFile.uid);
|
|
|
|
|
+ if (uploadIndex > -1) {
|
|
|
|
|
+ uploadFiles.splice(uploadIndex, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果文件有 blob URL,释放它
|
|
|
|
|
+ if (uploadFile.url && uploadFile.url.startsWith("blob:")) {
|
|
|
|
|
+ URL.revokeObjectURL(uploadFile.url);
|
|
|
|
|
+ }
|
|
|
|
|
+ ElMessage.warning("只支持上传 JPG 和 PNG 格式的图片");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 同步文件列表到表单数据(只添加通过验证的文件)
|
|
|
|
|
+ const existingIndex = fileList.value.findIndex((f: any) => f.uid === uploadFile.uid);
|
|
|
|
|
+ if (existingIndex === -1) {
|
|
|
|
|
+ fileList.value.push(uploadFile);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const readyFiles = fileList.value.filter(file => file.status === "ready");
|
|
|
|
|
+ if (readyFiles.length) {
|
|
|
|
|
+ readyFiles.forEach(file => {
|
|
|
|
|
+ if (!pendingUploadFiles.value.some(item => item.uid === file.uid)) {
|
|
|
|
|
+ pendingUploadFiles.value.push(file);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ processUploadQueue();
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 处理上传队列 - 逐个上传文件
|
|
|
|
|
+ */
|
|
|
|
|
+const processUploadQueue = async () => {
|
|
|
|
|
+ if (uploading.value || pendingUploadFiles.value.length === 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 每次只取一个文件进行上传
|
|
|
|
|
+ const file = pendingUploadFiles.value.shift();
|
|
|
|
|
+ if (file) {
|
|
|
|
|
+ await uploadSingleFile(file);
|
|
|
|
|
+ // 继续处理队列中的下一个文件
|
|
|
|
|
+ processUploadQueue();
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 单文件上传图片
|
|
|
|
|
+ * @param file 待上传的文件
|
|
|
|
|
+ */
|
|
|
|
|
+const uploadSingleFile = async (file: UploadFile) => {
|
|
|
|
|
+ if (!file.raw) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const rawFile = file.raw as File;
|
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
|
- formData.append("file", options.file);
|
|
|
|
|
|
|
+ formData.append("file", rawFile);
|
|
|
|
|
+ formData.append("user", "text");
|
|
|
|
|
+ file.status = "uploading";
|
|
|
|
|
+ file.percentage = 0;
|
|
|
|
|
+ uploading.value = true;
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
- const { data } = await uploadImg(formData);
|
|
|
|
|
- newLicenseUrl.value = data.fileUrl ? data.fileUrl : data[0];
|
|
|
|
|
- ElMessage.success("上传成功");
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- ElMessage.error("上传失败");
|
|
|
|
|
|
|
+ // 上传过程中保持进度为 0,避免接口异常时进度条误显示 100%
|
|
|
|
|
+ const result: any = await uploadContractImage(formData);
|
|
|
|
|
+ if (result?.code === 200 && result.data) {
|
|
|
|
|
+ // 处理单个文件的上传结果
|
|
|
|
|
+ let imageUrl = result.data[0];
|
|
|
|
|
+ if (!imageUrl) {
|
|
|
|
|
+ throw new Error("上传成功但未获取到图片URL");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ file.status = "success";
|
|
|
|
|
+ file.percentage = 100;
|
|
|
|
|
+ // 保存图片URL到文件对象
|
|
|
|
|
+ file.url = imageUrl;
|
|
|
|
|
+ file.response = { url: imageUrl };
|
|
|
|
|
+
|
|
|
|
|
+ // 保存图片URL
|
|
|
|
|
+ if (!Array.isArray(imageUrlList.value)) {
|
|
|
|
|
+ imageUrlList.value = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!imageUrlList.value.includes(imageUrl)) {
|
|
|
|
|
+ imageUrlList.value.push(imageUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new Error(result?.msg || "图片上传失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error: any) {
|
|
|
|
|
+ file.status = "fail";
|
|
|
|
|
+ // 上传失败时保持进度条为 0
|
|
|
|
|
+ file.percentage = 0;
|
|
|
|
|
+ if (file.url && file.url.startsWith("blob:")) {
|
|
|
|
|
+ URL.revokeObjectURL(file.url);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 从文件列表中移除失败的文件
|
|
|
|
|
+ const index = fileList.value.findIndex((f: any) => f.uid === file.uid);
|
|
|
|
|
+ if (index > -1) {
|
|
|
|
|
+ fileList.value.splice(index, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ // Error message handled by global upload method, except for specific business logic errors
|
|
|
|
|
+ if (error?.message && error.message.includes("未获取到图片URL")) {
|
|
|
|
|
+ ElMessage.error(error.message);
|
|
|
|
|
+ }
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ uploading.value = false;
|
|
|
|
|
+ // 触发视图更新
|
|
|
|
|
+ fileList.value = [...fileList.value];
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const handleCancelReplace = () => {
|
|
|
|
|
- if (newLicenseUrl.value) {
|
|
|
|
|
- cancelConfirmVisible.value = true;
|
|
|
|
|
- } else {
|
|
|
|
|
- replaceDialogVisible.value = false;
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 图片预览 - 使用 el-image-viewer 预览功能
|
|
|
|
|
+ * @param file 上传文件对象
|
|
|
|
|
+ */
|
|
|
|
|
+const handlePictureCardPreview = (file: any) => {
|
|
|
|
|
+ // 如果文件在排队中(未上传),禁止预览
|
|
|
|
|
+ if (isFilePending(file)) {
|
|
|
|
|
+ ElMessage.warning("图片尚未上传,请等待上传完成后再预览");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果文件正在上传中,允许预览(使用本地预览)
|
|
|
|
|
+ if (file.status === "uploading" && file.url) {
|
|
|
|
|
+ imageViewerUrlList.value = [file.url];
|
|
|
|
|
+ imageViewerInitialIndex.value = 0;
|
|
|
|
|
+ imageViewerVisible.value = true;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取所有图片的 URL 列表(只包含已上传成功的图片)
|
|
|
|
|
+ const urlList = fileList.value
|
|
|
|
|
+ .filter((item: any) => item.status === "success" && (item.url || item.response?.data))
|
|
|
|
|
+ .map((item: any) => item.url || item.response?.data);
|
|
|
|
|
+ // 找到当前点击的图片索引
|
|
|
|
|
+ const currentIndex = urlList.findIndex((url: string) => url === (file.url || file.response?.data));
|
|
|
|
|
+ if (currentIndex < 0) {
|
|
|
|
|
+ ElMessage.warning("图片尚未上传完成,无法预览");
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+ imageViewerUrlList.value = urlList;
|
|
|
|
|
+ imageViewerInitialIndex.value = currentIndex;
|
|
|
|
|
+ imageViewerVisible.value = true;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const handleConfirmCancel = () => {
|
|
|
|
|
- newLicenseUrl.value = "";
|
|
|
|
|
- cancelConfirmVisible.value = false;
|
|
|
|
|
- replaceDialogVisible.value = false;
|
|
|
|
|
|
|
+const handleCancelReplace = async () => {
|
|
|
|
|
+ // 如果有图片正在上传,阻止关闭
|
|
|
|
|
+ if (hasUnuploadedImages.value) {
|
|
|
|
|
+ ElMessage.warning("请等待图片上传完成后再关闭");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fileList.value.length > 0) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await ElMessageBox.confirm("确定要取消本次图片上传吗?已上传的图片将不保存", "提示", {
|
|
|
|
|
+ confirmButtonText: "确定",
|
|
|
|
|
+ cancelButtonText: "取消",
|
|
|
|
|
+ type: "warning"
|
|
|
|
|
+ });
|
|
|
|
|
+ // 用户确认取消
|
|
|
|
|
+ fileList.value = [];
|
|
|
|
|
+ imageUrlList.value = [];
|
|
|
|
|
+ pendingUploadFiles.value = [];
|
|
|
|
|
+ uploading.value = false;
|
|
|
|
|
+ replaceDialogVisible.value = false;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // 用户取消操作,不做任何处理
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ replaceDialogVisible.value = false;
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const handleReplaceDialogClose = () => {
|
|
|
|
|
- if (newLicenseUrl.value) {
|
|
|
|
|
- cancelConfirmVisible.value = true;
|
|
|
|
|
|
|
+const handleReplaceDialogClose = async (done: () => void) => {
|
|
|
|
|
+ // 如果有图片正在上传,阻止关闭
|
|
|
|
|
+ if (hasUnuploadedImages.value) {
|
|
|
|
|
+ ElMessage.warning("请等待图片上传完成后再关闭");
|
|
|
|
|
+ return; // 不调用 done(),阻止关闭弹窗
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fileList.value.length > 0) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await ElMessageBox.confirm("确定要取消本次图片上传吗?已上传的图片将不保存", "提示", {
|
|
|
|
|
+ confirmButtonText: "确定",
|
|
|
|
|
+ cancelButtonText: "取消",
|
|
|
|
|
+ type: "warning"
|
|
|
|
|
+ });
|
|
|
|
|
+ // 用户确认取消,清空数据并关闭弹窗
|
|
|
|
|
+ fileList.value = [];
|
|
|
|
|
+ imageUrlList.value = [];
|
|
|
|
|
+ pendingUploadFiles.value = [];
|
|
|
|
|
+ uploading.value = false;
|
|
|
|
|
+ done(); // 调用 done() 允许关闭弹窗
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // 用户取消操作,不调用 done(),阻止关闭弹窗
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 没有文件,直接关闭
|
|
|
|
|
+ done();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleSubmitReplace = async () => {
|
|
const handleSubmitReplace = async () => {
|
|
|
- if (!newLicenseUrl.value) {
|
|
|
|
|
|
|
+ // 检查是否有未上传完成的图片
|
|
|
|
|
+ if (hasUnuploadedImages.value) {
|
|
|
|
|
+ ElMessage.warning("请等待图片上传完成后再提交");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fileList.value.length === 0) {
|
|
|
|
|
+ ElMessage.warning("请先上传图片");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const uploadedFiles = fileList.value.filter(file => file.status === "success");
|
|
|
|
|
+ if (uploadedFiles.length === 0) {
|
|
|
ElMessage.warning("请先上传图片");
|
|
ElMessage.warning("请先上传图片");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- // TODO: 调用API提交审核
|
|
|
|
|
- // await submitFoodLicenseReview(newLicenseUrl.value);
|
|
|
|
|
|
|
+ // 只提交单张图片,排序为0
|
|
|
|
|
+ const imageDataWithSort = uploadedFiles.map((file, index) => ({
|
|
|
|
|
+ url: file.url,
|
|
|
|
|
+ sort: index
|
|
|
|
|
+ }));
|
|
|
|
|
+ await submitFoodLicenseReview({ images: imageDataWithSort });
|
|
|
ElMessage.success("提交审核成功");
|
|
ElMessage.success("提交审核成功");
|
|
|
replaceDialogVisible.value = false;
|
|
replaceDialogVisible.value = false;
|
|
|
- newLicenseUrl.value = "";
|
|
|
|
|
|
|
+ fileList.value = [];
|
|
|
|
|
+ imageUrlList.value = [];
|
|
|
|
|
+ pendingUploadFiles.value = [];
|
|
|
|
|
+ uploading.value = false;
|
|
|
await initData();
|
|
await initData();
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
ElMessage.error("提交审核失败");
|
|
ElMessage.error("提交审核失败");
|
|
@@ -223,11 +535,12 @@ const handleSubmitReplace = async () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const getStatusClass = (status: string) => {
|
|
const getStatusClass = (status: string) => {
|
|
|
- return {
|
|
|
|
|
- "status-pending": status === "pending",
|
|
|
|
|
- "status-success": status === "success",
|
|
|
|
|
- "status-failed": status === "failed"
|
|
|
|
|
|
|
+ const statusMap: Record<string, string> = {
|
|
|
|
|
+ pending: "status-pending",
|
|
|
|
|
+ success: "status-success",
|
|
|
|
|
+ failed: "status-failed"
|
|
|
};
|
|
};
|
|
|
|
|
+ return statusMap[status] || "";
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const getStatusText = (status: string) => {
|
|
const getStatusText = (status: string) => {
|
|
@@ -300,38 +613,75 @@ const getStatusText = (status: string) => {
|
|
|
}
|
|
}
|
|
|
.replace-upload-area {
|
|
.replace-upload-area {
|
|
|
min-height: 300px;
|
|
min-height: 300px;
|
|
|
- padding: 20px 0;
|
|
|
|
|
- .upload-box {
|
|
|
|
|
- width: 100%;
|
|
|
|
|
- min-height: 200px;
|
|
|
|
|
|
|
+ padding: 20px;
|
|
|
|
|
+ :deep(.el-upload-list--picture-card .el-upload-list__item:hover .el-upload-list__item-status-label) {
|
|
|
|
|
+ display: inline-flex !important;
|
|
|
|
|
+ opacity: 1 !important;
|
|
|
}
|
|
}
|
|
|
- .upload-tip {
|
|
|
|
|
- margin-top: 10px;
|
|
|
|
|
- font-size: 14px;
|
|
|
|
|
- color: var(--el-text-color-secondary);
|
|
|
|
|
- text-align: center;
|
|
|
|
|
|
|
+ :deep(.el-upload-list__item.is-success:focus .el-upload-list__item-status-label) {
|
|
|
|
|
+ display: inline-flex !important;
|
|
|
|
|
+ opacity: 1 !important;
|
|
|
}
|
|
}
|
|
|
- .preview-section {
|
|
|
|
|
- padding: 20px;
|
|
|
|
|
- margin-top: 30px;
|
|
|
|
|
- background-color: var(--el-fill-color-lighter);
|
|
|
|
|
- border-radius: 8px;
|
|
|
|
|
- .preview-label {
|
|
|
|
|
- margin-bottom: 15px;
|
|
|
|
|
- font-size: 14px;
|
|
|
|
|
- color: var(--el-text-color-secondary);
|
|
|
|
|
|
|
+ :deep(.el-upload-list--picture-card .el-icon--close-tip) {
|
|
|
|
|
+ display: none !important;
|
|
|
|
|
+ }
|
|
|
|
|
+ &.upload-full {
|
|
|
|
|
+ :deep(.el-upload--picture-card) {
|
|
|
|
|
+ display: none !important;
|
|
|
}
|
|
}
|
|
|
- .preview-image {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+.dialog-footer {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ gap: 10px;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* el-upload 图片预览铺满容器 */
|
|
|
|
|
+:deep(.el-upload-list--picture-card) {
|
|
|
|
|
+ .el-upload-list__item {
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ .el-upload-list__item-thumbnail {
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
- max-height: 300px;
|
|
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ object-fit: fill;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* 排队中(未上传)的图片禁用样式 */
|
|
|
|
|
+ .el-upload-list__item[data-status="ready"],
|
|
|
|
|
+ .el-upload-list__item.is-ready {
|
|
|
|
|
+ position: relative;
|
|
|
|
|
+ pointer-events: none;
|
|
|
|
|
+ cursor: not-allowed;
|
|
|
|
|
+ opacity: 0.6;
|
|
|
|
|
+ &::after {
|
|
|
|
|
+ position: absolute;
|
|
|
|
|
+ inset: 0;
|
|
|
|
|
+ z-index: 1;
|
|
|
|
|
+ content: "";
|
|
|
|
|
+ background-color: rgb(0 0 0 / 30%);
|
|
|
|
|
+ }
|
|
|
|
|
+ .el-upload-list__item-actions {
|
|
|
|
|
+ pointer-events: none;
|
|
|
|
|
+ opacity: 0.5;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-.confirm-text {
|
|
|
|
|
- padding: 10px 0;
|
|
|
|
|
- font-size: 14px;
|
|
|
|
|
- line-height: 1.6;
|
|
|
|
|
- color: var(--el-text-color-primary);
|
|
|
|
|
|
|
+.upload-trigger-card {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ font-size: 28px;
|
|
|
|
|
+ color: #8c939d;
|
|
|
|
|
+ .upload-tip {
|
|
|
|
|
+ margin-top: 8px;
|
|
|
|
|
+ font-size: 14px;
|
|
|
|
|
+ color: #8c939d;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
.change-record-content {
|
|
.change-record-content {
|
|
|
padding: 20px 0;
|
|
padding: 20px 0;
|
|
@@ -348,32 +698,51 @@ const getStatusText = (status: string) => {
|
|
|
margin-bottom: 20px;
|
|
margin-bottom: 20px;
|
|
|
}
|
|
}
|
|
|
.record-item {
|
|
.record-item {
|
|
|
- display: flex;
|
|
|
|
|
- align-items: center;
|
|
|
|
|
- justify-content: center;
|
|
|
|
|
|
|
+ position: relative;
|
|
|
width: 150px;
|
|
width: 150px;
|
|
|
- height: 100px;
|
|
|
|
|
- background-color: var(--el-fill-color-lighter);
|
|
|
|
|
- border: 1px solid var(--el-border-color-light);
|
|
|
|
|
|
|
+ height: 150px;
|
|
|
|
|
+ overflow: hidden;
|
|
|
border-radius: 8px;
|
|
border-radius: 8px;
|
|
|
- .record-status-text {
|
|
|
|
|
- font-size: 14px;
|
|
|
|
|
|
|
+ .record-status-badge {
|
|
|
|
|
+ position: absolute;
|
|
|
|
|
+ right: 0;
|
|
|
|
|
+ bottom: 0;
|
|
|
|
|
+ left: 0;
|
|
|
|
|
+ z-index: 1;
|
|
|
|
|
+ padding: 4px 8px;
|
|
|
|
|
+ font-size: 12px;
|
|
|
font-weight: 500;
|
|
font-weight: 500;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ border-radius: 0 0 8px 8px;
|
|
|
|
|
+ &.status-pending {
|
|
|
|
|
+ color: #e6a23c;
|
|
|
|
|
+ background-color: rgb(253 246 236 / 95%);
|
|
|
|
|
+ border-top: 1px solid #e6a23c;
|
|
|
|
|
+ }
|
|
|
|
|
+ &.status-success {
|
|
|
|
|
+ color: #67c23a;
|
|
|
|
|
+ background-color: rgb(240 249 255 / 95%);
|
|
|
|
|
+ border-top: 1px solid #67c23a;
|
|
|
|
|
+ }
|
|
|
|
|
+ &.status-failed {
|
|
|
|
|
+ color: #f56c6c;
|
|
|
|
|
+ background-color: rgb(254 240 240 / 95%);
|
|
|
|
|
+ border-top: 1px solid #f56c6c;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- &.status-pending {
|
|
|
|
|
- color: #e6a23c;
|
|
|
|
|
- background-color: #fdf6ec;
|
|
|
|
|
- border-color: #e6a23c;
|
|
|
|
|
- }
|
|
|
|
|
- &.status-success {
|
|
|
|
|
- color: #67c23a;
|
|
|
|
|
- background-color: #f0f9ff;
|
|
|
|
|
- border-color: #67c23a;
|
|
|
|
|
- }
|
|
|
|
|
- &.status-failed {
|
|
|
|
|
- color: #f56c6c;
|
|
|
|
|
- background-color: #fef0f0;
|
|
|
|
|
- border-color: #f56c6c;
|
|
|
|
|
|
|
+ .record-image {
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ .image-slot {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ font-size: 30px;
|
|
|
|
|
+ color: var(--el-text-color-placeholder);
|
|
|
|
|
+ background: var(--el-fill-color-light);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
.rejection-reason {
|
|
.rejection-reason {
|