feat: 完善追溯码出库上链管理
This commit is contained in:
@@ -62,6 +62,8 @@
|
||||
{{ t('pages.traceCode.batchGroup') }}
|
||||
</n-button>
|
||||
</n-dropdown>
|
||||
<n-button size="small" @click="openBatchModal()">{{ t('pages.traceCode.batchMove') }}</n-button>
|
||||
<n-button size="small" @click="batchOnchain">{{ t('pages.traceCode.batchOnchain') }}</n-button>
|
||||
<n-button size="small" @click="batchStatus(false)">{{ t('pages.traceCode.batchEnable') }}</n-button>
|
||||
<n-button size="small" type="warning" @click="batchStatus(true)">{{ t('pages.traceCode.batchDisable') }}</n-button>
|
||||
</n-space>
|
||||
@@ -75,6 +77,7 @@
|
||||
class="table-fill"
|
||||
flex-height
|
||||
remote
|
||||
:scroll-x="1560"
|
||||
:row-key="(r) => r.id"
|
||||
v-model:checked-row-keys="checkedKeys"
|
||||
/>
|
||||
@@ -142,6 +145,62 @@
|
||||
</n-list-item>
|
||||
</n-list>
|
||||
</n-modal>
|
||||
|
||||
<n-modal v-model:show="batchModal" preset="card" :title="t('pages.traceCode.changeBatch')" style="width: 460px">
|
||||
<n-form :model="batchForm" label-placement="top">
|
||||
<n-form-item :label="t('pages.traceCode.batchNo')">
|
||||
<n-select
|
||||
v-model:value="batchForm.batchValue"
|
||||
:options="batchMoveOptions"
|
||||
filterable
|
||||
tag
|
||||
clearable
|
||||
:placeholder="t('pages.traceCode.batchNo')"
|
||||
/>
|
||||
<template #feedback>{{ t('pages.traceCode.batchNoInputTip') }}</template>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div style="text-align: right">
|
||||
<n-button class="mr8" @click="batchModal = false">{{ t('common.action.cancel') }}</n-button>
|
||||
<n-button type="primary" :disabled="!batchForm.batchValue" @click="applyBatchMove">{{ t('common.action.confirm') }}</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<n-modal v-model:show="outboundModal" preset="card" :title="t('pages.traceCode.registerOutbound')" style="width: 620px">
|
||||
<n-form :model="outboundForm" label-placement="top">
|
||||
<n-grid :cols="2" :x-gap="16">
|
||||
<n-form-item-gi :label="t('pages.outbound.outTime')">
|
||||
<n-date-picker v-model:formatted-value="outboundForm.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="outboundForm.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="outboundForm.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="outboundForm.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="outboundForm.blockHeight" :min="0" style="width: 100%" />
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div style="text-align: right">
|
||||
<n-button class="mr8" @click="outboundModal = false">{{ t('common.action.cancel') }}</n-button>
|
||||
<n-button type="primary" :loading="outboundSaving" @click="saveOutbound">{{ t('common.action.save') }}</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -151,13 +210,15 @@ import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NButton, NDropdown, NIcon, NTag, NText, type DataTableColumns, type DropdownOption } from 'naive-ui';
|
||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline, EllipsisHorizontalOutline } from '@vicons/ionicons5';
|
||||
import dayjs from 'dayjs';
|
||||
import { TraceCodeStatus } from '@artveris/shared';
|
||||
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
||||
import { traceCodeApi, jobApi, artworkApi, outboundApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
artworkId?: number;
|
||||
@@ -194,6 +255,7 @@ const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(lo
|
||||
const statusOptions = Object.values(TraceCodeStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
||||
|
||||
const batchOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const batchMoveOptions = computed(() => batchOptions.value.map((b) => ({ label: b.label, value: b.value })));
|
||||
const groups = ref<any[]>([]);
|
||||
const groupFilterOptions = computed(() => groups.value.map((g) => ({ label: g.name, value: g.id })));
|
||||
const groupPlainOptions = computed(() => groups.value.map((g) => ({ label: g.name, value: g.id })));
|
||||
@@ -205,9 +267,6 @@ const rowGroupOptions = computed<DropdownOption[]>(() => [
|
||||
{ label: t('pages.traceCode.noGroup'), key: 'group:__none__' },
|
||||
...groups.value.map((g) => ({ label: g.name, key: `group:${g.id}` })),
|
||||
]);
|
||||
const rowBatchOptions = computed<DropdownOption[]>(() =>
|
||||
batchOptions.value.map((b) => ({ label: b.label, key: `batch:${b.value}` })),
|
||||
);
|
||||
|
||||
const genModal = ref(false);
|
||||
const generating = ref(false);
|
||||
@@ -229,15 +288,49 @@ const qrUrl = ref('');
|
||||
const groupModal = ref(false);
|
||||
const groupForm = reactive<{ name: string }>({ name: '' });
|
||||
const editingGroup = ref<number | null>(null);
|
||||
const batchModal = ref(false);
|
||||
const batchTarget = ref<any | null>(null);
|
||||
const batchForm = reactive<{ batchValue: number | string | null }>({ batchValue: null });
|
||||
const outboundModal = ref(false);
|
||||
const outboundSaving = ref(false);
|
||||
const outboundTarget = ref<any | null>(null);
|
||||
const outImages = ref<any[]>([]);
|
||||
const outboundForm = reactive<any>({
|
||||
outTime: null,
|
||||
remark: '',
|
||||
txHash: '',
|
||||
onchainAt: null,
|
||||
blockHeight: null,
|
||||
});
|
||||
|
||||
const columns = computed<DataTableColumns<any>>(() => {
|
||||
const base: DataTableColumns<any> = [
|
||||
{ type: 'selection' },
|
||||
{ title: () => t('pages.traceCode.batchNo'), key: 'batch', width: 150, render: (r) => r.batch?.batchNo || '-' },
|
||||
{
|
||||
title: () => t('pages.traceCode.outboundStatus'),
|
||||
key: 'outboundStatus',
|
||||
width: 96,
|
||||
render: (r) =>
|
||||
r.outTime || r.outImage
|
||||
? h(NTag, { size: 'small', type: 'success' }, { default: () => t('pages.traceCode.outRegistered') })
|
||||
: h(NText, { depth: 3 }, { default: () => t('pages.traceCode.notOutbound') }),
|
||||
},
|
||||
{ title: () => t('pages.outbound.outTime'), key: 'outTime', width: 150, render: (r) => fmt(r.outTime) },
|
||||
{
|
||||
title: () => t('pages.traceCode.onchainStatus'),
|
||||
key: 'onchainStatus',
|
||||
width: 100,
|
||||
render: (r) =>
|
||||
r.latestAnyProof
|
||||
? h(NTag, { size: 'small', type: statusType(r.latestAnyProof.status) }, { default: () => t(`common.status.${r.latestAnyProof.status}`) })
|
||||
: h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noOnchain') }),
|
||||
},
|
||||
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 120 },
|
||||
{
|
||||
title: () => t('pages.traceCode.url'),
|
||||
key: 'url',
|
||||
width: 320,
|
||||
ellipsis: { tooltip: true },
|
||||
render: (r) =>
|
||||
h(
|
||||
@@ -259,6 +352,8 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: auth.canWrite ? 104 : 70,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
render: (r) =>
|
||||
h('div', { class: 'row-actions' }, [
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
||||
@@ -434,10 +529,22 @@ async function batchStatus(disabled: boolean) {
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
async function batchOnchain() {
|
||||
for (const id of checkedKeys.value.map(String)) {
|
||||
await traceCodeApi.onchain(id);
|
||||
}
|
||||
message.success(t('pages.blockchain.triggered'));
|
||||
checkedKeys.value = [];
|
||||
await load();
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
function rowActionOptions(row: any): DropdownOption[] {
|
||||
return [
|
||||
{ label: t('pages.traceCode.changeGroup'), key: 'changeGroup', children: rowGroupOptions.value },
|
||||
{ label: t('pages.traceCode.changeBatch'), key: 'changeBatch', children: rowBatchOptions.value },
|
||||
{ label: t('pages.traceCode.changeBatch'), key: 'batch:open' },
|
||||
{ label: t('pages.traceCode.registerOutbound'), key: 'outbound:open' },
|
||||
{ label: t('pages.blockchain.trigger'), key: 'onchain' },
|
||||
{ type: 'divider', key: 'divider-1' },
|
||||
{
|
||||
label: row.status === TraceCodeStatus.DISABLED ? t('pages.traceCode.enableOne') : t('pages.traceCode.disableOne'),
|
||||
@@ -457,10 +564,19 @@ async function onRowAction(row: any, key: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.startsWith('batch:')) {
|
||||
await traceCodeApi.update(String(row.id), { batchId: Number(key.slice('batch:'.length)) });
|
||||
message.success(t('common.msg.saved'));
|
||||
await loadBatches();
|
||||
if (key === 'batch:open') {
|
||||
openBatchModal(row);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'outbound:open') {
|
||||
openOutboundModal(row);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'onchain') {
|
||||
await traceCodeApi.onchain(String(row.id));
|
||||
message.success(t('pages.blockchain.triggered'));
|
||||
await load();
|
||||
emit('changed');
|
||||
return;
|
||||
@@ -491,6 +607,80 @@ async function onRowAction(row: any, key: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function openBatchModal(row?: any) {
|
||||
batchTarget.value = row || null;
|
||||
batchForm.batchValue = row?.batch?.id ?? null;
|
||||
batchModal.value = true;
|
||||
}
|
||||
|
||||
async function applyBatchMove() {
|
||||
const value = batchForm.batchValue;
|
||||
const batchNo = typeof value === 'string' ? value.trim() : '';
|
||||
const payload: { batchId?: number; batchNo?: string } = batchNo ? { batchNo } : { batchId: typeof value === 'number' ? value : undefined };
|
||||
if (!payload.batchId && !payload.batchNo) return;
|
||||
|
||||
if (batchTarget.value) {
|
||||
await traceCodeApi.update(String(batchTarget.value.id), payload);
|
||||
} else {
|
||||
await traceCodeApi.batchMove(checkedKeys.value.map(String), payload);
|
||||
}
|
||||
message.success(t('common.msg.saved'));
|
||||
batchModal.value = false;
|
||||
batchTarget.value = null;
|
||||
checkedKeys.value = [];
|
||||
await loadBatches();
|
||||
await load();
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
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 openOutboundModal(row: any) {
|
||||
outboundTarget.value = row;
|
||||
const latestProof = row.latestProof;
|
||||
outboundForm.outTime = formatDateTime(row.outTime);
|
||||
outboundForm.remark = row.remark || '';
|
||||
outboundForm.txHash = latestProof?.txHash || '';
|
||||
outboundForm.onchainAt = formatDateTime(latestProof?.onchainAt);
|
||||
outboundForm.blockHeight = toNumber(latestProof?.blockHeight);
|
||||
outImages.value = row.outImage ? [{ key: row.outImage, url: row.outImageUrl || row.outImage, name: fileName(row.outImage) }] : [];
|
||||
outboundModal.value = true;
|
||||
}
|
||||
|
||||
async function saveOutbound() {
|
||||
if (!outboundTarget.value) return;
|
||||
outboundSaving.value = true;
|
||||
try {
|
||||
await outboundApi.updateSingle(String(outboundTarget.value.id), {
|
||||
outTime: outboundForm.outTime ? dayjs(outboundForm.outTime).toISOString() : null,
|
||||
outImageKey: outImages.value[0]?.key ?? null,
|
||||
txHash: outboundForm.txHash || undefined,
|
||||
onchainAt: outboundForm.onchainAt ? dayjs(outboundForm.onchainAt).toISOString() : undefined,
|
||||
blockHeight: outboundForm.blockHeight ?? undefined,
|
||||
remark: outboundForm.remark || null,
|
||||
});
|
||||
message.success(t('common.msg.saved'));
|
||||
outboundModal.value = false;
|
||||
outboundTarget.value = null;
|
||||
await load();
|
||||
emit('changed');
|
||||
} finally {
|
||||
outboundSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function resetGroupForm() {
|
||||
editingGroup.value = null;
|
||||
groupForm.name = '';
|
||||
@@ -595,7 +785,9 @@ onMounted(async () => {
|
||||
.row-actions {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
.mr8 {
|
||||
margin-right: 8px;
|
||||
|
||||
Reference in New Issue
Block a user