feat: 增强追溯码单码管理
This commit is contained in:
@@ -50,6 +50,9 @@ export const traceCodeApi = {
|
||||
post('/trace-codes/batch', data),
|
||||
batches: (params: object) => get<PageResult<any>>('/batches', params),
|
||||
list: (params: object) => get<PageResult<any>>('/trace-codes', params),
|
||||
update: (id: string, data: { groupId?: number | null; batchId?: number; disabled?: boolean }) =>
|
||||
put(`/trace-codes/${id}`, data),
|
||||
remove: (id: string) => del(`/trace-codes/${id}`),
|
||||
qrUrl: (id: string) => `/api/trace-codes/${id}/qrcode`,
|
||||
onchain: (id: string) => post(`/trace-codes/${id}/onchain`, {}),
|
||||
// 分组
|
||||
|
||||
@@ -149,8 +149,8 @@
|
||||
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 { NButton, NDropdown, NIcon, NTag, NText, type DataTableColumns, type DropdownOption } from 'naive-ui';
|
||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline, EllipsisHorizontalOutline } from '@vicons/ionicons5';
|
||||
import { TraceCodeStatus } from '@artveris/shared';
|
||||
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
@@ -163,6 +163,9 @@ const props = defineProps<{
|
||||
artworkId?: number;
|
||||
embedded?: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
(e: 'changed'): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
@@ -198,6 +201,13 @@ const groupAssignOptions = computed(() => [
|
||||
{ label: t('pages.traceCode.noGroup'), key: '__none__' },
|
||||
...groups.value.map((g) => ({ label: g.name, key: String(g.id) })),
|
||||
]);
|
||||
const rowGroupOptions = computed<DropdownOption[]>(() => [
|
||||
{ label: t('pages.traceCode.noGroup'), key: 'group:__none__' },
|
||||
...groups.value.map((g) => ({ label: g.name, key: `group:${g.id}` })),
|
||||
]);
|
||||
const rowBatchOptions = computed<DropdownOption[]>(() =>
|
||||
batchOptions.value.map((b) => ({ label: b.label, key: `batch:${b.value}` })),
|
||||
);
|
||||
|
||||
const genModal = ref(false);
|
||||
const generating = ref(false);
|
||||
@@ -248,9 +258,25 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
{
|
||||
title: () => t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 70,
|
||||
width: auth.canWrite ? 104 : 70,
|
||||
render: (r) =>
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
||||
h('div', { class: 'row-actions' }, [
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
||||
auth.canWrite
|
||||
? h(
|
||||
NDropdown,
|
||||
{ trigger: 'hover', options: rowActionOptions(r), onSelect: (key) => onRowAction(r, String(key)) },
|
||||
{
|
||||
default: () =>
|
||||
h(
|
||||
NButton,
|
||||
{ quaternary: true, circle: true, size: 'small' },
|
||||
{ icon: () => h(NIcon, null, { default: () => h(EllipsisHorizontalOutline) }) },
|
||||
),
|
||||
},
|
||||
)
|
||||
: null,
|
||||
]),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -270,7 +296,7 @@ function currentArtworkId() {
|
||||
}
|
||||
|
||||
async function loadBatches() {
|
||||
const params: Record<string, unknown> = { pageSize: 100 };
|
||||
const params: Record<string, unknown> = { pageSize: 0 };
|
||||
const aid = currentArtworkId();
|
||||
if (aid) params.artworkId = aid;
|
||||
const res: any = await traceCodeApi.batches(params);
|
||||
@@ -351,6 +377,7 @@ async function generate() {
|
||||
genForm.batchNo = '';
|
||||
await loadBatches();
|
||||
await load();
|
||||
emit('changed');
|
||||
} finally {
|
||||
generating.value = false;
|
||||
}
|
||||
@@ -397,12 +424,71 @@ async function batchAssignGroup(key: string) {
|
||||
await traceCodeApi.batchGroup(checkedKeys.value.map(String), groupId);
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
await load();
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
async function batchStatus(disabled: boolean) {
|
||||
await traceCodeApi.batchStatus(checkedKeys.value.map(String), disabled);
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
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 },
|
||||
{ type: 'divider', key: 'divider-1' },
|
||||
{
|
||||
label: row.status === TraceCodeStatus.DISABLED ? t('pages.traceCode.enableOne') : t('pages.traceCode.disableOne'),
|
||||
key: row.status === TraceCodeStatus.DISABLED ? 'status:enable' : 'status:disable',
|
||||
},
|
||||
{ label: t('common.action.delete'), key: 'delete' },
|
||||
];
|
||||
}
|
||||
|
||||
async function onRowAction(row: any, key: string) {
|
||||
if (key.startsWith('group:')) {
|
||||
const groupKey = key.slice('group:'.length);
|
||||
await traceCodeApi.update(String(row.id), { groupId: groupKey === '__none__' ? null : Number(groupKey) });
|
||||
message.success(t('common.msg.saved'));
|
||||
await load();
|
||||
emit('changed');
|
||||
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();
|
||||
await load();
|
||||
emit('changed');
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'status:disable' || key === 'status:enable') {
|
||||
await traceCodeApi.update(String(row.id), { disabled: key === 'status:disable' });
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
await load();
|
||||
emit('changed');
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'delete') {
|
||||
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.remove(String(row.id));
|
||||
message.success(t('common.msg.deleted'));
|
||||
await loadBatches();
|
||||
await load();
|
||||
emit('changed');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function resetGroupForm() {
|
||||
@@ -437,6 +523,7 @@ function removeGroup(g: any) {
|
||||
message.success(t('common.msg.deleted'));
|
||||
await loadGroups();
|
||||
await load();
|
||||
emit('changed');
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -505,6 +592,11 @@ onMounted(async () => {
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
}
|
||||
.row-actions {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.mr8 {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
"artist": "Artist",
|
||||
"template": "Template",
|
||||
"archiveNo": "Archive No.",
|
||||
"batchCount": "Batches",
|
||||
"codeCount": "Codes",
|
||||
"activeCount": "Activated",
|
||||
"queryTotal": "Total Queries",
|
||||
@@ -261,6 +262,10 @@
|
||||
"batchGroup": "Set Group",
|
||||
"batchEnable": "Enable",
|
||||
"batchDisable": "Disable",
|
||||
"changeGroup": "Change Group",
|
||||
"changeBatch": "Change Batch",
|
||||
"enableOne": "Enable",
|
||||
"disableOne": "Disable",
|
||||
"selected": "{n} selected",
|
||||
"assignGroup": "Assign group"
|
||||
},
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
"artist": "艺术家",
|
||||
"template": "所属模板",
|
||||
"archiveNo": "档案编号",
|
||||
"batchCount": "批次数量",
|
||||
"codeCount": "追溯码数",
|
||||
"activeCount": "已激活",
|
||||
"queryTotal": "查询总数",
|
||||
@@ -261,6 +262,10 @@
|
||||
"batchGroup": "批量分组",
|
||||
"batchEnable": "批量启用",
|
||||
"batchDisable": "批量停用",
|
||||
"changeGroup": "修改分组",
|
||||
"changeBatch": "修改批次",
|
||||
"enableOne": "启用",
|
||||
"disableOne": "禁用",
|
||||
"selected": "已选 {n} 项",
|
||||
"assignGroup": "设为分组"
|
||||
},
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
</n-tag>
|
||||
</div>
|
||||
</template>
|
||||
<n-descriptions :column="4" label-placement="top" bordered size="small">
|
||||
<n-descriptions :column="5" 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.batchCount')">{{ artwork?.codeStats?.batchTotal ?? artwork?.batches?.length ?? 0 }}</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>
|
||||
@@ -27,7 +28,7 @@
|
||||
|
||||
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false" class="table-card">
|
||||
<div class="trace-table-wrap">
|
||||
<trace-code-panel :artwork-id="artworkId" />
|
||||
<trace-code-panel :artwork-id="artworkId" @changed="loadArtwork" />
|
||||
</div>
|
||||
</n-card>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user