feat: 完善追溯码出库上链管理
This commit is contained in:
@@ -50,7 +50,7 @@ export const traceCodeApi = {
|
||||
post('/trace-codes/batch', data),
|
||||
batches: (params: object) => get<PageResult<any>>('/batches', params),
|
||||
list: (params: object) => get<PageResult<any>>('/trace-codes', params),
|
||||
update: (id: string, data: { groupId?: number | null; batchId?: number; disabled?: boolean }) =>
|
||||
update: (id: string, data: { groupId?: number | null; batchId?: number; batchNo?: string; disabled?: boolean }) =>
|
||||
put(`/trace-codes/${id}`, data),
|
||||
remove: (id: string) => del(`/trace-codes/${id}`),
|
||||
qrUrl: (id: string) => `/api/trace-codes/${id}/qrcode`,
|
||||
@@ -64,6 +64,8 @@ export const traceCodeApi = {
|
||||
// 批量
|
||||
batchGroup: (ids: string[], groupId: number | null) =>
|
||||
put('/trace-codes/batch/group', { ids, groupId }),
|
||||
batchMove: (ids: string[], data: { batchId?: number; batchNo?: string }) =>
|
||||
put('/trace-codes/batch/move', { ids, ...data }),
|
||||
batchStatus: (ids: string[], disabled: boolean) =>
|
||||
put('/trace-codes/batch/status', { ids, disabled }),
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<n-layout has-sider position="absolute">
|
||||
<n-layout has-sider position="absolute" class="admin-layout">
|
||||
<n-layout-sider
|
||||
bordered
|
||||
:collapsed="collapsed"
|
||||
@@ -24,7 +24,7 @@
|
||||
/>
|
||||
</n-layout-sider>
|
||||
|
||||
<n-layout>
|
||||
<n-layout class="admin-main">
|
||||
<n-layout-header bordered class="header">
|
||||
<div class="header-title text-ellipsis">{{ currentTitle }}</div>
|
||||
<div class="spacer" />
|
||||
@@ -177,6 +177,13 @@ onUnmounted(() => window.removeEventListener('resize', resizeHandler));
|
||||
font-weight: 600;
|
||||
color: var(--brand);
|
||||
}
|
||||
.admin-layout {
|
||||
min-width: var(--admin-min-width);
|
||||
min-height: var(--admin-min-height);
|
||||
}
|
||||
.admin-main {
|
||||
min-width: 0;
|
||||
}
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -193,7 +200,8 @@ onUnmounted(() => window.removeEventListener('resize', resizeHandler));
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
.content {
|
||||
height: calc(100vh - var(--admin-header-height) - var(--admin-footer-height));
|
||||
height: calc(max(100vh, var(--admin-min-height)) - var(--admin-header-height) - var(--admin-footer-height));
|
||||
min-height: calc(var(--admin-min-height) - var(--admin-header-height) - var(--admin-footer-height));
|
||||
}
|
||||
.footer {
|
||||
height: var(--admin-footer-height);
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
"codeCount": "Codes",
|
||||
"activeCount": "Activated",
|
||||
"queryTotal": "Total Queries",
|
||||
"traceCodes": "Batches & Trace Codes",
|
||||
"traceCodes": "Trace Code Management",
|
||||
"genCodes": "Generate Trace Codes",
|
||||
"viewCodes": "View All Codes",
|
||||
"batches": "Batches",
|
||||
@@ -230,7 +230,7 @@
|
||||
"watermarkPending": "Generating watermark…",
|
||||
"editDetail": "Edit Details",
|
||||
"dataManage": "Data Management",
|
||||
"traceCodeManage": "Batches & Trace Code Management"
|
||||
"traceCodeManage": "Trace Code Management"
|
||||
},
|
||||
"traceCode": {
|
||||
"batches": "Batches",
|
||||
@@ -260,10 +260,22 @@
|
||||
"editGroup": "Edit Group",
|
||||
"groupName": "Group Name",
|
||||
"batchGroup": "Set Group",
|
||||
"batchMove": "Move Batch",
|
||||
"batchOnchain": "Batch On-chain",
|
||||
"batchEnable": "Enable",
|
||||
"batchDisable": "Disable",
|
||||
"changeGroup": "Change Group",
|
||||
"changeBatch": "Change Batch",
|
||||
"selectExistingBatch": "Select Existing Batch",
|
||||
"newBatchNo": "New Batch No.",
|
||||
"newBatchNoTip": "Fill this to create a new batch and move selected trace codes into it.",
|
||||
"batchNoInputTip": "Select an existing batch, or type a new batch no. to create it automatically.",
|
||||
"outboundStatus": "Outbound",
|
||||
"onchainStatus": "On-chain",
|
||||
"outRegistered": "Recorded",
|
||||
"notOutbound": "Not Outbound",
|
||||
"noOnchain": "Not On-chain",
|
||||
"registerOutbound": "Record Outbound / Chain",
|
||||
"enableOne": "Enable",
|
||||
"disableOne": "Disable",
|
||||
"selected": "{n} selected",
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
"codeCount": "追溯码数",
|
||||
"activeCount": "已激活",
|
||||
"queryTotal": "查询总数",
|
||||
"traceCodes": "批次与追溯码",
|
||||
"traceCodes": "追溯码管理",
|
||||
"genCodes": "生成追溯码",
|
||||
"viewCodes": "查看全部码",
|
||||
"batches": "批次列表",
|
||||
@@ -230,7 +230,7 @@
|
||||
"watermarkPending": "水印生成中…",
|
||||
"editDetail": "编辑详情",
|
||||
"dataManage": "数据管理",
|
||||
"traceCodeManage": "批次与追溯码管理"
|
||||
"traceCodeManage": "追溯码管理"
|
||||
},
|
||||
"traceCode": {
|
||||
"batches": "批次列表",
|
||||
@@ -260,10 +260,22 @@
|
||||
"editGroup": "编辑分组",
|
||||
"groupName": "分组名称",
|
||||
"batchGroup": "批量分组",
|
||||
"batchMove": "批量修改批次",
|
||||
"batchOnchain": "批量上链",
|
||||
"batchEnable": "批量启用",
|
||||
"batchDisable": "批量停用",
|
||||
"changeGroup": "修改分组",
|
||||
"changeBatch": "修改批次",
|
||||
"selectExistingBatch": "选择已有批次",
|
||||
"newBatchNo": "新批次编号",
|
||||
"newBatchNoTip": "填写后将自动创建新批次,并把所选追溯码移动到该批次",
|
||||
"batchNoInputTip": "可下拉选择已有批次,也可直接输入新批次编号并自动创建",
|
||||
"outboundStatus": "出库状态",
|
||||
"onchainStatus": "上链状态",
|
||||
"outRegistered": "已登记",
|
||||
"notOutbound": "未出库",
|
||||
"noOnchain": "未上链",
|
||||
"registerOutbound": "登记出库/上链",
|
||||
"enableOne": "启用",
|
||||
"disableOne": "禁用",
|
||||
"selected": "已选 {n} 项",
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
--brand-to: #1bb6b6;
|
||||
--admin-header-height: 56px;
|
||||
--admin-footer-height: 32px;
|
||||
--admin-min-width: 1120px;
|
||||
--admin-min-height: 680px;
|
||||
--admin-content-height: calc(max(100vh, var(--admin-min-height)) - var(--admin-header-height) - var(--admin-footer-height));
|
||||
}
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
@@ -23,8 +26,9 @@ body,
|
||||
min-height: 100%;
|
||||
}
|
||||
.page.table-page {
|
||||
height: calc(100vh - var(--admin-header-height) - var(--admin-footer-height));
|
||||
max-height: calc(100vh - var(--admin-header-height) - var(--admin-footer-height));
|
||||
height: var(--admin-content-height);
|
||||
min-height: calc(var(--admin-min-height) - var(--admin-header-height) - var(--admin-footer-height));
|
||||
max-height: var(--admin-content-height);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
@@ -55,6 +59,14 @@ body,
|
||||
flex: 1 1 auto !important;
|
||||
min-height: 0;
|
||||
}
|
||||
.table-fill .n-data-table-td--fixed-right,
|
||||
.table-fill .n-data-table-th--fixed-right {
|
||||
background-color: var(--n-td-color);
|
||||
box-shadow: -8px 0 10px -10px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
.table-fill .n-data-table-th--fixed-right {
|
||||
background-color: var(--n-th-color);
|
||||
}
|
||||
.table-pagination {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</n-descriptions>
|
||||
</n-card>
|
||||
|
||||
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false" class="table-card">
|
||||
<n-card :bordered="false" class="table-card">
|
||||
<div class="trace-table-wrap">
|
||||
<trace-code-panel :artwork-id="artworkId" @changed="loadArtwork" />
|
||||
</div>
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
class="table-fill"
|
||||
flex-height
|
||||
remote
|
||||
:scroll-x="1280"
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
<div class="table-pagination">
|
||||
@@ -79,7 +80,7 @@ const columns: DataTableColumns<any> = [
|
||||
: h(NAvatar, { size: 44, style: 'border-radius:8px' }, { default: () => '—' }),
|
||||
},
|
||||
{ title: () => t('pages.artwork.archiveNo'), key: 'archiveNo', width: 140, render: (r) => r.archiveNo || '-' },
|
||||
{ title: () => t('pages.artwork.title'), key: 'title', ellipsis: { tooltip: true } },
|
||||
{ title: () => t('pages.artwork.title'), key: 'title', width: 200, ellipsis: { tooltip: true } },
|
||||
{ title: () => t('pages.artwork.artist'), key: 'artist', width: 110, render: (r) => r.artist || '-' },
|
||||
{ title: () => t('pages.artwork.template'), key: 'template', width: 120, render: (r) => r.template?.name || '-' },
|
||||
{ title: () => t('pages.artwork.codeCount'), key: 'codeCount', width: 80, render: (r) => r.codeCount ?? 0 },
|
||||
@@ -106,6 +107,8 @@ const columns: DataTableColumns<any> = [
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 112,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
render: (r) =>
|
||||
h('div', { class: 'row-actions' }, [
|
||||
h(
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
class="table-fill"
|
||||
flex-height
|
||||
remote
|
||||
:scroll-x="1120"
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
<div class="table-pagination">
|
||||
@@ -95,7 +96,7 @@ const columns: DataTableColumns<any> = [
|
||||
? h(NAvatar, { src: r.images[0].url, size: 40, style: 'border-radius:8px' })
|
||||
: h(NAvatar, { size: 40, style: 'border-radius:8px' }, { default: () => '—' }),
|
||||
},
|
||||
{ title: () => t('pages.artwork.title'), key: 'title', ellipsis: { tooltip: true } },
|
||||
{ title: () => t('pages.artwork.title'), key: 'title', width: 220, ellipsis: { tooltip: true } },
|
||||
{ title: () => t('pages.artwork.artist'), key: 'artist', width: 110, render: (r) => r.artist || '-' },
|
||||
{
|
||||
title: () => t('pages.audit.status'),
|
||||
@@ -103,12 +104,14 @@ const columns: DataTableColumns<any> = [
|
||||
width: 100,
|
||||
render: (r) => h(NTag, { size: 'small', type: auditTagType(r.auditStatus) }, { default: () => t(`common.auditStatus.${r.auditStatus}`) }),
|
||||
},
|
||||
{ title: () => t('pages.audit.remark'), key: 'auditRemark', ellipsis: { tooltip: true }, render: (r) => r.auditRemark || '-' },
|
||||
{ title: () => t('pages.audit.remark'), key: 'auditRemark', width: 260, ellipsis: { tooltip: true }, render: (r) => r.auditRemark || '-' },
|
||||
{ title: () => t('common.label.updatedAt'), key: 'updatedAt', width: 160, render: (r) => fmt(r.updatedAt) },
|
||||
{
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
render: (r) =>
|
||||
h('div', { style: 'display:flex;gap:2px' }, [
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', title: t('common.action.detail'), onClick: () => router.push(`/artworks/${r.id}`) }, { icon: () => h(NIcon, null, { default: () => h(EyeOutline) }) }),
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
class="table-fill"
|
||||
flex-height
|
||||
remote
|
||||
:scroll-x="1320"
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
<div class="table-pagination">
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
class="table-fill"
|
||||
flex-height
|
||||
remote
|
||||
:scroll-x="1080"
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
<div class="table-pagination">
|
||||
@@ -129,10 +130,12 @@ const rules: FormRules = { name: { required: true, message: () => t('pages.templ
|
||||
|
||||
const columns: DataTableColumns<any> = [
|
||||
{ title: 'ID', key: 'id', width: 70 },
|
||||
{ title: () => t('pages.template.name'), key: 'name' },
|
||||
{ title: () => t('pages.template.name'), key: 'name', width: 180, ellipsis: { tooltip: true } },
|
||||
{
|
||||
title: () => t('pages.template.fields'),
|
||||
key: 'fields',
|
||||
width: 340,
|
||||
ellipsis: { tooltip: true },
|
||||
render: (r) => (r.fields || []).map((f: any) => f.label).join('、') || '-',
|
||||
},
|
||||
{
|
||||
@@ -147,6 +150,8 @@ const columns: DataTableColumns<any> = [
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
render: (r) =>
|
||||
auth.canWrite
|
||||
? h('div', { style: 'display:flex;gap:4px' }, [
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
class="table-fill"
|
||||
flex-height
|
||||
remote
|
||||
:scroll-x="980"
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
<div class="table-pagination">
|
||||
@@ -100,8 +101,8 @@ const pwdUserId = ref<number | null>(null);
|
||||
|
||||
const columns: DataTableColumns<any> = [
|
||||
{ title: 'ID', key: 'id', width: 64 },
|
||||
{ title: () => t('pages.user.username'), key: 'username' },
|
||||
{ title: () => t('pages.user.realName'), key: 'realName', render: (r) => r.realName || '-' },
|
||||
{ title: () => t('pages.user.username'), key: 'username', width: 160, ellipsis: { tooltip: true } },
|
||||
{ title: () => t('pages.user.realName'), key: 'realName', width: 160, ellipsis: { tooltip: true }, render: (r) => r.realName || '-' },
|
||||
{ title: () => t('pages.user.role'), key: 'role', width: 120, render: (r) => t(`common.role.${r.role}`) },
|
||||
{
|
||||
title: () => t('common.label.status'),
|
||||
@@ -114,6 +115,8 @@ const columns: DataTableColumns<any> = [
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 140,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
render: (r) =>
|
||||
h('div', { style: 'display:flex;gap:2px' }, [
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => openEdit(r) }, { icon: () => h(NIcon, null, { default: () => h(CreateOutline) }) }),
|
||||
|
||||
@@ -129,12 +129,38 @@ export class UpdateTraceCodeDto {
|
||||
@IsInt()
|
||||
batchId?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: '新批次编号,填写后自动创建批次并移动到该批次' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(50)
|
||||
batchNo?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'true 停用,false 启用' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export class BatchMoveDto {
|
||||
@ApiProperty({ description: '追溯码 ID 列表', type: [String] })
|
||||
@IsArray()
|
||||
@ArrayNotEmpty()
|
||||
@IsString({ each: true })
|
||||
ids!: string[];
|
||||
|
||||
@ApiPropertyOptional({ description: '目标批次 ID' })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
batchId?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: '新批次编号,填写后自动创建批次并移动到该批次' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(50)
|
||||
batchNo?: string;
|
||||
}
|
||||
|
||||
export class QueryBatchDto extends PaginationDto {
|
||||
@ApiPropertyOptional({ description: '作品/款式 ID' })
|
||||
@IsOptional()
|
||||
|
||||
@@ -16,6 +16,7 @@ import { RoleType } from '@artveris/shared';
|
||||
import { TraceCodeService } from './trace-code.service';
|
||||
import {
|
||||
BatchGroupDto,
|
||||
BatchMoveDto,
|
||||
BatchStatusDto,
|
||||
ExportTraceCodeDto,
|
||||
GenerateBatchDto,
|
||||
@@ -88,11 +89,18 @@ export class TraceCodeController {
|
||||
return this.service.batchSetStatus(dto);
|
||||
}
|
||||
|
||||
@Put('trace-codes/batch/move')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
@ApiOperation({ summary: '批量修改追溯码批次' })
|
||||
batchMove(@Body() dto: BatchMoveDto, @CurrentUser() user: AuthUser) {
|
||||
return this.service.batchMove(dto, user.id);
|
||||
}
|
||||
|
||||
@Put('trace-codes/:id')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
@ApiOperation({ summary: '更新单个追溯码' })
|
||||
updateOne(@Param('id') id: string, @Body() dto: UpdateTraceCodeDto) {
|
||||
return this.service.updateOne(id, dto);
|
||||
updateOne(@Param('id') id: string, @Body() dto: UpdateTraceCodeDto, @CurrentUser() user: AuthUser) {
|
||||
return this.service.updateOne(id, dto, user.id);
|
||||
}
|
||||
|
||||
@Delete('trace-codes/:id')
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Response } from 'express';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
import * as QRCode from 'qrcode';
|
||||
import dayjs from 'dayjs';
|
||||
import { ArtworkStatus, ErrorCode, JobType, QUEUE_NAMES, TraceCodeStatus } from '@artveris/shared';
|
||||
import { ArtworkStatus, BatchStatus, ErrorCode, JobType, QUEUE_NAMES, TraceCodeStatus } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { BusinessException } from '../common/exceptions/business.exception';
|
||||
@@ -15,6 +15,7 @@ import { buildPage } from '../common/utils/pagination.util';
|
||||
import { JobsService } from '../jobs/jobs.service';
|
||||
import {
|
||||
BatchGroupDto,
|
||||
BatchMoveDto,
|
||||
BatchStatusDto,
|
||||
ExportTraceCodeDto,
|
||||
GenerateBatchDto,
|
||||
@@ -139,24 +140,131 @@ export class TraceCodeService {
|
||||
return { success: true, count: ids.length };
|
||||
}
|
||||
|
||||
async updateOne(id: string, dto: UpdateTraceCodeDto) {
|
||||
private async resolveTargetBatch(options: {
|
||||
artworkId: number;
|
||||
batchId?: number;
|
||||
batchNo?: string;
|
||||
count: number;
|
||||
userId?: number;
|
||||
}) {
|
||||
const batchNo = options.batchNo?.trim();
|
||||
if (batchNo) {
|
||||
const exists = await this.prisma.batch.findUnique({ where: { batchNo } });
|
||||
if (exists) throw new BusinessException(ErrorCode.BAD_REQUEST, '批次编号已存在');
|
||||
return this.prisma.batch.create({
|
||||
data: {
|
||||
batchNo,
|
||||
artworkId: options.artworkId,
|
||||
quantity: options.count,
|
||||
generatedCount: options.count,
|
||||
status: BatchStatus.DONE,
|
||||
createdBy: options.userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!options.batchId) {
|
||||
throw new BusinessException(ErrorCode.BAD_REQUEST, '请选择目标批次或填写新批次编号');
|
||||
}
|
||||
|
||||
const targetBatch = await this.prisma.batch.findUnique({ where: { id: options.batchId } });
|
||||
if (!targetBatch || targetBatch.artworkId !== options.artworkId) {
|
||||
throw new BusinessException(ErrorCode.BAD_REQUEST, '目标批次不存在或不属于当前艺术品档案');
|
||||
}
|
||||
return targetBatch;
|
||||
}
|
||||
|
||||
private batchCountUpdates(batchCounts: Map<number, number>, direction: 'increment' | 'decrement') {
|
||||
return [...batchCounts.entries()].map(([batchId, count]) =>
|
||||
this.prisma.batch.update({
|
||||
where: { id: batchId },
|
||||
data: {
|
||||
quantity: { [direction]: count },
|
||||
generatedCount: { [direction]: count },
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async batchMove(dto: BatchMoveDto, userId: number) {
|
||||
const ids = dto.ids.map((i) => BigInt(i));
|
||||
const codes = await this.prisma.traceCode.findMany({
|
||||
where: { id: { in: ids } },
|
||||
select: { id: true, artworkId: true, batchId: true },
|
||||
});
|
||||
if (codes.length !== ids.length) {
|
||||
throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '部分追溯码不存在', 404);
|
||||
}
|
||||
const artworkIds = new Set(codes.map((c) => c.artworkId));
|
||||
if (artworkIds.size !== 1) {
|
||||
throw new BusinessException(ErrorCode.BAD_REQUEST, '只能批量移动同一艺术品档案下的追溯码');
|
||||
}
|
||||
|
||||
const artworkId = codes[0].artworkId;
|
||||
const targetBatch = await this.resolveTargetBatch({
|
||||
artworkId,
|
||||
batchId: dto.batchId,
|
||||
batchNo: dto.batchNo,
|
||||
count: codes.length,
|
||||
userId,
|
||||
});
|
||||
|
||||
const movedCodes = codes.filter((c) => c.batchId !== targetBatch.id);
|
||||
if (!movedCodes.length) return { success: true, count: 0, batch: targetBatch };
|
||||
|
||||
const sourceCounts = new Map<number, number>();
|
||||
for (const code of movedCodes) {
|
||||
sourceCounts.set(code.batchId, (sourceCounts.get(code.batchId) ?? 0) + 1);
|
||||
}
|
||||
|
||||
const updates = [
|
||||
this.prisma.traceCode.updateMany({
|
||||
where: { id: { in: movedCodes.map((c) => c.id) } },
|
||||
data: { batchId: targetBatch.id },
|
||||
}),
|
||||
...this.batchCountUpdates(sourceCounts, 'decrement'),
|
||||
];
|
||||
if (!dto.batchNo?.trim()) {
|
||||
updates.push(
|
||||
this.prisma.batch.update({
|
||||
where: { id: targetBatch.id },
|
||||
data: {
|
||||
quantity: { increment: movedCodes.length },
|
||||
generatedCount: { increment: movedCodes.length },
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
await this.prisma.$transaction(updates);
|
||||
|
||||
return { success: true, count: movedCodes.length, batch: targetBatch };
|
||||
}
|
||||
|
||||
async updateOne(id: string, dto: UpdateTraceCodeDto, userId?: number) {
|
||||
const traceCodeId = BigInt(id);
|
||||
const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId } });
|
||||
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
|
||||
|
||||
const data: Prisma.TraceCodeUncheckedUpdateInput = {};
|
||||
let targetBatchId: number | undefined;
|
||||
let createdBatch = false;
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(dto, 'groupId')) {
|
||||
if (dto.groupId !== null && dto.groupId !== undefined) await this.ensureGroup(dto.groupId);
|
||||
data.groupId = dto.groupId ?? null;
|
||||
}
|
||||
|
||||
if (dto.batchId !== undefined) {
|
||||
const targetBatch = await this.prisma.batch.findUnique({ where: { id: dto.batchId } });
|
||||
if (!targetBatch || targetBatch.artworkId !== code.artworkId) {
|
||||
throw new BusinessException(ErrorCode.BAD_REQUEST, '目标批次不存在或不属于当前艺术品档案');
|
||||
}
|
||||
data.batchId = dto.batchId;
|
||||
if (dto.batchId !== undefined || dto.batchNo?.trim()) {
|
||||
const targetBatch = await this.resolveTargetBatch({
|
||||
artworkId: code.artworkId,
|
||||
batchId: dto.batchId,
|
||||
batchNo: dto.batchNo,
|
||||
count: 1,
|
||||
userId,
|
||||
});
|
||||
targetBatchId = targetBatch.id;
|
||||
createdBatch = Boolean(dto.batchNo?.trim());
|
||||
data.batchId = targetBatchId;
|
||||
}
|
||||
|
||||
if (dto.disabled !== undefined) {
|
||||
@@ -169,12 +277,23 @@ export class TraceCodeService {
|
||||
|
||||
if (Object.keys(data).length === 0) return code;
|
||||
|
||||
if (data.batchId !== undefined && data.batchId !== code.batchId) {
|
||||
await this.prisma.$transaction([
|
||||
if (targetBatchId !== undefined && targetBatchId !== code.batchId) {
|
||||
const updates = [
|
||||
this.prisma.traceCode.update({ where: { id: traceCodeId }, data }),
|
||||
this.prisma.batch.update({ where: { id: code.batchId }, data: { generatedCount: { decrement: 1 } } }),
|
||||
this.prisma.batch.update({ where: { id: data.batchId as number }, data: { generatedCount: { increment: 1 } } }),
|
||||
]);
|
||||
this.prisma.batch.update({
|
||||
where: { id: code.batchId },
|
||||
data: { quantity: { decrement: 1 }, generatedCount: { decrement: 1 } },
|
||||
}),
|
||||
];
|
||||
if (!createdBatch) {
|
||||
updates.push(
|
||||
this.prisma.batch.update({
|
||||
where: { id: targetBatchId },
|
||||
data: { quantity: { increment: 1 }, generatedCount: { increment: 1 } },
|
||||
}),
|
||||
);
|
||||
}
|
||||
await this.prisma.$transaction(updates);
|
||||
} else {
|
||||
await this.prisma.traceCode.update({ where: { id: traceCodeId }, data });
|
||||
}
|
||||
@@ -202,7 +321,7 @@ export class TraceCodeService {
|
||||
this.prisma.traceCode.delete({ where: { id: traceCodeId } }),
|
||||
this.prisma.batch.update({
|
||||
where: { id: code.batchId },
|
||||
data: { generatedCount: { decrement: 1 } },
|
||||
data: { quantity: { decrement: 1 }, generatedCount: { decrement: 1 } },
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -247,9 +366,8 @@ export class TraceCodeService {
|
||||
batch: { select: { id: true, batchNo: true } },
|
||||
group: { select: { id: true, name: true } },
|
||||
proofs: {
|
||||
where: { status: 'ONCHAIN' },
|
||||
orderBy: [{ onchainAt: 'desc' }, { id: 'desc' }],
|
||||
take: 1,
|
||||
orderBy: [{ createdAt: 'desc' }, { id: 'desc' }],
|
||||
take: 10,
|
||||
},
|
||||
},
|
||||
orderBy: { id: 'desc' },
|
||||
@@ -261,10 +379,12 @@ export class TraceCodeService {
|
||||
return buildPage(
|
||||
list.map((code) => {
|
||||
const { proofs, ...rest } = code;
|
||||
const latestOnchainProof = proofs.find((p) => p.status === 'ONCHAIN') ?? null;
|
||||
return {
|
||||
...rest,
|
||||
outImageUrl: code.outImage ? this.storage.getUrl(code.outImage) : null,
|
||||
latestProof: proofs[0] ?? null,
|
||||
latestProof: latestOnchainProof,
|
||||
latestAnyProof: proofs[0] ?? null,
|
||||
};
|
||||
}),
|
||||
total,
|
||||
|
||||
Reference in New Issue
Block a user