feat: 后台语言包合并默认中文、日夜主题切换、官方侧栏收缩、追溯码分组与批量

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 18:37:57 +08:00
co-authored by Cursor
parent 6578007c9e
commit b5170fe84b
21 changed files with 873 additions and 666 deletions
+2 -3
View File
@@ -123,12 +123,11 @@ onMounted(async () => {
.stat-value {
font-size: 28px;
font-weight: 700;
color: #1f2937;
line-height: 1.2;
}
.stat-label {
font-size: 13px;
color: #6b7280;
opacity: 0.6;
}
.mt16 {
margin-top: 16px;
@@ -147,6 +146,6 @@ onMounted(async () => {
}
.top-count {
font-weight: 600;
color: #2e5496;
color: var(--brand);
}
</style>
+4 -19
View File
@@ -1,13 +1,7 @@
<template>
<div class="login-wrap">
<div class="login-lang">
<n-select
v-model:value="currentLocale"
:options="localeOptions"
size="small"
style="width: 120px"
@update:value="changeLocale"
/>
<lang-switch />
</div>
<div class="login-left">
<div class="login-left-inner">
@@ -56,29 +50,22 @@ import { useI18n } from 'vue-i18n';
import type { FormInst, FormRules } from 'naive-ui';
import { PersonOutline, LockClosedOutline } from '@vicons/ionicons5';
import { useAuthStore } from '@/stores/auth';
import { SUPPORTED_LOCALES, setLocale } from '@/locales';
import { message } from '@/utils/feedback';
import LangSwitch from '@/components/LangSwitch.vue';
const { t, locale } = useI18n();
const { t } = useI18n();
const router = useRouter();
const auth = useAuthStore();
const formRef = ref<FormInst | null>(null);
const form = ref({ username: '', password: '' });
const loading = ref(false);
const currentLocale = ref(locale.value);
const localeOptions = SUPPORTED_LOCALES.map((l) => ({ label: l.label, value: l.value }));
const rules: FormRules = {
username: { required: true, message: () => t('pages.login.placeholderUser'), trigger: 'blur' },
password: { required: true, message: () => t('pages.login.placeholderPass'), trigger: 'blur' },
};
function changeLocale(val: string) {
setLocale(val);
currentLocale.value = val;
}
async function onSubmit() {
try {
await formRef.value?.validate();
@@ -103,7 +90,6 @@ async function onSubmit() {
position: relative;
display: flex;
height: 100vh;
background: #f0f2f5;
}
.login-lang {
position: absolute;
@@ -113,7 +99,7 @@ async function onSubmit() {
}
.login-left {
flex: 1 1 55%;
background: linear-gradient(135deg, #1f3864 0%, #2e5496 100%);
background: linear-gradient(135deg, var(--brand-from) 0%, var(--brand-to) 100%);
color: #fff;
display: flex;
align-items: center;
@@ -158,7 +144,6 @@ async function onSubmit() {
.login-card-title {
margin: 0 0 24px;
font-size: 22px;
color: #1f2937;
text-align: center;
}
@media (max-width: 768px) {
+167 -34
View File
@@ -1,12 +1,20 @@
<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: 200px"
style="width: 190px"
@update:value="onSearch"
/>
<n-select
@@ -14,14 +22,14 @@
:options="statusOptions"
clearable
:placeholder="t('common.label.status')"
style="width: 140px"
style="width: 130px"
@update:value="onSearch"
/>
<n-input
v-model:value="query.keyword"
:placeholder="t('pages.traceCode.shortCode')"
clearable
style="width: 180px"
style="width: 160px"
@keyup.enter="onSearch"
/>
<n-button type="primary" @click="onSearch">
@@ -29,6 +37,10 @@
{{ 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-button v-if="auth.canWrite && query.batchId" @click="exportBatch">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('pages.traceCode.exportBatch') }}
@@ -39,6 +51,21 @@
</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"
@@ -46,14 +73,19 @@
: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: 420px">
<!-- 生成 -->
<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.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>
@@ -67,24 +99,47 @@
</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; color: #6b7280; word-break: break-all">{{ qrUrl }}</div>
<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>
</div>
</template>
<script setup lang="ts">
import { h, onMounted, reactive, ref } from 'vue';
import { computed, h, onMounted, reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { NButton, NIcon, NTag, NText, type DataTableColumns } from 'naive-ui';
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline } from '@vicons/ionicons5';
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline } from '@vicons/ionicons5';
import { TraceCodeStatus } from '@artveris/shared';
import { traceCodeApi, jobApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { message } from '@/utils/feedback';
import { message, dialog } from '@/utils/feedback';
import { fmt, statusType } from '@/utils/format';
import { downloadFile } from '@/utils/download';
@@ -93,7 +148,9 @@ const auth = useAuthStore();
const rows = ref<any[]>([]);
const loading = ref(false);
const query = reactive<{ batchId: number | null; status: string | null; keyword: string; page: number; pageSize: number }>({
const checkedKeys = ref<Array<string | number>>([]);
const query = reactive<{ groupId: number | null; batchId: number | null; status: string | null; keyword: string; page: number; pageSize: number }>({
groupId: null,
batchId: null,
status: null,
keyword: '',
@@ -102,57 +159,76 @@ const query = reactive<{ batchId: number | null; status: string | null; keyword:
});
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<{ quantity: number; batchNo: string }>({ quantity: 100, batchNo: '' });
const genForm = reactive<{ quantity: number; batchNo: string; groupId: number | null }>({ quantity: 100, batchNo: '', groupId: null });
const qrModal = ref(false);
const qrSrc = ref('');
const qrUrl = ref('');
const columns: DataTableColumns<any> = [
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 130 },
{ title: () => t('pages.traceCode.url'), key: 'url', ellipsis: { tooltip: true } },
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.artwork.title'),
key: 'artwork',
width: 150,
render: (r) => r.artwork?.title || '-',
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('pages.artwork.title'), key: 'artwork', width: 140, render: (r) => r.artwork?.title || '-' },
{
title: () => t('common.label.status'),
key: 'status',
width: 100,
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: 90 },
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 160, render: (r) => fmt(r.firstActivatedAt) },
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 80 },
{
title: () => t('common.label.operation'),
key: 'ops',
width: 80,
width: 70,
render: (r) =>
h(
NButton,
{ quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) },
{ icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) },
),
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({
groupId: query.groupId || undefined,
batchId: query.batchId || undefined,
status: query.status || undefined,
keyword: query.keyword || undefined,
@@ -178,14 +254,16 @@ function onPage(p: number) {
async function generate() {
generating.value = true;
try {
const res: any = await traceCodeApi.generate({ quantity: genForm.quantity, batchNo: genForm.batchNo || undefined });
const res: any = await traceCodeApi.generate({
quantity: genForm.quantity,
batchNo: genForm.batchNo || undefined,
groupId: genForm.groupId || undefined,
});
message.success(t('pages.traceCode.genSuccess'));
// 轮询任务
const jobId = res.jobId;
for (let i = 0; i < 30; i++) {
await new Promise((r) => setTimeout(r, 700));
const job: any = await jobApi.get(jobId);
if (job.status === 'SUCCESS' || job.status === 'FAILED' || job.status === 'PARTIAL') break;
const job: any = await jobApi.get(res.jobId);
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
}
genModal.value = false;
await loadBatches();
@@ -200,14 +278,60 @@ function showQr(r: any) {
qrUrl.value = r.url;
qrModal.value = true;
}
async function exportBatch() {
if (!query.batchId) return;
await downloadFile('/trace-codes/export', `trace-codes-${query.batchId}.xlsx`, { batchId: query.batchId });
}
/* 批量操作 */
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 () => {
await loadBatches();
await Promise.all([loadBatches(), loadGroups()]);
await load();
});
</script>
@@ -216,4 +340,13 @@ onMounted(async () => {
.mr8 {
margin-right: 8px;
}
.batch-bar {
margin-bottom: 12px;
}
.group-row {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
</style>