refactor: 精简出库上链批量导入页
This commit is contained in:
@@ -1,112 +1,54 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<n-card :bordered="false">
|
||||
<n-tabs type="line" animated>
|
||||
<!-- 单条录入 -->
|
||||
<n-tab-pane name="single" :tab="t('pages.outbound.single')">
|
||||
<n-form label-placement="top" style="max-width: 560px">
|
||||
<n-form-item :label="t('pages.outbound.selectCode')" required>
|
||||
<n-select
|
||||
v-model:value="form.traceCodeId"
|
||||
filterable
|
||||
remote
|
||||
clearable
|
||||
:loading="searching"
|
||||
:options="codeOptions"
|
||||
:placeholder="t('pages.outbound.selectCodePlaceholder')"
|
||||
@search="searchCodes"
|
||||
@update:value="onPickCode"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-grid :cols="2" :x-gap="16">
|
||||
<n-form-item-gi :label="t('pages.outbound.outTime')">
|
||||
<n-date-picker v-model:formatted-value="form.outTime" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi :label="t('common.label.remark')">
|
||||
<n-input v-model:value="form.remark" />
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
<n-form-item :label="t('pages.outbound.outImage')">
|
||||
<media-upload v-model="outImages" type="image" :max="1" />
|
||||
</n-form-item>
|
||||
<n-card :title="t('pages.outbound.import')" :bordered="false">
|
||||
<n-alert type="info" :show-icon="true" style="margin-bottom: 16px">
|
||||
{{ t('pages.outbound.tip') }}
|
||||
</n-alert>
|
||||
<n-space>
|
||||
<n-button @click="downloadTemplate">
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('common.action.downloadTemplate') }}
|
||||
</n-button>
|
||||
<n-upload
|
||||
:show-file-list="false"
|
||||
accept=".xlsx,.xls"
|
||||
:custom-request="doImport"
|
||||
:disabled="importing || !auth.canWrite"
|
||||
>
|
||||
<n-button type="primary" :loading="importing">
|
||||
<template #icon><n-icon :component="CloudUploadOutline" /></template>
|
||||
{{ t('pages.outbound.selectFile') }}
|
||||
</n-button>
|
||||
</n-upload>
|
||||
</n-space>
|
||||
|
||||
<n-divider style="margin: 4px 0 14px">{{ t('pages.outbound.onchainSection') }}</n-divider>
|
||||
<n-grid :cols="2" :x-gap="16">
|
||||
<n-form-item-gi span="2" :label="t('pages.blockchain.txHash')">
|
||||
<n-input v-model:value="form.txHash" :placeholder="t('pages.outbound.txHashTip')" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi :label="t('pages.blockchain.onchainAt')">
|
||||
<n-date-picker v-model:formatted-value="form.onchainAt" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi span="2">
|
||||
<n-collapse>
|
||||
<n-collapse-item :title="t('pages.outbound.moreOnchainInfo')" name="more-onchain">
|
||||
<n-form-item :label="t('pages.blockchain.blockHeight')">
|
||||
<n-input-number v-model:value="form.blockHeight" :min="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
</n-collapse-item>
|
||||
</n-collapse>
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
|
||||
<n-button type="primary" :loading="saving" :disabled="!auth.canWrite || !form.traceCodeId" @click="saveSingle">
|
||||
{{ t('common.action.save') }}
|
||||
</n-button>
|
||||
</n-form>
|
||||
</n-tab-pane>
|
||||
|
||||
<!-- 批量导入 -->
|
||||
<n-tab-pane name="import" :tab="t('pages.outbound.import')">
|
||||
<n-alert type="info" :show-icon="true" style="margin-bottom: 16px">{{ t('pages.outbound.tip') }}</n-alert>
|
||||
<n-space>
|
||||
<n-button @click="downloadTemplate">
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('common.action.downloadTemplate') }}
|
||||
</n-button>
|
||||
<n-upload
|
||||
:show-file-list="false"
|
||||
accept=".xlsx,.xls"
|
||||
:custom-request="doImport"
|
||||
:disabled="importing || !auth.canWrite"
|
||||
>
|
||||
<n-button type="primary" :loading="importing">
|
||||
<template #icon><n-icon :component="CloudUploadOutline" /></template>
|
||||
{{ t('pages.outbound.selectFile') }}
|
||||
</n-button>
|
||||
</n-upload>
|
||||
</n-space>
|
||||
|
||||
<n-card v-if="result" embedded :title="t('pages.outbound.importResult')" style="margin-top: 16px">
|
||||
<n-space align="center" size="large">
|
||||
<n-statistic :label="t('common.label.total', { n: result.total })" :value="result.total" />
|
||||
<n-statistic :label="t('pages.outbound.successCount')">
|
||||
<span style="color: #138a72">{{ result.successCount }}</span>
|
||||
</n-statistic>
|
||||
<n-statistic :label="t('pages.outbound.failCount')">
|
||||
<span style="color: #c0392b">{{ result.failCount }}</span>
|
||||
</n-statistic>
|
||||
<n-tag :type="statusType(result.status)">{{ t(`common.status.${result.status}`) }}</n-tag>
|
||||
<n-button v-if="result.resultFileUrl" text tag="a" :href="result.resultFileUrl" target="_blank" type="primary">
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('pages.outbound.downloadResult') }}
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-card>
|
||||
</n-tab-pane>
|
||||
</n-tabs>
|
||||
<n-card v-if="result" embedded :title="t('pages.outbound.importResult')" style="margin-top: 16px">
|
||||
<n-space align="center" size="large">
|
||||
<n-statistic :label="t('common.label.total', { n: result.total })" :value="result.total" />
|
||||
<n-statistic :label="t('pages.outbound.successCount')">
|
||||
<span style="color: #138a72">{{ result.successCount }}</span>
|
||||
</n-statistic>
|
||||
<n-statistic :label="t('pages.outbound.failCount')">
|
||||
<span style="color: #c0392b">{{ result.failCount }}</span>
|
||||
</n-statistic>
|
||||
<n-tag :type="statusType(result.status)">{{ t(`common.status.${result.status}`) }}</n-tag>
|
||||
<n-button v-if="result.resultFileUrl" text tag="a" :href="result.resultFileUrl" target="_blank" type="primary">
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('pages.outbound.downloadResult') }}
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-card>
|
||||
</n-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from 'vue';
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { UploadCustomRequestOptions } from 'naive-ui';
|
||||
import { DownloadOutline, CloudUploadOutline } from '@vicons/ionicons5';
|
||||
import dayjs from 'dayjs';
|
||||
import { jobApi, outboundApi, traceCodeApi, post } from '@/api';
|
||||
import { jobApi, post } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
import { message } from '@/utils/feedback';
|
||||
import { statusType } from '@/utils/format';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
@@ -114,117 +56,13 @@ import { downloadFile } from '@/utils/download';
|
||||
const { t } = useI18n();
|
||||
const auth = useAuthStore();
|
||||
|
||||
/* 单条录入 */
|
||||
const saving = ref(false);
|
||||
const searching = ref(false);
|
||||
const codeOptions = ref<{ label: string; value: string; raw: any }[]>([]);
|
||||
const outImages = ref<any[]>([]);
|
||||
const form = reactive<any>({
|
||||
traceCodeId: null,
|
||||
outTime: null,
|
||||
remark: '',
|
||||
txHash: '',
|
||||
onchainAt: null,
|
||||
blockHeight: null,
|
||||
});
|
||||
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let searchSeq = 0;
|
||||
|
||||
function formatDateTime(value?: string | Date | null) {
|
||||
return value ? dayjs(value).format('YYYY-MM-DD HH:mm') : null;
|
||||
}
|
||||
|
||||
function toNumber(value: unknown) {
|
||||
if (value === null || value === undefined || value === '') return null;
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
|
||||
function fileName(key: string) {
|
||||
return key.split('/').pop() || key;
|
||||
}
|
||||
|
||||
function codeLabel(c: any) {
|
||||
return [
|
||||
c.shortCode,
|
||||
c.artwork?.archiveNo,
|
||||
c.artwork?.title,
|
||||
c.batch?.batchNo,
|
||||
].filter(Boolean).join(' · ');
|
||||
}
|
||||
|
||||
function resetCodeDetail() {
|
||||
form.outTime = null;
|
||||
form.remark = '';
|
||||
form.txHash = '';
|
||||
form.onchainAt = null;
|
||||
form.blockHeight = null;
|
||||
outImages.value = [];
|
||||
}
|
||||
|
||||
async function loadCodeOptions(keyword = '') {
|
||||
const seq = ++searchSeq;
|
||||
searching.value = true;
|
||||
try {
|
||||
const res: any = await traceCodeApi.list({ keyword: keyword || undefined, pageSize: 20 });
|
||||
if (seq !== searchSeq) return;
|
||||
codeOptions.value = res.list.map((c: any) => ({
|
||||
label: codeLabel(c),
|
||||
value: String(c.id),
|
||||
raw: c,
|
||||
}));
|
||||
} finally {
|
||||
if (seq === searchSeq) searching.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function searchCodes(keyword: string) {
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
searchTimer = setTimeout(() => loadCodeOptions(keyword), 300);
|
||||
}
|
||||
|
||||
function onPickCode(id: string | null, opt: any) {
|
||||
if (!id) {
|
||||
resetCodeDetail();
|
||||
return;
|
||||
}
|
||||
const c = opt?.raw;
|
||||
if (!c) return;
|
||||
const latestProof = c.latestProof;
|
||||
form.outTime = formatDateTime(c.outTime);
|
||||
form.remark = c.remark || '';
|
||||
form.txHash = latestProof?.txHash || '';
|
||||
form.onchainAt = formatDateTime(latestProof?.onchainAt);
|
||||
form.blockHeight = toNumber(latestProof?.blockHeight);
|
||||
outImages.value = c.outImage ? [{ key: c.outImage, url: c.outImageUrl || c.outImage, name: fileName(c.outImage) }] : [];
|
||||
}
|
||||
|
||||
async function saveSingle() {
|
||||
if (!form.traceCodeId) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
await outboundApi.updateSingle(form.traceCodeId, {
|
||||
outTime: form.outTime ? dayjs(form.outTime).toISOString() : null,
|
||||
outImageKey: outImages.value[0]?.key ?? null,
|
||||
txHash: form.txHash || undefined,
|
||||
onchainAt: form.onchainAt ? dayjs(form.onchainAt).toISOString() : undefined,
|
||||
blockHeight: form.blockHeight ?? undefined,
|
||||
remark: form.remark || null,
|
||||
});
|
||||
message.success(t('common.msg.saved'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* 批量导入 */
|
||||
const importing = ref(false);
|
||||
const result = ref<any>(null);
|
||||
|
||||
async function downloadTemplate() {
|
||||
await downloadFile('/outbound/import/template', 'outbound-import-template.xlsx');
|
||||
}
|
||||
|
||||
async function doImport({ file, onFinish, onError }: UploadCustomRequestOptions) {
|
||||
importing.value = true;
|
||||
result.value = null;
|
||||
@@ -249,12 +87,4 @@ async function doImport({ file, onFinish, onError }: UploadCustomRequestOptions)
|
||||
importing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadCodeOptions();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user