refactor: 合并档案与实物码管理入口
This commit is contained in:
@@ -0,0 +1,522 @@
|
||||
<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')"
|
||||
clearable
|
||||
class="toolbar-control"
|
||||
@keyup.enter="onSearch"
|
||||
/>
|
||||
<n-button type="primary" @click="onSearch">
|
||||
<template #icon><n-icon :component="SearchOutline" /></template>
|
||||
{{ t('common.action.search') }}
|
||||
</n-button>
|
||||
<div class="spacer" />
|
||||
<n-button v-if="auth.canWrite" @click="groupModal = true">
|
||||
<template #icon><n-icon :component="FolderOutline" /></template>
|
||||
{{ t('pages.traceCode.manageGroups') }}
|
||||
</n-button>
|
||||
<n-dropdown v-if="auth.canWrite" trigger="click" :options="exportOptions" @select="onExport">
|
||||
<n-button>
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('common.action.export') }}
|
||||
</n-button>
|
||||
</n-dropdown>
|
||||
<n-button v-if="auth.canWrite" type="primary" @click="openGenerate">
|
||||
<template #icon><n-icon :component="AddOutline" /></template>
|
||||
{{ t('pages.traceCode.generate') }}
|
||||
</n-button>
|
||||
</div>
|
||||
|
||||
<n-card v-if="auth.canWrite && checkedKeys.length" size="small" class="batch-bar" :bordered="false">
|
||||
<n-space align="center">
|
||||
<span>{{ t('pages.traceCode.selected', { n: checkedKeys.length }) }}</span>
|
||||
<n-dropdown trigger="click" :options="groupAssignOptions" @select="batchAssignGroup">
|
||||
<n-button size="small">
|
||||
<template #icon><n-icon :component="FolderOutline" /></template>
|
||||
{{ t('pages.traceCode.batchGroup') }}
|
||||
</n-button>
|
||||
</n-dropdown>
|
||||
<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>
|
||||
</n-card>
|
||||
|
||||
<n-data-table
|
||||
:columns="columns"
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
v-model:checked-row-keys="checkedKeys"
|
||||
@update:page="onPage"
|
||||
/>
|
||||
|
||||
<n-modal v-model:show="genModal" preset="card" :title="t('pages.traceCode.generate')" style="width: 440px">
|
||||
<n-form :model="genForm" label-placement="top">
|
||||
<n-form-item v-if="!fixedArtworkId" :label="t('pages.artwork.selectArtwork')" required>
|
||||
<n-select
|
||||
v-model:value="genForm.artworkId"
|
||||
filterable
|
||||
remote
|
||||
clearable
|
||||
:loading="artworkSearching"
|
||||
:options="artworkOptions"
|
||||
:placeholder="t('pages.artwork.selectArtworkTip')"
|
||||
@search="searchArtworks"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.traceCode.quantity')">
|
||||
<n-input-number v-model:value="genForm.quantity" :min="1" :max="10000" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.traceCode.group')">
|
||||
<n-select v-model:value="genForm.groupId" :options="groupPlainOptions" clearable :placeholder="t('pages.traceCode.noGroup')" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.traceCode.batchNo')">
|
||||
<n-input v-model:value="genForm.batchNo" placeholder="(auto)" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<n-text v-if="generating" depth="3">{{ t('pages.traceCode.generating') }}</n-text>
|
||||
<template #footer>
|
||||
<div style="text-align: right">
|
||||
<n-button class="mr8" @click="genModal = false">{{ t('common.action.cancel') }}</n-button>
|
||||
<n-button type="primary" :loading="generating" @click="generate">{{ t('common.action.generate') }}</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<n-modal v-model:show="qrModal" preset="card" :title="t('pages.traceCode.qrPreview')" style="width: 360px">
|
||||
<div style="text-align: center">
|
||||
<img :src="qrSrc" alt="qrcode" style="width: 280px; height: 280px" />
|
||||
<div style="margin-top: 8px; opacity: 0.6; word-break: break-all">{{ qrUrl }}</div>
|
||||
</div>
|
||||
</n-modal>
|
||||
|
||||
<n-modal v-model:show="groupModal" preset="card" :title="t('pages.traceCode.manageGroups')" style="width: 520px">
|
||||
<div class="panel-toolbar group-toolbar">
|
||||
<n-input v-model:value="groupForm.name" :placeholder="t('pages.traceCode.groupName')" style="width: 200px" />
|
||||
<n-button type="primary" :disabled="!groupForm.name" @click="saveGroup">
|
||||
{{ editingGroup ? t('common.action.save') : t('pages.traceCode.createGroup') }}
|
||||
</n-button>
|
||||
<n-button v-if="editingGroup" @click="resetGroupForm">{{ t('common.action.cancel') }}</n-button>
|
||||
</div>
|
||||
<n-list bordered>
|
||||
<n-list-item v-for="g in groups" :key="g.id">
|
||||
<div class="group-row">
|
||||
<span>{{ g.name }}<n-text depth="3">({{ g._count?.traceCodes ?? 0 }})</n-text></span>
|
||||
<span>
|
||||
<n-button text type="primary" size="small" @click="editGroup(g)">{{ t('common.action.edit') }}</n-button>
|
||||
<n-button text type="error" size="small" style="margin-left: 10px" @click="removeGroup(g)">{{ t('common.action.delete') }}</n-button>
|
||||
</span>
|
||||
</div>
|
||||
</n-list-item>
|
||||
</n-list>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NButton, NIcon, NTag, NText, type DataTableColumns } from 'naive-ui';
|
||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline } from '@vicons/ionicons5';
|
||||
import { TraceCodeStatus } from '@artveris/shared';
|
||||
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
|
||||
const props = defineProps<{
|
||||
artworkId?: number;
|
||||
embedded?: boolean;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const auth = useAuthStore();
|
||||
|
||||
const fixedArtworkId = computed(() => props.artworkId || null);
|
||||
const embedded = computed(() => props.embedded === true);
|
||||
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const checkedKeys = ref<Array<string | number>>([]);
|
||||
const query = reactive<{
|
||||
artworkId: number | null;
|
||||
groupId: number | null;
|
||||
batchId: number | null;
|
||||
status: string | null;
|
||||
keyword: string;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}>({
|
||||
artworkId: fixedArtworkId.value,
|
||||
groupId: null,
|
||||
batchId: null,
|
||||
status: null,
|
||||
keyword: '',
|
||||
page: 1,
|
||||
pageSize: embedded.value ? 8 : 10,
|
||||
});
|
||||
const pagination = reactive({ page: 1, pageSize: query.pageSize, itemCount: 0 });
|
||||
const statusOptions = Object.values(TraceCodeStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
||||
|
||||
const batchOptions = ref<{ label: string; value: number }[]>([]);
|
||||
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 })));
|
||||
const groupAssignOptions = computed(() => [
|
||||
{ label: t('pages.traceCode.noGroup'), key: '__none__' },
|
||||
...groups.value.map((g) => ({ label: g.name, key: String(g.id) })),
|
||||
]);
|
||||
|
||||
const genModal = ref(false);
|
||||
const generating = ref(false);
|
||||
const genForm = reactive<{ artworkId: number | null; quantity: number; batchNo: string; groupId: number | null }>({
|
||||
artworkId: fixedArtworkId.value,
|
||||
quantity: 100,
|
||||
batchNo: '',
|
||||
groupId: null,
|
||||
});
|
||||
|
||||
const artworkSearching = ref(false);
|
||||
const artworkOptions = ref<{ label: string; value: number }[]>([]);
|
||||
let artworkTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const qrModal = ref(false);
|
||||
const qrSrc = ref('');
|
||||
const qrUrl = ref('');
|
||||
|
||||
const groupModal = ref(false);
|
||||
const groupForm = reactive<{ name: string }>({ name: '' });
|
||||
const editingGroup = ref<number | null>(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.shortCode'), key: 'shortCode', width: 120 },
|
||||
{
|
||||
title: () => t('pages.traceCode.url'),
|
||||
key: 'url',
|
||||
ellipsis: { tooltip: true },
|
||||
render: (r) =>
|
||||
h(
|
||||
'a',
|
||||
{ href: r.url, target: '_blank', rel: 'noopener', style: 'color: var(--brand); text-decoration: none' },
|
||||
[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'),
|
||||
key: 'status',
|
||||
width: 96,
|
||||
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
|
||||
},
|
||||
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 84 },
|
||||
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 150, render: (r) => fmt(r.firstActivatedAt) },
|
||||
{
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 70,
|
||||
render: (r) =>
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
||||
},
|
||||
];
|
||||
|
||||
if (!fixedArtworkId.value) {
|
||||
base.splice(
|
||||
4,
|
||||
0,
|
||||
{ title: () => t('pages.artwork.archiveNo'), key: 'archiveNo', width: 130, render: (r) => r.artwork?.archiveNo || '-' },
|
||||
{ title: () => t('pages.artwork.title'), key: 'artwork', width: 130, render: (r) => r.artwork?.title || '-' },
|
||||
);
|
||||
}
|
||||
return base;
|
||||
});
|
||||
|
||||
function currentArtworkId() {
|
||||
return fixedArtworkId.value || query.artworkId || null;
|
||||
}
|
||||
|
||||
async function loadBatches() {
|
||||
const params: Record<string, unknown> = { pageSize: 100 };
|
||||
const aid = currentArtworkId();
|
||||
if (aid) params.artworkId = aid;
|
||||
const res: any = await traceCodeApi.batches(params);
|
||||
batchOptions.value = res.list.map((b: any) => ({ label: `${b.batchNo} (${b.generatedCount}/${b.quantity})`, value: b.id }));
|
||||
}
|
||||
|
||||
async function loadGroups() {
|
||||
groups.value = await traceCodeApi.groups();
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
checkedKeys.value = [];
|
||||
try {
|
||||
const res: any = await traceCodeApi.list({
|
||||
artworkId: currentArtworkId() || undefined,
|
||||
groupId: query.groupId || undefined,
|
||||
batchId: query.batchId || undefined,
|
||||
status: query.status || undefined,
|
||||
keyword: query.keyword || undefined,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
});
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
query.page = 1;
|
||||
load();
|
||||
}
|
||||
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
load();
|
||||
}
|
||||
|
||||
function openGenerate() {
|
||||
genForm.artworkId = fixedArtworkId.value || query.artworkId;
|
||||
genModal.value = true;
|
||||
}
|
||||
|
||||
function searchArtworks(keyword: string) {
|
||||
if (artworkTimer) clearTimeout(artworkTimer);
|
||||
artworkTimer = setTimeout(async () => {
|
||||
artworkSearching.value = true;
|
||||
try {
|
||||
const res: any = await artworkApi.list({ keyword: keyword || undefined, pageSize: 20 });
|
||||
artworkOptions.value = res.list.map((a: any) => ({
|
||||
label: `${a.archiveNo || '-'} - ${a.title}`,
|
||||
value: a.id,
|
||||
}));
|
||||
} finally {
|
||||
artworkSearching.value = false;
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
const targetArtworkId = fixedArtworkId.value || genForm.artworkId;
|
||||
if (!targetArtworkId) {
|
||||
message.error(t('pages.artwork.selectArtworkTip'));
|
||||
return;
|
||||
}
|
||||
generating.value = true;
|
||||
try {
|
||||
const res: any = await traceCodeApi.generate({
|
||||
artworkId: targetArtworkId,
|
||||
quantity: genForm.quantity,
|
||||
batchNo: genForm.batchNo || undefined,
|
||||
groupId: genForm.groupId || undefined,
|
||||
});
|
||||
message.success(t('pages.traceCode.genSuccess'));
|
||||
for (let i = 0; i < 30; i++) {
|
||||
await new Promise((r) => setTimeout(r, 700));
|
||||
const job: any = await jobApi.get(res.jobId);
|
||||
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
|
||||
}
|
||||
genModal.value = false;
|
||||
genForm.batchNo = '';
|
||||
await loadBatches();
|
||||
await load();
|
||||
} finally {
|
||||
generating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function showQr(r: any) {
|
||||
qrSrc.value = traceCodeApi.qrUrl(r.id);
|
||||
qrUrl.value = r.url;
|
||||
qrModal.value = true;
|
||||
}
|
||||
|
||||
const exportOptions = computed(() => {
|
||||
const cur = t('pages.traceCode.exportCurrent');
|
||||
const opts: Array<{ label: string; key: string }> = [
|
||||
{ label: `Excel - ${cur}`, key: 'filter:xlsx' },
|
||||
{ label: `CSV - ${cur}`, key: 'filter:csv' },
|
||||
];
|
||||
if (checkedKeys.value.length) {
|
||||
const sel = t('pages.traceCode.selected', { n: checkedKeys.value.length });
|
||||
opts.push({ label: `Excel - ${sel}`, key: 'selected:xlsx' });
|
||||
opts.push({ label: `CSV - ${sel}`, key: 'selected:csv' });
|
||||
}
|
||||
return opts;
|
||||
});
|
||||
|
||||
async function onExport(key: string) {
|
||||
const [scope, format] = key.split(':');
|
||||
const params: Record<string, unknown> = { format };
|
||||
if (scope === 'selected') {
|
||||
params.ids = checkedKeys.value.map(String).join(',');
|
||||
} else {
|
||||
const aid = currentArtworkId();
|
||||
if (aid) params.artworkId = aid;
|
||||
if (query.groupId) params.groupId = query.groupId;
|
||||
if (query.batchId) params.batchId = query.batchId;
|
||||
if (query.status) params.status = query.status;
|
||||
if (query.keyword) params.keyword = query.keyword;
|
||||
}
|
||||
await downloadFile('/trace-codes/export', `trace-codes.${format}`, params);
|
||||
}
|
||||
|
||||
async function batchAssignGroup(key: string) {
|
||||
const groupId = key === '__none__' ? null : Number(key);
|
||||
await traceCodeApi.batchGroup(checkedKeys.value.map(String), groupId);
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
await load();
|
||||
}
|
||||
|
||||
async function batchStatus(disabled: boolean) {
|
||||
await traceCodeApi.batchStatus(checkedKeys.value.map(String), disabled);
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
await load();
|
||||
}
|
||||
|
||||
function resetGroupForm() {
|
||||
editingGroup.value = null;
|
||||
groupForm.name = '';
|
||||
}
|
||||
|
||||
function editGroup(g: any) {
|
||||
editingGroup.value = g.id;
|
||||
groupForm.name = g.name;
|
||||
}
|
||||
|
||||
async function saveGroup() {
|
||||
if (editingGroup.value) {
|
||||
await traceCodeApi.updateGroup(editingGroup.value, { name: groupForm.name });
|
||||
} else {
|
||||
await traceCodeApi.createGroup({ name: groupForm.name });
|
||||
}
|
||||
message.success(t('common.msg.saved'));
|
||||
resetGroupForm();
|
||||
await loadGroups();
|
||||
}
|
||||
|
||||
function removeGroup(g: any) {
|
||||
dialog.warning({
|
||||
title: t('common.action.delete'),
|
||||
content: t('common.msg.confirmDelete'),
|
||||
positiveText: t('common.action.confirm'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
await traceCodeApi.removeGroup(g.id);
|
||||
message.success(t('common.msg.deleted'));
|
||||
await loadGroups();
|
||||
await load();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
watch(
|
||||
() => fixedArtworkId.value,
|
||||
async (aid) => {
|
||||
query.artworkId = aid;
|
||||
genForm.artworkId = aid;
|
||||
query.batchId = null;
|
||||
query.page = 1;
|
||||
await loadBatches();
|
||||
await load();
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
if (!fixedArtworkId.value) {
|
||||
const aid = Number(route.query.artworkId);
|
||||
if (aid) {
|
||||
query.artworkId = aid;
|
||||
genForm.artworkId = aid;
|
||||
}
|
||||
}
|
||||
await Promise.all([loadBatches(), loadGroups()]);
|
||||
await load();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.trace-code-panel {
|
||||
min-width: 0;
|
||||
}
|
||||
.panel-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.toolbar-control {
|
||||
width: 170px;
|
||||
}
|
||||
.toolbar-control.wide {
|
||||
width: 210px;
|
||||
}
|
||||
.toolbar-control.narrow {
|
||||
width: 130px;
|
||||
}
|
||||
.spacer {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
.batch-bar {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.group-toolbar {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.group-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
}
|
||||
.mr8 {
|
||||
margin-right: 8px;
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
.toolbar-control,
|
||||
.toolbar-control.wide,
|
||||
.toolbar-control.narrow {
|
||||
width: 100%;
|
||||
}
|
||||
.panel-toolbar :deep(.n-button) {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -59,7 +59,6 @@ import {
|
||||
GridOutline,
|
||||
DocumentTextOutline,
|
||||
ImagesOutline,
|
||||
QrCodeOutline,
|
||||
CubeOutline,
|
||||
ListOutline,
|
||||
PeopleOutline,
|
||||
@@ -92,7 +91,6 @@ const menuOptions = computed<MenuOption[]>(() => {
|
||||
{ label: t('menu.dashboard'), key: 'dashboard', icon: renderIcon(GridOutline) },
|
||||
{ label: t('menu.templates'), key: 'templates', icon: renderIcon(DocumentTextOutline) },
|
||||
{ label: t('menu.artworks'), key: 'artworks', icon: renderIcon(ImagesOutline) },
|
||||
{ label: t('menu.traceCodes'), key: 'traceCodes', icon: renderIcon(QrCodeOutline) },
|
||||
{ label: t('menu.outbound'), key: 'outbound', icon: renderIcon(CubeOutline) },
|
||||
{ label: t('menu.audit'), key: 'audit', icon: renderIcon(ShieldCheckmarkOutline), auditOnly: true },
|
||||
{ label: t('menu.queryLogs'), key: 'queryLogs', icon: renderIcon(ListOutline) },
|
||||
@@ -104,7 +102,7 @@ const menuOptions = computed<MenuOption[]>(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const activeKey = computed(() => (route.name === 'artwork-detail' ? 'artworks' : (route.name as string)));
|
||||
const activeKey = computed(() => (['artwork-detail', 'traceCodes'].includes(route.name as string) ? 'artworks' : (route.name as string)));
|
||||
const currentTitle = computed(() => (activeKey.value ? t(`menu.${activeKey.value}`) : ''));
|
||||
|
||||
const userOptions = computed(() => [
|
||||
|
||||
@@ -119,8 +119,8 @@
|
||||
"menu": {
|
||||
"dashboard": "Dashboard",
|
||||
"templates": "Templates",
|
||||
"artworks": "Artworks",
|
||||
"traceCodes": "Trace Codes",
|
||||
"artworks": "Artwork Files",
|
||||
"traceCodes": "Item Codes",
|
||||
"outbound": "Outbound & Chain",
|
||||
"audit": "Content Audit",
|
||||
"queryLogs": "Query Logs",
|
||||
@@ -187,8 +187,8 @@
|
||||
"codeCount": "Codes",
|
||||
"activeCount": "Activated",
|
||||
"queryTotal": "Total Queries",
|
||||
"traceCodes": "Trace Codes (multi-code)",
|
||||
"genCodes": "Generate Codes",
|
||||
"traceCodes": "Batches & Item Codes",
|
||||
"genCodes": "Generate Item Codes",
|
||||
"viewCodes": "View All Codes",
|
||||
"batches": "Batches",
|
||||
"selectArtwork": "Select Artwork",
|
||||
@@ -227,7 +227,7 @@
|
||||
"codes": "Trace Codes",
|
||||
"batchNo": "Batch No.",
|
||||
"quantity": "Quantity",
|
||||
"generate": "Generate",
|
||||
"generate": "Generate Item Codes",
|
||||
"generatedCount": "Generated",
|
||||
"shortCode": "Short Code",
|
||||
"code": "Trace Code",
|
||||
@@ -236,7 +236,7 @@
|
||||
"firstActivatedAt": "First Activated",
|
||||
"exportBatch": "Export Batch",
|
||||
"exportCurrent": "Current filter",
|
||||
"bindArtwork": "Bind Artwork",
|
||||
"bindArtwork": "Link Artwork File",
|
||||
"selectArtwork": "Select artwork",
|
||||
"qrPreview": "QR Preview",
|
||||
"generating": "Generating, please wait…",
|
||||
@@ -263,7 +263,7 @@
|
||||
"outTime": "Outbound Time",
|
||||
"outImage": "Outbound Photo",
|
||||
"selectCode": "Select Trace Code",
|
||||
"selectCodePlaceholder": "Search by short code / SKU / archive no.",
|
||||
"selectCodePlaceholder": "Search by short code / trace code / archive no.",
|
||||
"onchainSection": "On-chain info (optional; filling a hash records the result)",
|
||||
"txHashTip": "Paste the on-chain transaction/attestation hash",
|
||||
"selectFile": "Select File",
|
||||
@@ -291,7 +291,7 @@
|
||||
"queriedAt": "Time",
|
||||
"startTime": "Start",
|
||||
"endTime": "End",
|
||||
"keywordPlaceholder": "Short code / trace code / SKU / archive no."
|
||||
"keywordPlaceholder": "Short code / trace code / archive no."
|
||||
},
|
||||
"user": {
|
||||
"username": "Username",
|
||||
|
||||
@@ -119,8 +119,8 @@
|
||||
"menu": {
|
||||
"dashboard": "数据看板",
|
||||
"templates": "溯源模板",
|
||||
"artworks": "艺术品建档",
|
||||
"traceCodes": "追溯码管理",
|
||||
"artworks": "艺术品档案",
|
||||
"traceCodes": "实物码明细",
|
||||
"outbound": "出库与上链",
|
||||
"audit": "内容审核",
|
||||
"queryLogs": "查询日志",
|
||||
@@ -187,8 +187,8 @@
|
||||
"codeCount": "追溯码数",
|
||||
"activeCount": "已激活",
|
||||
"queryTotal": "查询总数",
|
||||
"traceCodes": "追溯码(一款多码)",
|
||||
"genCodes": "生成追溯码",
|
||||
"traceCodes": "批次与实物码",
|
||||
"genCodes": "生成实物码",
|
||||
"viewCodes": "查看全部码",
|
||||
"batches": "批次列表",
|
||||
"selectArtwork": "选择作品",
|
||||
@@ -227,7 +227,7 @@
|
||||
"codes": "追溯码列表",
|
||||
"batchNo": "批次编号",
|
||||
"quantity": "数量",
|
||||
"generate": "生成追溯码",
|
||||
"generate": "生成实物码",
|
||||
"generatedCount": "已生成",
|
||||
"shortCode": "短码",
|
||||
"code": "追溯码",
|
||||
@@ -236,7 +236,7 @@
|
||||
"firstActivatedAt": "首次激活时间",
|
||||
"exportBatch": "导出本批",
|
||||
"exportCurrent": "当前筛选",
|
||||
"bindArtwork": "绑定作品",
|
||||
"bindArtwork": "关联作品档案",
|
||||
"selectArtwork": "选择作品",
|
||||
"qrPreview": "二维码预览",
|
||||
"generating": "正在生成,请稍候…",
|
||||
@@ -263,7 +263,7 @@
|
||||
"outTime": "出库时间",
|
||||
"outImage": "出库实况图",
|
||||
"selectCode": "选择追溯码",
|
||||
"selectCodePlaceholder": "输入短码 / SKU / 档案号搜索",
|
||||
"selectCodePlaceholder": "输入短码 / 追溯码 / 档案号搜索",
|
||||
"onchainSection": "上链信息(选填,填写哈希即登记上链结果)",
|
||||
"txHashTip": "粘贴链上交易/存证哈希",
|
||||
"selectFile": "选择文件",
|
||||
@@ -291,7 +291,7 @@
|
||||
"queriedAt": "查询时间",
|
||||
"startTime": "开始时间",
|
||||
"endTime": "结束时间",
|
||||
"keywordPlaceholder": "短码 / 追溯码 / SKU / 档案号"
|
||||
"keywordPlaceholder": "短码 / 追溯码 / 档案号"
|
||||
},
|
||||
"user": {
|
||||
"username": "用户名",
|
||||
|
||||
@@ -185,56 +185,23 @@
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
|
||||
<!-- 追溯码(一款多码) -->
|
||||
<!-- 批次与实物码:每套实物一码 -->
|
||||
<n-grid-item>
|
||||
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false">
|
||||
<template #header-extra>
|
||||
<n-space>
|
||||
<n-button v-if="auth.canWrite" size="small" type="primary" @click="genModal = true">
|
||||
<template #icon><n-icon :component="AddOutline" /></template>
|
||||
{{ t('pages.artwork.genCodes') }}
|
||||
</n-button>
|
||||
<n-button size="small" @click="goCodes">{{ t('pages.artwork.viewCodes') }}</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
<n-descriptions :column="4" label-placement="top" bordered size="small">
|
||||
<n-descriptions-item :label="t('pages.artwork.archiveNo')">{{ artwork?.archiveNo || '-' }}</n-descriptions-item>
|
||||
<n-descriptions-item :label="t('pages.artwork.codeCount')">{{ artwork?.codeStats?.total ?? 0 }}</n-descriptions-item>
|
||||
<n-descriptions-item :label="t('pages.artwork.activeCount')">{{ artwork?.codeStats?.active ?? 0 }}</n-descriptions-item>
|
||||
<n-descriptions-item :label="t('pages.artwork.queryTotal')">{{ artwork?.codeStats?.queryTotal ?? 0 }}</n-descriptions-item>
|
||||
</n-descriptions>
|
||||
<div class="batch-title">{{ t('pages.artwork.batches') }}</div>
|
||||
<n-empty v-if="!artwork?.batches?.length" :description="t('common.msg.noData')" size="small" />
|
||||
<n-data-table
|
||||
v-else
|
||||
size="small"
|
||||
:columns="batchColumns"
|
||||
:data="artwork.batches"
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
<div class="trace-panel-wrap">
|
||||
<trace-code-panel :artwork-id="artworkId" embedded />
|
||||
</div>
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
</template>
|
||||
</n-grid>
|
||||
|
||||
<!-- 生码弹窗 -->
|
||||
<n-modal v-model:show="genModal" preset="card" :title="t('pages.artwork.genCodes')" style="width:420px">
|
||||
<n-form :model="genForm" label-placement="top">
|
||||
<n-form-item :label="t('pages.traceCode.quantity')">
|
||||
<n-input-number v-model:value="genForm.quantity" :min="1" :max="10000" style="width:100%" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.traceCode.batchNo')">
|
||||
<n-input v-model:value="genForm.batchNo" placeholder="(auto)" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div style="text-align:right">
|
||||
<n-button class="mr8" @click="genModal = false">{{ t('common.action.cancel') }}</n-button>
|
||||
<n-button type="primary" :loading="generating" @click="genCodes">{{ t('common.action.generate') }}</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<!-- 节点弹窗 -->
|
||||
<n-modal v-model:show="nodeModal" preset="card" :title="t('pages.artwork.addNode')" style="width:560px;max-width:94vw">
|
||||
<n-form :model="nodeForm" label-placement="top">
|
||||
@@ -297,15 +264,16 @@
|
||||
import { computed, h, onMounted, reactive, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NTag, type DataTableColumns, type FormInst, type FormRules } from 'naive-ui';
|
||||
import { NTag, type FormInst, type FormRules } from 'naive-ui';
|
||||
import { ArrowBackOutline, AddOutline } from '@vicons/ionicons5';
|
||||
import { ArtworkStatus, CertType, NodeType } from '@artveris/shared';
|
||||
import { artworkApi, templateApi, traceCodeApi, jobApi } from '@/api';
|
||||
import { artworkApi, templateApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
import MediaSorter from '@/components/MediaSorter.vue';
|
||||
import TraceCodePanel from '@/components/TraceCodePanel.vue';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, fmtDate, statusType } from '@/utils/format';
|
||||
import { fmtDate } from '@/utils/format';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
@@ -508,49 +476,6 @@ function removeCert(c: any) {
|
||||
});
|
||||
}
|
||||
|
||||
/* 追溯码(一款多码):生码 + 批次 */
|
||||
const batchColumns: DataTableColumns<any> = [
|
||||
{ title: () => t('pages.traceCode.batchNo'), key: 'batchNo' },
|
||||
{ title: () => t('pages.traceCode.quantity'), key: 'quantity', width: 90 },
|
||||
{ title: () => t('pages.traceCode.generatedCount'), key: 'generatedCount', width: 90 },
|
||||
{
|
||||
title: () => t('common.label.status'),
|
||||
key: 'status',
|
||||
width: 100,
|
||||
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
|
||||
},
|
||||
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 160, render: (r) => fmt(r.createdAt) },
|
||||
];
|
||||
|
||||
const genModal = ref(false);
|
||||
const generating = ref(false);
|
||||
const genForm = reactive<{ quantity: number; batchNo: string }>({ quantity: 100, batchNo: '' });
|
||||
|
||||
async function genCodes() {
|
||||
generating.value = true;
|
||||
try {
|
||||
const res: any = await traceCodeApi.generate({
|
||||
artworkId: artworkId.value,
|
||||
quantity: genForm.quantity,
|
||||
batchNo: genForm.batchNo || undefined,
|
||||
});
|
||||
message.success(t('pages.traceCode.genSuccess'));
|
||||
for (let i = 0; i < 30; i++) {
|
||||
await new Promise((r) => setTimeout(r, 700));
|
||||
const job: any = await jobApi.get(res.jobId);
|
||||
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
|
||||
}
|
||||
genModal.value = false;
|
||||
genForm.batchNo = '';
|
||||
await loadArtwork();
|
||||
} finally {
|
||||
generating.value = false;
|
||||
}
|
||||
}
|
||||
function goCodes() {
|
||||
router.push({ name: 'traceCodes', query: { artworkId: String(artworkId.value) } });
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadTemplates();
|
||||
if (!isNew.value) await loadArtwork();
|
||||
@@ -565,10 +490,8 @@ onMounted(async () => {
|
||||
.mr8 {
|
||||
margin-right: 8px;
|
||||
}
|
||||
.batch-title {
|
||||
font-size: 13px;
|
||||
color: #6b7280;
|
||||
margin: 14px 0 8px;
|
||||
.trace-panel-wrap {
|
||||
margin-top: 14px;
|
||||
}
|
||||
.node-head {
|
||||
display: flex;
|
||||
|
||||
@@ -1,422 +1,9 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page-toolbar">
|
||||
<n-select
|
||||
v-model:value="query.groupId"
|
||||
:options="groupFilterOptions"
|
||||
clearable
|
||||
:placeholder="t('pages.traceCode.allGroups')"
|
||||
style="width: 170px"
|
||||
@update:value="onSearch"
|
||||
/>
|
||||
<n-select
|
||||
v-model:value="query.batchId"
|
||||
:options="batchOptions"
|
||||
clearable
|
||||
:placeholder="t('pages.traceCode.batchNo')"
|
||||
style="width: 190px"
|
||||
@update:value="onSearch"
|
||||
/>
|
||||
<n-select
|
||||
v-model:value="query.status"
|
||||
:options="statusOptions"
|
||||
clearable
|
||||
:placeholder="t('common.label.status')"
|
||||
style="width: 130px"
|
||||
@update:value="onSearch"
|
||||
/>
|
||||
<n-input
|
||||
v-model:value="query.keyword"
|
||||
:placeholder="t('pages.traceCode.shortCode')"
|
||||
clearable
|
||||
style="width: 160px"
|
||||
@keyup.enter="onSearch"
|
||||
/>
|
||||
<n-button type="primary" @click="onSearch">
|
||||
<template #icon><n-icon :component="SearchOutline" /></template>
|
||||
{{ t('common.action.search') }}
|
||||
</n-button>
|
||||
<div class="spacer" />
|
||||
<n-button v-if="auth.canWrite" @click="groupModal = true">
|
||||
<template #icon><n-icon :component="FolderOutline" /></template>
|
||||
{{ t('pages.traceCode.manageGroups') }}
|
||||
</n-button>
|
||||
<n-dropdown v-if="auth.canWrite" trigger="click" :options="exportOptions" @select="onExport">
|
||||
<n-button>
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('common.action.export') }}
|
||||
</n-button>
|
||||
</n-dropdown>
|
||||
<n-button v-if="auth.canWrite" type="primary" @click="genModal = true">
|
||||
<template #icon><n-icon :component="AddOutline" /></template>
|
||||
{{ t('pages.traceCode.generate') }}
|
||||
</n-button>
|
||||
</div>
|
||||
|
||||
<!-- 批量操作条 -->
|
||||
<n-card v-if="auth.canWrite && checkedKeys.length" size="small" class="batch-bar" :bordered="false">
|
||||
<n-space align="center">
|
||||
<span>{{ t('pages.traceCode.selected', { n: checkedKeys.length }) }}</span>
|
||||
<n-dropdown trigger="click" :options="groupAssignOptions" @select="batchAssignGroup">
|
||||
<n-button size="small">
|
||||
<template #icon><n-icon :component="FolderOutline" /></template>
|
||||
{{ t('pages.traceCode.batchGroup') }}
|
||||
</n-button>
|
||||
</n-dropdown>
|
||||
<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>
|
||||
</n-card>
|
||||
|
||||
<n-data-table
|
||||
:columns="columns"
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
v-model:checked-row-keys="checkedKeys"
|
||||
@update:page="onPage"
|
||||
/>
|
||||
|
||||
<!-- 生成 -->
|
||||
<n-modal v-model:show="genModal" preset="card" :title="t('pages.traceCode.generate')" style="width: 440px">
|
||||
<n-form :model="genForm" label-placement="top">
|
||||
<n-form-item :label="t('pages.artwork.selectArtwork')" required>
|
||||
<n-select
|
||||
v-model:value="genForm.artworkId"
|
||||
filterable
|
||||
remote
|
||||
clearable
|
||||
:loading="artworkSearching"
|
||||
:options="artworkOptions"
|
||||
:placeholder="t('pages.artwork.selectArtworkTip')"
|
||||
@search="searchArtworks"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.traceCode.quantity')">
|
||||
<n-input-number v-model:value="genForm.quantity" :min="1" :max="10000" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.traceCode.group')">
|
||||
<n-select v-model:value="genForm.groupId" :options="groupPlainOptions" clearable :placeholder="t('pages.traceCode.noGroup')" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.traceCode.batchNo')">
|
||||
<n-input v-model:value="genForm.batchNo" placeholder="(auto)" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<n-text v-if="generating" depth="3">{{ t('pages.traceCode.generating') }}</n-text>
|
||||
<template #footer>
|
||||
<div style="text-align: right">
|
||||
<n-button class="mr8" @click="genModal = false">{{ t('common.action.cancel') }}</n-button>
|
||||
<n-button type="primary" :loading="generating" @click="generate">{{ t('common.action.generate') }}</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<!-- 二维码 -->
|
||||
<n-modal v-model:show="qrModal" preset="card" :title="t('pages.traceCode.qrPreview')" style="width: 360px">
|
||||
<div style="text-align: center">
|
||||
<img :src="qrSrc" alt="qrcode" style="width: 280px; height: 280px" />
|
||||
<div style="margin-top: 8px; opacity: 0.6; word-break: break-all">{{ qrUrl }}</div>
|
||||
</div>
|
||||
</n-modal>
|
||||
|
||||
<!-- 分组管理 -->
|
||||
<n-modal v-model:show="groupModal" preset="card" :title="t('pages.traceCode.manageGroups')" style="width: 520px">
|
||||
<div class="page-toolbar">
|
||||
<n-input v-model:value="groupForm.name" :placeholder="t('pages.traceCode.groupName')" style="width: 200px" />
|
||||
<n-button type="primary" :disabled="!groupForm.name" @click="saveGroup">
|
||||
{{ editingGroup ? t('common.action.save') : t('pages.traceCode.createGroup') }}
|
||||
</n-button>
|
||||
<n-button v-if="editingGroup" @click="resetGroupForm">{{ t('common.action.cancel') }}</n-button>
|
||||
</div>
|
||||
<n-list bordered>
|
||||
<n-list-item v-for="g in groups" :key="g.id">
|
||||
<div class="group-row">
|
||||
<span>{{ g.name }}<n-text depth="3">({{ g._count?.traceCodes ?? 0 }})</n-text></span>
|
||||
<span>
|
||||
<n-button text type="primary" size="small" @click="editGroup(g)">{{ t('common.action.edit') }}</n-button>
|
||||
<n-button text type="error" size="small" style="margin-left: 10px" @click="removeGroup(g)">{{ t('common.action.delete') }}</n-button>
|
||||
</span>
|
||||
</div>
|
||||
</n-list-item>
|
||||
</n-list>
|
||||
</n-modal>
|
||||
<trace-code-panel />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, reactive, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NButton, NIcon, NTag, NText, type DataTableColumns } from 'naive-ui';
|
||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline } from '@vicons/ionicons5';
|
||||
import { TraceCodeStatus } from '@artveris/shared';
|
||||
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const auth = useAuthStore();
|
||||
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const checkedKeys = ref<Array<string | number>>([]);
|
||||
const query = reactive<{ artworkId: number | null; groupId: number | null; batchId: number | null; status: string | null; keyword: string; page: number; pageSize: number }>({
|
||||
artworkId: null,
|
||||
groupId: null,
|
||||
batchId: null,
|
||||
status: null,
|
||||
keyword: '',
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
|
||||
const statusOptions = Object.values(TraceCodeStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
||||
|
||||
const batches = ref<any[]>([]);
|
||||
const batchOptions = ref<{ label: string; value: number }[]>([]);
|
||||
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 })));
|
||||
const groupAssignOptions = computed(() => [
|
||||
{ label: t('pages.traceCode.noGroup'), key: '__none__' },
|
||||
...groups.value.map((g) => ({ label: g.name, key: String(g.id) })),
|
||||
]);
|
||||
|
||||
const genModal = ref(false);
|
||||
const generating = ref(false);
|
||||
const genForm = reactive<{ artworkId: number | null; quantity: number; batchNo: string; groupId: number | null }>({ artworkId: null, quantity: 100, batchNo: '', groupId: null });
|
||||
|
||||
const artworkSearching = ref(false);
|
||||
const artworkOptions = ref<{ label: string; value: number }[]>([]);
|
||||
let artworkTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
function searchArtworks(keyword: string) {
|
||||
if (artworkTimer) clearTimeout(artworkTimer);
|
||||
artworkTimer = setTimeout(async () => {
|
||||
artworkSearching.value = true;
|
||||
try {
|
||||
const res: any = await artworkApi.list({ keyword: keyword || undefined, pageSize: 20 });
|
||||
artworkOptions.value = res.list.map((a: any) => ({
|
||||
label: `${a.archiveNo || '-'} · ${a.title}`,
|
||||
value: a.id,
|
||||
}));
|
||||
} finally {
|
||||
artworkSearching.value = false;
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
const qrModal = ref(false);
|
||||
const qrSrc = ref('');
|
||||
const qrUrl = ref('');
|
||||
|
||||
const groupModal = ref(false);
|
||||
const groupForm = reactive<{ name: string }>({ name: '' });
|
||||
const editingGroup = ref<number | null>(null);
|
||||
|
||||
const columns = computed<DataTableColumns<any>>(() => [
|
||||
{ type: 'selection' },
|
||||
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 120 },
|
||||
{
|
||||
title: () => t('pages.traceCode.url'),
|
||||
key: 'url',
|
||||
ellipsis: { tooltip: true },
|
||||
render: (r) =>
|
||||
h(
|
||||
'a',
|
||||
{ href: r.url, target: '_blank', rel: 'noopener', style: 'color: var(--brand); text-decoration: none' },
|
||||
[r.url, h(NIcon, { component: OpenOutline, style: 'vertical-align:-2px;margin-left:4px' })],
|
||||
),
|
||||
},
|
||||
{ title: () => t('pages.traceCode.group'), key: 'group', width: 100, render: (r) => r.group?.name || h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noGroup') }) },
|
||||
{ title: () => t('pages.artwork.archiveNo'), key: 'archiveNo', width: 130, render: (r) => r.artwork?.archiveNo || '-' },
|
||||
{ title: () => t('pages.artwork.title'), key: 'artwork', width: 130, render: (r) => r.artwork?.title || '-' },
|
||||
{
|
||||
title: () => t('common.label.status'),
|
||||
key: 'status',
|
||||
width: 96,
|
||||
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
|
||||
},
|
||||
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 80 },
|
||||
{
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 70,
|
||||
render: (r) =>
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
||||
},
|
||||
]);
|
||||
|
||||
async function loadBatches() {
|
||||
const res: any = await traceCodeApi.batches({ pageSize: 100 });
|
||||
batches.value = res.list;
|
||||
batchOptions.value = res.list.map((b: any) => ({ label: `${b.batchNo} (${b.generatedCount}/${b.quantity})`, value: b.id }));
|
||||
}
|
||||
async function loadGroups() {
|
||||
groups.value = await traceCodeApi.groups();
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
checkedKeys.value = [];
|
||||
try {
|
||||
const res: any = await traceCodeApi.list({
|
||||
artworkId: query.artworkId || undefined,
|
||||
groupId: query.groupId || undefined,
|
||||
batchId: query.batchId || undefined,
|
||||
status: query.status || undefined,
|
||||
keyword: query.keyword || undefined,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
});
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
function onSearch() {
|
||||
query.page = 1;
|
||||
load();
|
||||
}
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
load();
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
if (!genForm.artworkId) {
|
||||
message.error(t('pages.artwork.selectArtworkTip'));
|
||||
return;
|
||||
}
|
||||
generating.value = true;
|
||||
try {
|
||||
const res: any = await traceCodeApi.generate({
|
||||
artworkId: genForm.artworkId,
|
||||
quantity: genForm.quantity,
|
||||
batchNo: genForm.batchNo || undefined,
|
||||
groupId: genForm.groupId || undefined,
|
||||
});
|
||||
message.success(t('pages.traceCode.genSuccess'));
|
||||
for (let i = 0; i < 30; i++) {
|
||||
await new Promise((r) => setTimeout(r, 700));
|
||||
const job: any = await jobApi.get(res.jobId);
|
||||
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
|
||||
}
|
||||
genModal.value = false;
|
||||
await loadBatches();
|
||||
await load();
|
||||
} finally {
|
||||
generating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function showQr(r: any) {
|
||||
qrSrc.value = traceCodeApi.qrUrl(r.id);
|
||||
qrUrl.value = r.url;
|
||||
qrModal.value = true;
|
||||
}
|
||||
const exportOptions = computed(() => {
|
||||
const cur = t('pages.traceCode.exportCurrent');
|
||||
const opts: Array<{ label: string; key: string; type?: string }> = [
|
||||
{ label: `Excel · ${cur}`, key: 'filter:xlsx' },
|
||||
{ label: `CSV · ${cur}`, key: 'filter:csv' },
|
||||
];
|
||||
if (checkedKeys.value.length) {
|
||||
const sel = t('pages.traceCode.selected', { n: checkedKeys.value.length });
|
||||
opts.push({ label: `Excel · ${sel}`, key: 'selected:xlsx' });
|
||||
opts.push({ label: `CSV · ${sel}`, key: 'selected:csv' });
|
||||
}
|
||||
return opts;
|
||||
});
|
||||
|
||||
async function onExport(key: string) {
|
||||
const [scope, format] = key.split(':');
|
||||
const params: Record<string, unknown> = { format };
|
||||
if (scope === 'selected') {
|
||||
params.ids = checkedKeys.value.map(String).join(',');
|
||||
} else {
|
||||
if (query.artworkId) params.artworkId = query.artworkId;
|
||||
if (query.groupId) params.groupId = query.groupId;
|
||||
if (query.batchId) params.batchId = query.batchId;
|
||||
if (query.status) params.status = query.status;
|
||||
if (query.keyword) params.keyword = query.keyword;
|
||||
}
|
||||
await downloadFile('/trace-codes/export', `trace-codes.${format}`, params);
|
||||
}
|
||||
|
||||
/* 批量操作 */
|
||||
async function batchAssignGroup(key: string) {
|
||||
const groupId = key === '__none__' ? null : Number(key);
|
||||
await traceCodeApi.batchGroup(checkedKeys.value.map(String), groupId);
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
await load();
|
||||
}
|
||||
async function batchStatus(disabled: boolean) {
|
||||
await traceCodeApi.batchStatus(checkedKeys.value.map(String), disabled);
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
await load();
|
||||
}
|
||||
|
||||
/* 分组管理 */
|
||||
function resetGroupForm() {
|
||||
editingGroup.value = null;
|
||||
groupForm.name = '';
|
||||
}
|
||||
function editGroup(g: any) {
|
||||
editingGroup.value = g.id;
|
||||
groupForm.name = g.name;
|
||||
}
|
||||
async function saveGroup() {
|
||||
if (editingGroup.value) {
|
||||
await traceCodeApi.updateGroup(editingGroup.value, { name: groupForm.name });
|
||||
} else {
|
||||
await traceCodeApi.createGroup({ name: groupForm.name });
|
||||
}
|
||||
message.success(t('common.msg.saved'));
|
||||
resetGroupForm();
|
||||
await loadGroups();
|
||||
}
|
||||
function removeGroup(g: any) {
|
||||
dialog.warning({
|
||||
title: t('common.action.delete'),
|
||||
content: t('common.msg.confirmDelete'),
|
||||
positiveText: t('common.action.confirm'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
await traceCodeApi.removeGroup(g.id);
|
||||
message.success(t('common.msg.deleted'));
|
||||
await loadGroups();
|
||||
await load();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 支持从作品详情跳转:?artworkId=xx 直接筛选该款的码
|
||||
const aid = Number(route.query.artworkId);
|
||||
if (aid) query.artworkId = aid;
|
||||
await Promise.all([loadBatches(), loadGroups()]);
|
||||
await load();
|
||||
});
|
||||
import TraceCodePanel from '@/components/TraceCodePanel.vue';
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mr8 {
|
||||
margin-right: 8px;
|
||||
}
|
||||
.batch-bar {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.group-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { buildPage } from '../common/utils/pagination.util';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
class QueryLogQueryDto extends PaginationDto {
|
||||
@ApiPropertyOptional({ description: '关键词(短码 / 追溯码 / SKU / 档案编号)' })
|
||||
@ApiPropertyOptional({ description: '关键词(短码 / 追溯码 / 档案编号)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
keyword?: string;
|
||||
|
||||
@@ -66,7 +66,7 @@ export class QueryTraceCodeDto extends PaginationDto {
|
||||
@IsInt()
|
||||
groupId?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: '关键词(短码/追溯码/SKU/档案号)' })
|
||||
@ApiPropertyOptional({ description: '关键词(短码/追溯码/档案号/作品名称)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
keyword?: string;
|
||||
@@ -117,6 +117,12 @@ export class BatchStatusDto {
|
||||
}
|
||||
|
||||
export class QueryBatchDto extends PaginationDto {
|
||||
@ApiPropertyOptional({ description: '作品/款式 ID' })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
artworkId?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: '关键词(批次编号)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -38,7 +38,7 @@ export class TraceCodeService {
|
||||
}
|
||||
|
||||
async generateBatch(dto: GenerateBatchDto, userId: number) {
|
||||
// 必须指定作品(款):生码即归属该款(一款多码)
|
||||
// 必须指定作品档案/款式;每条 TraceCode 对应一套实物,仍是一物一码。
|
||||
const artwork = await this.prisma.artwork.findFirst({
|
||||
where: { id: dto.artworkId, deletedAt: null },
|
||||
});
|
||||
@@ -138,6 +138,7 @@ export class TraceCodeService {
|
||||
|
||||
async listBatches(query: QueryBatchDto) {
|
||||
const where: Prisma.BatchWhereInput = {};
|
||||
if (query.artworkId) where.artworkId = query.artworkId;
|
||||
if (query.keyword) where.batchNo = { contains: query.keyword };
|
||||
const [list, total] = await this.prisma.$transaction([
|
||||
this.prisma.batch.findMany({
|
||||
|
||||
Reference in New Issue
Block a user