fix: 优化追溯码管理入口和筛选
This commit is contained in:
@@ -65,7 +65,7 @@ export const traceCodeApi = {
|
||||
qrBlob: (id: string) => download(`/trace-codes/${id}/qrcode`),
|
||||
onchain: (id: string) => post(`/trace-codes/${id}/onchain`, {}),
|
||||
// 分组
|
||||
groups: () => get<any[]>('/trace-code-groups'),
|
||||
groups: (params?: object) => get<any[]>('/trace-code-groups', params),
|
||||
createGroup: (data: { name: string; remark?: string }) => post('/trace-code-groups', data),
|
||||
updateGroup: (id: number, data: { name: string; remark?: string }) =>
|
||||
put(`/trace-code-groups/${id}`, data),
|
||||
|
||||
@@ -74,13 +74,14 @@
|
||||
:options="artworkOptions"
|
||||
:placeholder="t('pages.artwork.selectArtworkTip')"
|
||||
@search="searchArtworks"
|
||||
@focus="loadArtworkOptions('')"
|
||||
/>
|
||||
</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-select v-model:value="genForm.groupId" :options="generateGroupOptions" 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)" />
|
||||
@@ -249,8 +250,9 @@ const outboundStatusOptions = computed(() => [
|
||||
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 generateGroups = 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 generateGroupOptions = computed(() => generateGroups.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) })),
|
||||
@@ -466,6 +468,10 @@ async function loadGroups() {
|
||||
groups.value = await traceCodeApi.groups();
|
||||
}
|
||||
|
||||
async function loadGenerateGroups(artworkId: number | null) {
|
||||
generateGroups.value = artworkId ? await traceCodeApi.groups({ artworkId }) : [];
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
checkedKeys.value = [];
|
||||
@@ -493,25 +499,28 @@ function onSearch() {
|
||||
load();
|
||||
}
|
||||
|
||||
function openGenerate() {
|
||||
async function openGenerate() {
|
||||
genForm.artworkId = fixedArtworkId.value || query.artworkId;
|
||||
await Promise.all([loadArtworkOptions(''), loadGenerateGroups(genForm.artworkId)]);
|
||||
genModal.value = true;
|
||||
}
|
||||
|
||||
async function loadArtworkOptions(keyword: string) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
artworkTimer = setTimeout(() => loadArtworkOptions(keyword), 300);
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
@@ -810,12 +819,23 @@ watch(
|
||||
query.artworkId = aid;
|
||||
genForm.artworkId = aid;
|
||||
query.batchId = null;
|
||||
genForm.groupId = null;
|
||||
await loadGenerateGroups(aid);
|
||||
resetPage();
|
||||
await loadBatches();
|
||||
await load();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => genForm.artworkId,
|
||||
async (aid, oldAid) => {
|
||||
if (aid === oldAid) return;
|
||||
genForm.groupId = null;
|
||||
await loadGenerateGroups(aid);
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
if (!fixedArtworkId.value) {
|
||||
const aid = Number(route.query.artworkId);
|
||||
@@ -850,7 +870,7 @@ onUnmounted(() => {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.toolbar-control {
|
||||
width: 170px;
|
||||
width: 320px;
|
||||
}
|
||||
.toolbar-control.wide {
|
||||
width: 210px;
|
||||
|
||||
@@ -64,6 +64,7 @@ import {
|
||||
GridOutline,
|
||||
DocumentTextOutline,
|
||||
ImagesOutline,
|
||||
QrCodeOutline,
|
||||
CubeOutline,
|
||||
ListOutline,
|
||||
PeopleOutline,
|
||||
@@ -99,6 +100,7 @@ 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) },
|
||||
@@ -111,7 +113,7 @@ const menuOptions = computed<MenuOption[]>(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const activeKey = computed(() => (['artwork-detail', 'artwork-trace-codes', 'traceCodes'].includes(route.name as string) ? 'artworks' : (route.name as string)));
|
||||
const activeKey = computed(() => (['artwork-detail', 'artwork-trace-codes'].includes(route.name as string) ? 'artworks' : (route.name as string)));
|
||||
const currentTitle = computed(() => {
|
||||
if (route.name === 'traceCodes' || route.name === 'artwork-trace-codes') return t('pages.artwork.traceCodeManage');
|
||||
return activeKey.value ? t(`menu.${activeKey.value}`) : '';
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
"dashboard": "Dashboard",
|
||||
"templates": "Templates",
|
||||
"artworks": "Artwork Files",
|
||||
"traceCodes": "Trace Code Details",
|
||||
"traceCodes": "Trace Code Management",
|
||||
"outbound": "Outbound & Chain",
|
||||
"audit": "Content Audit",
|
||||
"queryLogs": "Query Logs",
|
||||
@@ -307,7 +307,7 @@
|
||||
"shortCode": "Trace Code",
|
||||
"code": "Trace Code",
|
||||
"url": "Link",
|
||||
"keywordPlaceholder": "Trace code / link / archive no. / name",
|
||||
"keywordPlaceholder": "Trace code / link / archive no. / name / artist / batch / group / note",
|
||||
"queryCount": "Queries",
|
||||
"firstActivatedAt": "First Activated",
|
||||
"exportBatch": "Export Batch",
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
"dashboard": "数据看板",
|
||||
"templates": "溯源模板",
|
||||
"artworks": "艺术品档案",
|
||||
"traceCodes": "追溯码明细",
|
||||
"traceCodes": "追溯码管理",
|
||||
"outbound": "出库与上链",
|
||||
"audit": "内容审核",
|
||||
"queryLogs": "查询日志",
|
||||
@@ -307,7 +307,7 @@
|
||||
"shortCode": "追溯码",
|
||||
"code": "追溯码",
|
||||
"url": "链接",
|
||||
"keywordPlaceholder": "追溯码 / 链接 / 档案编号 / 名称",
|
||||
"keywordPlaceholder": "追溯码 / 链接 / 档案编号 / 名称 / 艺术家 / 批次 / 分组 / 备注",
|
||||
"queryCount": "查询次数",
|
||||
"firstActivatedAt": "首次激活时间",
|
||||
"exportBatch": "导出本批",
|
||||
|
||||
@@ -94,7 +94,7 @@ const columns: DataTableColumns<any> = [
|
||||
render: (r) =>
|
||||
h(
|
||||
NButton,
|
||||
{ text: true, type: 'primary', title: t('pages.artwork.traceCodeManage'), onClick: () => router.push(`/artworks/${r.id}/trace-codes`) },
|
||||
{ text: true, type: 'primary', title: t('pages.artwork.editDetail'), onClick: () => router.push(`/artworks/${r.id}`) },
|
||||
{ default: () => r.archiveNo || '-' },
|
||||
),
|
||||
},
|
||||
|
||||
@@ -50,8 +50,9 @@ export class TraceCodeController {
|
||||
|
||||
@Get('trace-code-groups')
|
||||
@ApiOperation({ summary: '分组列表' })
|
||||
groups() {
|
||||
return this.service.listGroups();
|
||||
groups(@Query('artworkId') artworkId?: string) {
|
||||
const id = artworkId ? Number(artworkId) : undefined;
|
||||
return this.service.listGroups(id && Number.isFinite(id) ? id : undefined);
|
||||
}
|
||||
|
||||
@Post('trace-code-groups')
|
||||
|
||||
@@ -65,6 +65,8 @@ export class TraceCodeService {
|
||||
});
|
||||
if (!artwork) throw new BusinessException(ErrorCode.ARTWORK_NOT_FOUND, '鑹烘湳鍝佷笉瀛樺湪', 404);
|
||||
|
||||
if (dto.groupId !== undefined && dto.groupId !== null) await this.ensureGroup(dto.groupId);
|
||||
|
||||
const batchNo = dto.batchNo || `B${dayjs().format('YYYYMMDDHHmmss')}`;
|
||||
const exists = await this.prisma.batch.findUnique({ where: { batchNo } });
|
||||
if (exists) {
|
||||
@@ -89,8 +91,9 @@ export class TraceCodeService {
|
||||
}
|
||||
|
||||
// ===== 鍒嗙粍绠$悊 =====
|
||||
listGroups() {
|
||||
listGroups(artworkId?: number) {
|
||||
return this.prisma.traceCodeGroup.findMany({
|
||||
where: artworkId ? { traceCodes: { some: { artworkId } } } : undefined,
|
||||
orderBy: { id: 'desc' },
|
||||
include: { _count: { select: { traceCodes: true } } },
|
||||
});
|
||||
@@ -394,8 +397,13 @@ export class TraceCodeService {
|
||||
OR: [
|
||||
{ shortCode: { contains: query.keyword } },
|
||||
{ code: { contains: query.keyword } },
|
||||
{ url: { contains: query.keyword } },
|
||||
{ remark: { contains: query.keyword } },
|
||||
{ artwork: { archiveNo: { contains: query.keyword } } },
|
||||
{ artwork: { title: { contains: query.keyword } } },
|
||||
{ artwork: { artist: { contains: query.keyword } } },
|
||||
{ batch: { batchNo: { contains: query.keyword } } },
|
||||
{ group: { name: { contains: query.keyword } } },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user