diff --git a/aidocs/project_context.md b/aidocs/project_context.md index b6df28e..547e81f 100644 --- a/aidocs/project_context.md +++ b/aidocs/project_context.md @@ -97,6 +97,10 @@ - 后台全局页脚(2026-07-03):`MainLayout.vue` 在登录后的管理后台底部统一增加页脚,先放置版权年份和“备案信息待补充”占位,后续版权/ICP备案/公安备案只改全局布局即可;全局 CSS 新增 `--admin-header-height` / `--admin-footer-height`,内容区和 `table-page` 高度统一扣除页脚高度,避免列表分页被页脚遮挡或挤出。 - 查询日志列表单行展示(2026-07-04):`QueryLogs.vue` 中短码、档案编号、批次编号、IP、设备信息列使用 Naive UI `ellipsis: { tooltip: true }`,列表内保持单行省略,鼠标悬浮查看完整内容;已浏览器测量设备信息列为 `white-space: nowrap` / `text-overflow: ellipsis`,避免设备信息换行拉高行高。 - 批次与追溯码管理增强(2026-07-04):艺术品批次管理页上方摘要新增批次数量统计(`ArtworkService.get` 的 `codeStats.batchTotal`);`TraceCodePanel` 操作列固定为二维码按钮 + 悬停操作菜单,单码支持修改分组、移动到同作品其他批次、启用/禁用、删除。后端新增 `PUT /trace-codes/:id` 与 `DELETE /trace-codes/:id`;移动批次会维护源/目标批次 `generatedCount`,删除单码会先把查询日志的 `traceCodeId` 置空保留日志快照,再删除码并扣减批次生成数。 +- 追溯码管理闭环增强(2026-07-04):根据 PRD §6.4,将“出库/上链”内聚到艺术品档案下的追溯码管理页。`TraceCodePanel` 列表新增出库状态、出库时间、上链状态列;行操作菜单新增“登记出库/上链”和“触发上链”,批量条新增批量上链。登记弹窗复用现有出库单条录入能力(出库时间、实况图、备注、手工上链哈希/时间/区块高度),仍写入 `TraceCode` 与 `BlockchainProof`;触发上链仍走 `POST /trace-codes/:id/onchain`。批次修改弹窗合并为一个 `n-select tag` 控件,可下拉选择已有批次或直接输入新批次编号自动创建;后端 `PUT /trace-codes/:id` 与 `PUT /trace-codes/batch/move` 支持 `batchNo` 并维护源/目标批次 `quantity/generatedCount`。艺术品追溯码页下方表格卡片去掉重复标题,仅保留页面顶部“追溯码管理”。 +- 后台最小工作区尺寸(2026-07-04):为避免浏览器窗口过小时后台页面被压缩到表格不可见,`MainLayout.vue` 与全局 `styles.css` 新增 `--admin-min-width: 1120px`、`--admin-min-height: 680px` 和 `--admin-content-height`。管理后台根布局设置最小宽高,小于该尺寸时由浏览器外层滚动承载;正常尺寸下列表页仍保持“工具栏/表格内部滚动/底部分页”的固定布局。 +- 后台列表横向滚动(2026-07-04):主数据表(艺术品档案、模板、内容审核、查询日志、用户、追溯码面板)统一给 `n-data-table` 设置 `scroll-x`,并为弹性文本列补明确宽度与必要的 `ellipsis`,避免浏览器宽度不足或字段过多时列被强行压缩、操作列消失;横向滚动发生在列表内部,纵向仍保持表体内滚动与底部分页固定。 +- 后台操作列约定(2026-07-04):主列表的操作列统一 `fixed: 'right'` 且 `align: 'center'`,表头和内容居中;全局 `.table-fill` 为 Naive UI 右固定列补不透明表头/单元格背景与左侧阴影分隔,避免横向滚动时固定操作列透明叠在其他字段上。 ## 当前代码基准与注意事项 diff --git a/apps/admin/src/api/index.ts b/apps/admin/src/api/index.ts index 54842dd..20f6764 100644 --- a/apps/admin/src/api/index.ts +++ b/apps/admin/src/api/index.ts @@ -50,7 +50,7 @@ export const traceCodeApi = { post('/trace-codes/batch', data), batches: (params: object) => get>('/batches', params), list: (params: object) => get>('/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 }), }; diff --git a/apps/admin/src/components/TraceCodePanel.vue b/apps/admin/src/components/TraceCodePanel.vue index c2a1003..482baef 100644 --- a/apps/admin/src/components/TraceCodePanel.vue +++ b/apps/admin/src/components/TraceCodePanel.vue @@ -62,6 +62,8 @@ {{ t('pages.traceCode.batchGroup') }} + {{ t('pages.traceCode.batchMove') }} + {{ t('pages.traceCode.batchOnchain') }} {{ t('pages.traceCode.batchEnable') }} {{ t('pages.traceCode.batchDisable') }} @@ -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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + {{ t('pages.outbound.onchainSection') }} + + + + + + + + + + + + + + @@ -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([]); 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(() => [ { label: t('pages.traceCode.noGroup'), key: 'group:__none__' }, ...groups.value.map((g) => ({ label: g.name, key: `group:${g.id}` })), ]); -const rowBatchOptions = computed(() => - 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(null); +const batchModal = ref(false); +const batchTarget = ref(null); +const batchForm = reactive<{ batchValue: number | string | null }>({ batchValue: null }); +const outboundModal = ref(false); +const outboundSaving = ref(false); +const outboundTarget = ref(null); +const outImages = ref([]); +const outboundForm = reactive({ + outTime: null, + remark: '', + txHash: '', + onchainAt: null, + blockHeight: null, +}); const columns = computed>(() => { const base: DataTableColumns = [ { 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>(() => { 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; diff --git a/apps/admin/src/layouts/MainLayout.vue b/apps/admin/src/layouts/MainLayout.vue index 8dcb673..03f80d0 100644 --- a/apps/admin/src/layouts/MainLayout.vue +++ b/apps/admin/src/layouts/MainLayout.vue @@ -1,5 +1,5 @@