feat: 完善档案删除与追溯码筛选

This commit is contained in:
Nixevol
2026-07-04 07:18:52 +08:00
parent e2b54a8027
commit f51f45bcb1
9 changed files with 190 additions and 54 deletions
+100 -30
View File
@@ -1,30 +1,6 @@
<template>
<div :class="['trace-code-panel', { embedded }]">
<div class="panel-toolbar">
<n-select
v-model:value="query.groupId"
:options="groupFilterOptions"
clearable
:placeholder="t('pages.traceCode.allGroups')"
class="toolbar-control"
@update:value="onSearch"
/>
<n-select
v-model:value="query.batchId"
:options="batchOptions"
clearable
:placeholder="t('pages.traceCode.batchNo')"
class="toolbar-control wide"
@update:value="onSearch"
/>
<n-select
v-model:value="query.status"
:options="statusOptions"
clearable
:placeholder="t('common.label.status')"
class="toolbar-control narrow"
@update:value="onSearch"
/>
<n-input
v-model:value="query.keyword"
:placeholder="t('pages.traceCode.shortCode')"
@@ -76,7 +52,7 @@
class="table-fill"
flex-height
remote
:scroll-x="1560"
:scroll-x="1680"
:row-key="(r) => r.id"
v-model:checked-row-keys="checkedKeys"
/>
@@ -215,7 +191,7 @@ import { computed, h, onMounted, reactive, ref, watch } from 'vue';
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 { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline, EllipsisHorizontalOutline, FilterOutline } from '@vicons/ionicons5';
import dayjs from 'dayjs';
import { TraceCodeStatus } from '@artveris/shared';
import { traceCodeApi, jobApi, artworkApi, outboundApi } from '@/api';
@@ -249,16 +225,22 @@ const query = reactive<{
groupId: number | null;
batchId: number | null;
status: string | null;
outboundStatus: string | null;
keyword: string;
}>({
artworkId: fixedArtworkId.value,
groupId: null,
batchId: null,
status: null,
outboundStatus: null,
keyword: '',
});
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load, embedded.value ? 20 : 20);
const statusOptions = Object.values(TraceCodeStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
const outboundStatusOptions = computed(() => [
{ label: t('pages.traceCode.outRegistered'), value: 'OUTBOUND' },
{ label: t('pages.traceCode.notOutbound'), value: 'NOT_OUTBOUND' },
]);
const batchOptions = ref<{ label: string; value: number }[]>([]);
const batchMoveOptions = computed(() => batchOptions.value.map((b) => ({ label: b.label, value: b.value })));
@@ -313,9 +295,17 @@ const outboundForm = reactive<any>({
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'),
title: () => renderFilterTitle(t('pages.traceCode.batchNo'), query.batchId, batchOptions.value, (value) => setHeaderFilter('batchId', value)),
key: 'batch',
width: 150,
render: (r) => r.batch?.batchNo || '-',
},
{
title: () =>
renderFilterTitle(t('pages.traceCode.outboundStatus'), query.outboundStatus, outboundStatusOptions.value, (value) =>
setHeaderFilter('outboundStatus', value),
),
key: 'outboundStatus',
width: 96,
render: (r) =>
@@ -334,6 +324,7 @@ const columns = computed<DataTableColumns<any>>(() => {
: h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noOnchain') }),
},
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 120 },
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 150, render: (r) => fmt(r.createdAt) },
{
title: () => t('pages.traceCode.url'),
key: 'url',
@@ -346,9 +337,14 @@ const columns = computed<DataTableColumns<any>>(() => {
[r.url, h(NIcon, { component: OpenOutline, style: 'vertical-align:-2px;margin-left:4px' })],
),
},
{ title: () => t('pages.traceCode.group'), key: 'group', width: 110, render: (r) => r.group?.name || h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noGroup') }) },
{
title: () => t('common.label.status'),
title: () => renderFilterTitle(t('pages.traceCode.group'), query.groupId, groupFilterOptions.value, (value) => setHeaderFilter('groupId', value)),
key: 'group',
width: 110,
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: 96,
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
@@ -393,6 +389,57 @@ const columns = computed<DataTableColumns<any>>(() => {
return base;
});
type HeaderFilterField = 'batchId' | 'groupId' | 'status' | 'outboundStatus';
type HeaderFilterValue = string | number | null;
type HeaderFilterOption = { label: string; value: string | number };
function renderFilterTitle(
label: string,
value: HeaderFilterValue,
options: HeaderFilterOption[],
onSelect: (value: HeaderFilterValue) => void,
) {
const active = value !== null && value !== undefined && value !== '';
const dropdownOptions: DropdownOption[] = [
{ label: t('common.label.all'), key: '__all__' },
...options.map((option) => ({ label: option.label, key: option.value })),
];
return h('div', { class: 'filter-title' }, [
h('span', { class: 'filter-title-text' }, label),
h(
NDropdown,
{
trigger: 'click',
options: dropdownOptions,
onSelect: (key) => onSelect(key === '__all__' ? null : (key as string | number)),
},
{
default: () =>
h(
NButton,
{
quaternary: true,
circle: true,
size: 'tiny',
class: ['filter-trigger', { active }],
title: t('pages.traceCode.tableFilter'),
},
{ icon: () => h(NIcon, null, { default: () => h(FilterOutline) }) },
),
},
),
]);
}
function setHeaderFilter(field: HeaderFilterField, value: HeaderFilterValue) {
if (field === 'batchId' || field === 'groupId') {
query[field] = typeof value === 'number' ? value : null;
} else {
query[field] = value ? String(value) : null;
}
onSearch();
}
function currentArtworkId() {
return fixedArtworkId.value || query.artworkId || null;
}
@@ -418,6 +465,7 @@ async function load() {
groupId: query.groupId || undefined,
batchId: query.batchId || undefined,
status: query.status || undefined,
outboundStatus: query.outboundStatus || undefined,
keyword: query.keyword || undefined,
page: page.value,
pageSize: pageSize.value,
@@ -516,6 +564,7 @@ async function onExport(key: string) {
if (query.groupId) params.groupId = query.groupId;
if (query.batchId) params.batchId = query.batchId;
if (query.status) params.status = query.status;
if (query.outboundStatus) params.outboundStatus = query.outboundStatus;
if (query.keyword) params.keyword = query.keyword;
}
await downloadFile('/trace-codes/export', `trace-codes.${format}`, params);
@@ -785,6 +834,27 @@ onMounted(async () => {
gap: 4px;
width: 100%;
}
.filter-title {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 4px;
width: 100%;
min-width: 0;
}
.filter-title-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.filter-trigger {
flex: 0 0 auto;
opacity: 0.62;
}
.filter-trigger.active {
color: var(--brand);
opacity: 1;
}
.mr8 {
margin-right: 8px;
}
+4 -1
View File
@@ -232,7 +232,9 @@
"watermarkPending": "Generating watermark…",
"editDetail": "Edit Details",
"dataManage": "Data Management",
"traceCodeManage": "Trace Code Management"
"traceCodeManage": "Trace Code Management",
"deleteConfirm": "Delete this artwork archive? Only archives without trace codes and query logs can be deleted.",
"deleteDisabledTip": "This archive already has trace codes and cannot be deleted"
},
"traceCode": {
"batches": "Batches",
@@ -276,6 +278,7 @@
"outRegistered": "Recorded",
"notOutbound": "Not Outbound",
"noOnchain": "Not On-chain",
"tableFilter": "Filter",
"registerOutbound": "Record Outbound / Chain",
"enableOne": "Enable",
"disableOne": "Disable",
+4 -1
View File
@@ -232,7 +232,9 @@
"watermarkPending": "水印生成中…",
"editDetail": "编辑详情",
"dataManage": "数据管理",
"traceCodeManage": "追溯码管理"
"traceCodeManage": "追溯码管理",
"deleteConfirm": "确认删除该艺术品档案?仅未生成追溯码、无查询记录的档案可删除。",
"deleteDisabledTip": "该档案已生成追溯码,不能删除"
},
"traceCode": {
"batches": "批次列表",
@@ -276,6 +278,7 @@
"outRegistered": "已登记",
"notOutbound": "未出库",
"noOnchain": "未上链",
"tableFilter": "筛选",
"registerOutbound": "登记出库/上链",
"enableOne": "启用",
"disableOne": "禁用",
+31 -2
View File
@@ -49,12 +49,13 @@ import { h, onMounted, reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { NButton, NIcon, NTag, NAvatar, type DataTableColumns } from 'naive-ui';
import { SearchOutline, AddOutline, CreateOutline, BarChartOutline } from '@vicons/ionicons5';
import { SearchOutline, AddOutline, CreateOutline, BarChartOutline, TrashOutline } from '@vicons/ionicons5';
import { ArtworkStatus } from '@artveris/shared';
import { artworkApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { fmt, statusType } from '@/utils/format';
import { useTablePage } from '@/composables/useTablePage';
import { dialog, message } from '@/utils/feedback';
const { t } = useI18n();
const router = useRouter();
@@ -106,7 +107,7 @@ const columns: DataTableColumns<any> = [
{
title: () => t('common.label.operation'),
key: 'ops',
width: 112,
width: 148,
fixed: 'right',
align: 'center',
render: (r) =>
@@ -133,6 +134,21 @@ const columns: DataTableColumns<any> = [
},
{ icon: () => h(NIcon, null, { default: () => h(BarChartOutline) }) },
),
auth.canWrite
? h(
NButton,
{
quaternary: true,
circle: true,
size: 'small',
type: 'error',
disabled: (r.codeCount ?? 0) > 0,
title: (r.codeCount ?? 0) > 0 ? t('pages.artwork.deleteDisabledTip') : t('common.action.delete'),
onClick: () => remove(r),
},
{ icon: () => h(NIcon, null, { default: () => h(TrashOutline) }) },
)
: null,
]),
},
];
@@ -159,6 +175,19 @@ function onSearch() {
function goCreate() {
router.push('/artworks/new');
}
function remove(r: any) {
dialog.warning({
title: t('common.action.delete'),
content: t('pages.artwork.deleteConfirm'),
positiveText: t('common.action.confirm'),
negativeText: t('common.action.cancel'),
onPositiveClick: async () => {
await artworkApi.remove(r.id);
message.success(t('common.msg.deleted'));
await load();
},
});
}
onMounted(load);
</script>