feat: 追溯码列表列重排并做追溯码/档案编号/名称关联跳转

This commit is contained in:
Nixevol
2026-07-12 22:26:46 +08:00
parent 3ad50edd57
commit 8fd417aa87
4 changed files with 98 additions and 35 deletions
+91 -33
View File
@@ -235,7 +235,7 @@
<script setup lang="ts">
import { computed, h, onMounted, onUnmounted, reactive, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useRoute, useRouter } 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, FilterOutline, CopyOutline } from '@vicons/ionicons5';
@@ -260,6 +260,7 @@ const emit = defineEmits<{
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const auth = useAuthStore();
const fixedArtworkId = computed(() => props.artworkId || null);
@@ -363,8 +364,52 @@ const targetProof = computed<any>(() => outboundTarget.value?.latestProof ?? out
const outboundModalTitle = computed(() => outboundMenuLabel(outboundTarget.value));
const columns = computed<DataTableColumns<any>>(() => {
const base: DataTableColumns<any> = [
const cols: DataTableColumns<any> = [
{ type: 'selection' },
// 追溯码:点击打开该码的 C 端溯源页
{
title: () => t('pages.traceCode.shortCode'),
key: 'shortCode',
width: 140,
align: 'center',
fixed: 'left',
render: (r) =>
h(
'a',
{ href: r.url, target: '_blank', rel: 'noopener', class: 'cell-link', title: t('pages.traceCode.openTrace') },
r.shortCode,
),
},
];
// 名称 + 档案编号:点击跳到艺术品档案详情;档案内页(固定 artworkId)为同一作品,无需展示
if (!fixedArtworkId.value) {
cols.push(
{
title: () => t('pages.artwork.title'),
key: 'artwork',
minWidth: 180,
ellipsis: { tooltip: true },
render: (r) =>
r.artwork
? h('a', { class: 'cell-link', onClick: () => goArtwork(r.artwork.id) }, r.artwork.title || '-')
: '-',
},
{
title: () => t('pages.artwork.archiveNo'),
key: 'archiveNo',
width: 140,
align: 'center',
render: (r) =>
r.artwork?.archiveNo
? h('a', { class: 'cell-link', onClick: () => goArtwork(r.artwork.id) }, r.artwork.archiveNo)
: '-',
},
);
}
cols.push(
// 批次编号
{
title: () => renderFilterTitle(t('pages.traceCode.batchNo'), query.batchId, batchOptions.value, (value) => setHeaderFilter('batchId', value)),
key: 'batch',
@@ -372,6 +417,15 @@ const columns = computed<DataTableColumns<any>>(() => {
align: 'center',
render: (r) => r.batch?.batchNo || '-',
},
// 分组
{
title: () => renderFilterTitle(t('pages.traceCode.group'), query.groupId, groupFilterOptions.value, (value) => setHeaderFilter('groupId', value)),
key: 'group',
width: 110,
align: 'center',
render: (r) => r.group?.name || h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noGroup') }),
},
// 出库状态
{
title: () =>
renderFilterTitle(t('pages.traceCode.outboundStatus'), query.outboundStatus, outboundStatusOptions.value, (value) =>
@@ -385,7 +439,7 @@ const columns = computed<DataTableColumns<any>>(() => {
? 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, align: 'center', render: (r) => fmt(r.outTime), ...sortProps('outTime') },
// 上链状态
{
title: () => t('pages.traceCode.onchainStatus'),
key: 'onchainStatus',
@@ -396,12 +450,25 @@ const columns = computed<DataTableColumns<any>>(() => {
? h(NTag, { size: 'small', type: proofStatusType(r.latestAnyProof) }, { default: () => proofStatusText(r.latestAnyProof) })
: h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noOnchain') }),
},
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 120, align: 'center', ellipsis: { tooltip: true } },
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 150, align: 'center', render: (r) => fmt(r.createdAt), ...sortProps('createdAt') },
// 出库时间
{ title: () => t('pages.outbound.outTime'), key: 'outTime', width: 150, align: 'center', render: (r) => fmt(r.outTime), ...sortProps('outTime') },
// 激活状态
{
title: () => renderFilterTitle(t('pages.traceCode.activationStatus'), query.status, statusOptions, (value) => setHeaderFilter('status', value)),
key: 'status',
width: 108,
align: 'center',
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
},
// 查询次数
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 100, align: 'center' },
// 激活时间
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 150, align: 'center', render: (r) => fmt(r.firstActivatedAt), ...sortProps('firstActivatedAt') },
// 链接
{
title: () => t('pages.traceCode.url'),
key: 'url',
minWidth: 420,
minWidth: 360,
ellipsis: { tooltip: true },
render: (r) =>
h(
@@ -410,22 +477,9 @@ const columns = computed<DataTableColumns<any>>(() => {
[r.url, h(NIcon, { component: OpenOutline, style: 'vertical-align:-2px;margin-left:4px' })],
),
},
{
title: () => renderFilterTitle(t('pages.traceCode.group'), query.groupId, groupFilterOptions.value, (value) => setHeaderFilter('groupId', value)),
key: 'group',
width: 110,
align: 'center',
render: (r) => r.group?.name || h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noGroup') }),
},
{
title: () => renderFilterTitle(t('common.label.status'), query.status, statusOptions, (value) => setHeaderFilter('status', value)),
key: 'status',
width: 108,
align: 'center',
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
},
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 100, align: 'center' },
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 150, align: 'center', render: (r) => fmt(r.firstActivatedAt), ...sortProps('firstActivatedAt') },
// 创建时间
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 150, align: 'center', render: (r) => fmt(r.createdAt), ...sortProps('createdAt') },
// 操作
{
title: () => t('common.label.operation'),
key: 'ops',
@@ -451,19 +505,15 @@ const columns = computed<DataTableColumns<any>>(() => {
: null,
]),
},
];
if (!fixedArtworkId.value) {
base.splice(
4,
0,
{ title: () => t('pages.artwork.archiveNo'), key: 'archiveNo', width: 130, align: 'center', render: (r) => r.artwork?.archiveNo || '-' },
{ title: () => t('pages.artwork.title'), key: 'artwork', minWidth: 180, ellipsis: { tooltip: true }, render: (r) => r.artwork?.title || '-' },
);
}
return base;
);
return cols;
});
function goArtwork(id?: number) {
if (!id) return;
router.push({ name: 'artwork-detail', params: { id: String(id) } });
}
type HeaderFilterField = 'batchId' | 'groupId' | 'status' | 'outboundStatus';
type HeaderFilterValue = string | number | null;
type HeaderFilterOption = { label: string; value: string | number };
@@ -1045,6 +1095,14 @@ onUnmounted(() => {
.onchain-tip {
margin-top: 4px;
}
.cell-link {
color: var(--brand);
cursor: pointer;
text-decoration: none;
}
.cell-link:hover {
text-decoration: underline;
}
.onchain-mono {
font-family: 'JetBrains Mono', Consolas, monospace;
font-size: 12px;