mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
feat(m2): add contract attachment upload and listing
This commit is contained in:
@@ -3,6 +3,18 @@ import axios from "axios";
|
||||
/**
|
||||
* @param {{ page?: number, size?: number, keyword?: string }} params
|
||||
*/
|
||||
export function uploadContractAttachment(contractId, file) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return axios.post(`/api/v1/contracts/${contractId}/attachments`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
});
|
||||
}
|
||||
|
||||
export function listContractAttachments(contractId) {
|
||||
return axios.get(`/api/v1/contracts/${contractId}/attachments`);
|
||||
}
|
||||
|
||||
export function listCustomers(params) {
|
||||
return axios.get("/api/v1/customers", { params });
|
||||
}
|
||||
|
||||
@@ -62,6 +62,26 @@
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<h3 class="section-title">附件</h3>
|
||||
<div>
|
||||
<el-upload
|
||||
:action="''"
|
||||
:auto-upload="false"
|
||||
:show-file-list="false"
|
||||
:on-change="handleFileChange"
|
||||
:accept="'.pdf,.doc,.docx,.xls,.xlsx,.zip'"
|
||||
>
|
||||
<el-button type="primary" v-if="isDraft || isEffective">上传附件</el-button>
|
||||
</el-upload>
|
||||
<el-table :data="attachments" stripe size="small" style="margin-top:8px">
|
||||
<el-table-column prop="fileName" label="文件名" min-width="200" />
|
||||
<el-table-column prop="fileSize" label="大小" width="100">
|
||||
<template #default="{ row }">{{ (row.fileSize / 1024).toFixed(1) }} KB</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createdAt" label="上传时间" width="170" />
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<h3 class="section-title">最近审计</h3>
|
||||
<el-table v-loading="auditLoading" :data="auditRows" border stripe size="small" style="width: 100%">
|
||||
<el-table-column label="时间" width="180">
|
||||
@@ -110,6 +130,8 @@ import {
|
||||
listAuditEvents,
|
||||
listCustomers,
|
||||
listProjects,
|
||||
uploadContractAttachment,
|
||||
listContractAttachments,
|
||||
} from "../api/platform";
|
||||
import { apiErrorMessage } from "../utils/apiErrorMessage";
|
||||
|
||||
@@ -131,6 +153,9 @@ const form = reactive({
|
||||
const auditLoading = ref(false);
|
||||
const auditRows = ref([]);
|
||||
|
||||
const attachments = ref([]);
|
||||
const uploading = ref(false);
|
||||
|
||||
const lineDialogVisible = ref(false);
|
||||
const lineEditingId = ref(null);
|
||||
const lineFormRef = ref(null);
|
||||
@@ -150,6 +175,7 @@ const transitionLoading = ref("");
|
||||
const contractId = computed(() => route.params.id);
|
||||
|
||||
const isDraft = computed(() => String(contract.value?.status ?? "").toUpperCase() === "DRAFT");
|
||||
const isEffective = computed(() => String(contract.value?.status ?? "").toUpperCase() === "EFFECTIVE");
|
||||
|
||||
const lineRows = computed(() => {
|
||||
const c = contract.value;
|
||||
@@ -196,6 +222,7 @@ onMounted(async () => {
|
||||
auth.restoreAxiosAuth();
|
||||
await loadNameMaps();
|
||||
await refreshAll();
|
||||
await loadAttachments();
|
||||
});
|
||||
|
||||
watch(
|
||||
@@ -459,6 +486,26 @@ function onTransition(btn) {
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
async function loadAttachments() {
|
||||
try {
|
||||
const { data } = await listContractAttachments(route.params.id);
|
||||
attachments.value = data || [];
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
async function handleFileChange(uploadFile) {
|
||||
uploading.value = true;
|
||||
try {
|
||||
await uploadContractAttachment(route.params.id, uploadFile.raw);
|
||||
ElMessage.success('上传成功');
|
||||
loadAttachments();
|
||||
} catch (e) {
|
||||
ElMessage.error(apiErrorMessage(e, '上传失败'));
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user