197 lines
7.6 KiB
Vue
197 lines
7.6 KiB
Vue
<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-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 :label="t('pages.blockchain.blockHeight')">
|
|
<n-input-number v-model:value="form.blockHeight" :min="0" style="width: 100%" />
|
|
</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>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { reactive, ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type { UploadCustomRequestOptions } from 'naive-ui';
|
|
import { DownloadOutline, CloudUploadOutline } from '@vicons/ionicons5';
|
|
import { jobApi, outboundApi, traceCodeApi, 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';
|
|
|
|
const { t } = useI18n();
|
|
const auth = useAuthStore();
|
|
|
|
/* 单条录入 */
|
|
const saving = ref(false);
|
|
const searching = ref(false);
|
|
const codeOptions = ref<{ label: string; value: string }[]>([]);
|
|
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;
|
|
function searchCodes(keyword: string) {
|
|
if (searchTimer) clearTimeout(searchTimer);
|
|
searchTimer = setTimeout(async () => {
|
|
searching.value = true;
|
|
try {
|
|
const res: any = await traceCodeApi.list({ keyword: keyword || undefined, pageSize: 20 });
|
|
codeOptions.value = res.list.map((c: any) => ({
|
|
label: `${c.shortCode}${c.artwork ? ' · ' + (c.artwork.archiveNo || c.artwork.title) : ''}`,
|
|
value: String(c.id),
|
|
raw: c,
|
|
}));
|
|
} finally {
|
|
searching.value = false;
|
|
}
|
|
}, 300);
|
|
}
|
|
function onPickCode(_id: string, opt: any) {
|
|
const c = opt?.raw;
|
|
if (!c) return;
|
|
form.remark = c.remark || '';
|
|
outImages.value = c.outImage ? [{ key: c.outImage, url: c.outImage, name: c.outImage }] : [];
|
|
}
|
|
async function saveSingle() {
|
|
if (!form.traceCodeId) return;
|
|
saving.value = true;
|
|
try {
|
|
await outboundApi.updateSingle(form.traceCodeId, {
|
|
outTime: form.outTime ? new Date(form.outTime).toISOString() : undefined,
|
|
outImageKey: outImages.value[0]?.key || undefined,
|
|
txHash: form.txHash || undefined,
|
|
onchainAt: form.onchainAt ? new Date(form.onchainAt).toISOString() : undefined,
|
|
blockHeight: form.blockHeight ?? undefined,
|
|
remark: form.remark || undefined,
|
|
});
|
|
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;
|
|
try {
|
|
const fd = new FormData();
|
|
fd.append('file', file.file as File);
|
|
const res: any = await post('/outbound/import', fd);
|
|
const jobId = res.jobId;
|
|
let job: any = null;
|
|
for (let i = 0; i < 40; i++) {
|
|
await new Promise((r) => setTimeout(r, 700));
|
|
job = await jobApi.get(jobId);
|
|
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
|
|
}
|
|
result.value = job;
|
|
message.success(t('common.msg.operationSuccess'));
|
|
onFinish();
|
|
} catch (e) {
|
|
message.error((e as Error)?.message || 'import failed');
|
|
onError();
|
|
} finally {
|
|
importing.value = false;
|
|
}
|
|
}
|
|
</script>
|