feat: 实现后台管理前端全部页面与登录布局

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 16:52:41 +08:00
co-authored by Cursor
parent fa61840cfb
commit 5fa84f346b
40 changed files with 4481 additions and 1 deletions
+511
View File
@@ -0,0 +1,511 @@
<template>
<div class="page">
<div class="page-toolbar">
<n-button quaternary @click="router.back()">
<template #icon><n-icon :component="ArrowBackOutline" /></template>
{{ t('common.action.back') }}
</n-button>
<div class="page-title">{{ isNew ? t('pages.artwork.create') : t('pages.artwork.detail') }}</div>
</div>
<n-grid :cols="1" :y-gap="16">
<!-- 基础信息 -->
<n-grid-item>
<n-card :title="t('pages.artwork.basicInfo')" :bordered="false">
<n-form ref="formRef" :model="form" :rules="rules" label-placement="top">
<n-grid :cols="2" :x-gap="16" item-responsive responsive="screen">
<n-form-item-gi span="2 m:1" path="templateId" :label="t('pages.artwork.template')">
<n-select
v-model:value="form.templateId"
:options="templateOptions"
:disabled="!isNew"
@update:value="onTemplateChange"
/>
</n-form-item-gi>
<n-form-item-gi span="2 m:1" path="title" :label="t('pages.artwork.title')">
<n-input v-model:value="form.title" />
</n-form-item-gi>
<n-form-item-gi span="2 m:1" :label="t('pages.artwork.artist')">
<n-input v-model:value="form.artist" />
</n-form-item-gi>
<n-form-item-gi v-if="!isNew" span="2 m:1" :label="t('common.label.status')">
<n-select v-model:value="form.status" :options="statusOptions" />
</n-form-item-gi>
</n-grid>
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.dynamicFields') }}</n-divider>
<n-grid :cols="2" :x-gap="16" item-responsive responsive="screen">
<n-form-item-gi v-for="f in currentFields" :key="f.fieldKey" span="2 m:1" :label="f.label">
<n-date-picker
v-if="f.type === 'DATE'"
v-model:formatted-value="form.dynamicFields[f.fieldKey]"
value-format="yyyy-MM-dd"
type="date"
style="width: 100%"
/>
<n-input
v-else-if="f.type === 'TEXTAREA'"
v-model:value="form.dynamicFields[f.fieldKey]"
type="textarea"
:rows="2"
/>
<n-input v-else v-model:value="form.dynamicFields[f.fieldKey]" />
</n-form-item-gi>
</n-grid>
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.images') }}</n-divider>
<media-upload v-model="form.images" type="image" :max="8" />
</n-form>
<div style="text-align: right; margin-top: 16px">
<n-button type="primary" :loading="saving" :disabled="!auth.canWrite" @click="saveBasic">
{{ t('common.action.save') }}
</n-button>
</div>
</n-card>
</n-grid-item>
<template v-if="!isNew">
<!-- 溯源时间轴 -->
<n-grid-item>
<n-card :title="t('pages.artwork.nodes')" :bordered="false">
<template #header-extra>
<n-button v-if="auth.canWrite" size="small" type="primary" @click="openNode()">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.addNode') }}
</n-button>
</template>
<n-empty v-if="!nodes.length" :description="t('common.msg.noData')" />
<n-timeline v-else>
<n-timeline-item v-for="n in nodes" :key="n.id" type="info" :title="n.title">
<template #header>
<div class="node-head">
<span>{{ t(`common.nodeType.${n.nodeType}`) }} · {{ n.title }}</span>
<span v-if="auth.canWrite" class="node-ops">
<n-button text size="tiny" @click="openNode(n)">{{ t('common.action.edit') }}</n-button>
<n-button text size="tiny" type="error" @click="removeNode(n)">{{ t('common.action.delete') }}</n-button>
</span>
</div>
</template>
<div class="node-meta">{{ [fmtDate(n.occurredAt), n.location].filter(Boolean).join(' · ') }}</div>
<div>{{ n.description }}</div>
<div class="node-media">
<n-image v-for="m in n.media" :key="m.url" :src="m.url" width="64" height="64" object-fit="cover" style="border-radius:6px" />
</div>
</n-timeline-item>
</n-timeline>
</n-card>
</n-grid-item>
<!-- 认证文件 -->
<n-grid-item>
<n-card :title="t('pages.artwork.certificates')" :bordered="false">
<template #header-extra>
<n-button v-if="auth.canWrite" size="small" type="primary" @click="openCert()">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.addCert') }}
</n-button>
</template>
<n-empty v-if="!certs.length" :description="t('common.msg.noData')" />
<n-grid v-else :cols="4" :x-gap="12" :y-gap="12" item-responsive responsive="screen">
<n-grid-item v-for="c in certs" :key="c.id" span="2 m:1">
<n-card size="small" :title="c.name">
<template #cover>
<n-image v-if="c.watermarkUrl" :src="c.watermarkUrl" object-fit="cover" style="height:140px;width:100%" />
<div v-else class="cert-pending">{{ t('pages.artwork.watermarkPending') }}</div>
</template>
<div class="cert-meta">{{ c.issuer || '-' }}</div>
<template #footer>
<n-button v-if="auth.canWrite" text size="tiny" type="error" @click="removeCert(c)">
{{ t('common.action.delete') }}
</n-button>
</template>
</n-card>
</n-grid-item>
</n-grid>
</n-card>
</n-grid-item>
<!-- 追溯码与区块链 -->
<n-grid-item>
<n-card :title="t('pages.artwork.traceCode') + ' / ' + t('pages.blockchain.title')" :bordered="false">
<div v-if="artwork?.traceCode">
<n-descriptions :column="3" label-placement="left" bordered size="small">
<n-descriptions-item :label="t('pages.traceCode.shortCode')">{{ artwork.traceCode.shortCode }}</n-descriptions-item>
<n-descriptions-item :label="t('common.label.status')">
<n-tag size="small" :type="statusType(artwork.traceCode.status)">{{ t(`common.status.${artwork.traceCode.status}`) }}</n-tag>
</n-descriptions-item>
<n-descriptions-item :label="t('pages.traceCode.queryCount')">{{ artwork.traceCode.queryCount }}</n-descriptions-item>
</n-descriptions>
<div style="margin-top:12px; display:flex; gap:8px; flex-wrap:wrap">
<n-button v-if="auth.canWrite" size="small" @click="unbind">{{ t('common.action.unbind') }}</n-button>
<n-button v-if="auth.canWrite" size="small" type="primary" :loading="onchainLoading" @click="onchain">
<template #icon><n-icon :component="LinkOutline" /></template>
{{ t('common.action.onchain') }}
</n-button>
</div>
<n-data-table
v-if="artwork.traceCode.proofs?.length"
style="margin-top:12px"
size="small"
:columns="proofColumns"
:data="artwork.traceCode.proofs"
:row-key="(r) => r.id"
/>
</div>
<div v-else>
<n-empty :description="t('pages.artwork.noTrace')" />
<div v-if="auth.canWrite" style="margin-top:12px; display:flex; gap:8px; align-items:center">
<n-select
v-model:value="bindCodeId"
:options="unboundOptions"
filterable
:placeholder="t('pages.traceCode.shortCode')"
style="width: 240px"
@focus="loadUnbound"
/>
<n-button type="primary" :disabled="!bindCodeId" @click="bind">{{ t('pages.artwork.bindCode') }}</n-button>
</div>
</div>
</n-card>
</n-grid-item>
</template>
</n-grid>
<!-- 节点弹窗 -->
<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">
<n-grid :cols="2" :x-gap="12">
<n-form-item-gi :label="t('common.label.type')">
<n-select v-model:value="nodeForm.nodeType" :options="nodeTypeOptions" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.artwork.nodeTitle')">
<n-input v-model:value="nodeForm.title" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.artwork.nodeTime')">
<n-date-picker v-model:formatted-value="nodeForm.occurredAt" value-format="yyyy-MM-dd" type="date" style="width:100%" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.artwork.nodeLocation')">
<n-input v-model:value="nodeForm.location" />
</n-form-item-gi>
</n-grid>
<n-form-item :label="t('pages.artwork.nodeDesc')">
<n-input v-model:value="nodeForm.description" type="textarea" :rows="2" />
</n-form-item>
<n-form-item :label="t('pages.artwork.images')">
<media-upload v-model="nodeForm.mediaFiles" type="image" :max="6" />
</n-form-item>
</n-form>
<template #footer>
<div style="text-align:right">
<n-button class="mr8" @click="nodeModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" :loading="nodeSaving" @click="saveNode">{{ t('common.action.save') }}</n-button>
</div>
</template>
</n-modal>
<!-- 证书弹窗 -->
<n-modal v-model:show="certModal" preset="card" :title="t('pages.artwork.addCert')" style="width:480px;max-width:94vw">
<n-form :model="certForm" label-placement="top">
<n-form-item :label="t('pages.artwork.certName')">
<n-input v-model:value="certForm.name" />
</n-form-item>
<n-form-item :label="t('pages.artwork.certIssuer')">
<n-input v-model:value="certForm.issuer" />
</n-form-item>
<n-form-item :label="t('pages.artwork.certType')">
<n-select v-model:value="certForm.type" :options="certTypeOptions" />
</n-form-item>
<n-form-item :label="t('pages.artwork.originFile')">
<media-upload v-model="certForm.files" type="image" :max="1" />
</n-form-item>
</n-form>
<template #footer>
<div style="text-align:right">
<n-button class="mr8" @click="certModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" :loading="certSaving" @click="saveCert">{{ t('common.action.save') }}</n-button>
</div>
</template>
</n-modal>
</div>
</template>
<script setup lang="ts">
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 { ArrowBackOutline, AddOutline, LinkOutline } from '@vicons/ionicons5';
import { ArtworkStatus, CertType, NodeType } from '@artveris/shared';
import { artworkApi, templateApi, traceCodeApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import MediaUpload from '@/components/MediaUpload.vue';
import { message, dialog } from '@/utils/feedback';
import { fmt, fmtDate, statusType } from '@/utils/format';
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const auth = useAuthStore();
const isNew = computed(() => route.params.id === 'new');
const artworkId = computed(() => Number(route.params.id));
const formRef = ref<FormInst | null>(null);
const form = reactive<any>({ templateId: null, title: '', artist: '', status: ArtworkStatus.DRAFT, dynamicFields: {}, images: [] });
const rules: FormRules = {
templateId: { required: true, type: 'number', message: () => t('pages.artwork.template'), trigger: 'change' },
title: { required: true, message: () => t('pages.artwork.title'), trigger: 'blur' },
};
const saving = ref(false);
const templates = ref<any[]>([]);
const templateOptions = computed(() => templates.value.map((x) => ({ label: x.name, value: x.id })));
const statusOptions = Object.values(ArtworkStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
const nodeTypeOptions = Object.values(NodeType).map((v) => ({ label: t(`common.nodeType.${v}`), value: v }));
const certTypeOptions = Object.values(CertType).map((v) => ({ label: v, value: v }));
const currentFields = computed(() => templates.value.find((x) => x.id === form.templateId)?.fields ?? []);
const artwork = ref<any>(null);
const nodes = ref<any[]>([]);
const certs = ref<any[]>([]);
const proofColumns: DataTableColumns<any> = [
{ title: () => t('pages.blockchain.txHash'), key: 'txHash', ellipsis: { tooltip: true }, render: (r) => r.txHash || '-' },
{ title: () => t('pages.blockchain.blockHeight'), key: 'blockHeight', width: 120, render: (r) => r.blockHeight || '-' },
{
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('pages.blockchain.onchainAt'), key: 'onchainAt', width: 160, render: (r) => fmt(r.onchainAt) },
];
function onTemplateChange() {
form.dynamicFields = {};
}
async function loadTemplates() {
templates.value = await templateApi.options();
}
async function loadArtwork() {
const a: any = await artworkApi.get(artworkId.value);
artwork.value = a;
form.templateId = a.templateId;
form.title = a.title;
form.artist = a.artist;
form.status = a.status;
form.dynamicFields = a.dynamicFields || {};
form.images = a.images || [];
nodes.value = a.traceNodes || [];
certs.value = a.certificates || [];
}
async function saveBasic() {
try {
await formRef.value?.validate();
} catch {
return;
}
saving.value = true;
try {
const payload = {
templateId: form.templateId,
title: form.title,
artist: form.artist,
status: form.status,
dynamicFields: form.dynamicFields,
images: form.images.map((m: any) => ({ key: m.key, name: m.name })),
};
if (isNew.value) {
const created: any = await artworkApi.create(payload);
message.success(t('common.msg.created'));
router.replace(`/artworks/${created.id}`);
} else {
await artworkApi.update(artworkId.value, payload);
message.success(t('common.msg.saved'));
await loadArtwork();
}
} finally {
saving.value = false;
}
}
/* 节点 */
const nodeModal = ref(false);
const nodeSaving = ref(false);
const editingNode = ref<number | null>(null);
const nodeForm = reactive<any>({ nodeType: NodeType.CREATE, title: '', occurredAt: null, location: '', description: '', mediaFiles: [] });
function openNode(n?: any) {
editingNode.value = n?.id ?? null;
Object.assign(nodeForm, {
nodeType: n?.nodeType ?? NodeType.CREATE,
title: n?.title ?? '',
occurredAt: n?.occurredAt ? fmtDate(n.occurredAt) : null,
location: n?.location ?? '',
description: n?.description ?? '',
mediaFiles: n?.media ? n.media.map((m: any) => ({ key: m.key || m.url, url: m.url, name: m.name })) : [],
});
nodeModal.value = true;
}
async function saveNode() {
if (!nodeForm.title) {
message.error(t('pages.artwork.nodeTitle'));
return;
}
nodeSaving.value = true;
try {
const payload = {
nodeType: nodeForm.nodeType,
title: nodeForm.title,
occurredAt: nodeForm.occurredAt || undefined,
location: nodeForm.location,
description: nodeForm.description,
mediaFiles: nodeForm.mediaFiles.map((m: any) => ({ key: m.key, name: m.name, type: 'image' })),
};
if (editingNode.value) await artworkApi.updateNode(editingNode.value, payload);
else await artworkApi.createNode(artworkId.value, payload);
message.success(t('common.msg.saved'));
nodeModal.value = false;
nodes.value = await artworkApi.listNodes(artworkId.value);
} finally {
nodeSaving.value = false;
}
}
function removeNode(n: 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 artworkApi.removeNode(n.id);
nodes.value = await artworkApi.listNodes(artworkId.value);
},
});
}
/* 证书 */
const certModal = ref(false);
const certSaving = ref(false);
const certForm = reactive<any>({ name: '', issuer: '', type: CertType.CERT, files: [] });
function openCert() {
Object.assign(certForm, { name: '', issuer: '', type: CertType.CERT, files: [] });
certModal.value = true;
}
async function saveCert() {
if (!certForm.name || !certForm.files.length) {
message.error(t('pages.artwork.certName'));
return;
}
certSaving.value = true;
try {
await artworkApi.createCert(artworkId.value, {
name: certForm.name,
issuer: certForm.issuer,
type: certForm.type,
originKey: certForm.files[0].key,
});
message.success(t('common.msg.created'));
certModal.value = false;
certs.value = await artworkApi.listCerts(artworkId.value);
} finally {
certSaving.value = false;
}
}
function removeCert(c: 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 artworkApi.removeCert(c.id);
certs.value = await artworkApi.listCerts(artworkId.value);
},
});
}
/* 追溯码 / 区块链 */
const bindCodeId = ref<string | null>(null);
const unbound = ref<any[]>([]);
const unboundOptions = computed(() => unbound.value.map((c) => ({ label: c.shortCode, value: c.id })));
const onchainLoading = ref(false);
async function loadUnbound() {
const res: any = await traceCodeApi.list({ status: 'UNBOUND', pageSize: 50 });
unbound.value = res.list;
}
async function bind() {
if (!bindCodeId.value) return;
await traceCodeApi.bind(bindCodeId.value, artworkId.value);
message.success(t('common.msg.saved'));
bindCodeId.value = null;
await loadArtwork();
}
async function unbind() {
if (!artwork.value?.traceCode) return;
await traceCodeApi.unbind(String(artwork.value.traceCode.id));
message.success(t('common.msg.saved'));
await loadArtwork();
}
async function onchain() {
if (!artwork.value?.traceCode) return;
onchainLoading.value = true;
try {
await traceCodeApi.onchain(String(artwork.value.traceCode.id));
message.success(t('pages.blockchain.triggered'));
setTimeout(loadArtwork, 1500);
} finally {
onchainLoading.value = false;
}
}
onMounted(async () => {
await loadTemplates();
if (!isNew.value) await loadArtwork();
});
</script>
<style scoped>
.page-title {
font-size: 16px;
font-weight: 600;
}
.mr8 {
margin-right: 8px;
}
.node-head {
display: flex;
justify-content: space-between;
gap: 8px;
}
.node-ops {
display: inline-flex;
gap: 8px;
}
.node-meta {
color: #8a8a8a;
font-size: 12px;
margin: 2px 0;
}
.node-media {
display: flex;
gap: 8px;
margin-top: 6px;
flex-wrap: wrap;
}
.cert-meta {
font-size: 12px;
color: #6b7280;
}
.cert-pending {
height: 140px;
display: flex;
align-items: center;
justify-content: center;
color: #9ca3af;
background: #f4f7fc;
}
</style>
+139
View File
@@ -0,0 +1,139 @@
<template>
<div class="page">
<div class="page-toolbar">
<n-input
v-model:value="query.keyword"
:placeholder="t('common.label.keyword')"
clearable
style="width: 220px"
@keyup.enter="onSearch"
/>
<n-select
v-model:value="query.status"
:options="statusOptions"
clearable
:placeholder="t('common.label.status')"
style="width: 140px"
@update:value="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" type="primary" @click="goCreate">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.create') }}
</n-button>
</div>
<n-data-table
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
remote
:row-key="(r) => r.id"
@update:page="onPage"
/>
</div>
</template>
<script setup lang="ts">
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 } from '@vicons/ionicons5';
import { ArtworkStatus } from '@artveris/shared';
import { artworkApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { fmt, statusType } from '@/utils/format';
const { t } = useI18n();
const router = useRouter();
const auth = useAuthStore();
const rows = ref<any[]>([]);
const loading = ref(false);
const query = reactive<{ keyword: string; status: string | null; page: number; pageSize: number }>({
keyword: '',
status: null,
page: 1,
pageSize: 10,
});
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
const statusOptions = Object.values(ArtworkStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
const columns: DataTableColumns<any> = [
{
title: () => t('pages.artwork.images'),
key: 'cover',
width: 76,
render: (r) =>
r.images?.[0]?.url
? h(NAvatar, { src: r.images[0].url, size: 44, style: 'border-radius:8px' })
: h(NAvatar, { size: 44, style: 'border-radius:8px' }, { default: () => '—' }),
},
{ title: () => t('pages.artwork.title'), key: 'title', ellipsis: { tooltip: true } },
{ title: () => t('pages.artwork.artist'), key: 'artist', width: 120, render: (r) => r.artist || '-' },
{ title: () => t('pages.artwork.template'), key: 'template', width: 130, render: (r) => r.template?.name || '-' },
{
title: () => t('pages.artwork.traceCode'),
key: 'traceCode',
width: 130,
render: (r) =>
r.traceCode
? h(NTag, { size: 'small', type: statusType(r.traceCode.status) }, { default: () => r.traceCode.shortCode })
: h(NTag, { size: 'small' }, { default: () => t('pages.artwork.noTrace') }),
},
{
title: () => t('common.label.status'),
key: 'status',
width: 90,
render: (r) => h(NTag, { type: statusType(r.status), size: 'small' }, { default: () => t(`common.status.${r.status}`) }),
},
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 160, render: (r) => fmt(r.createdAt) },
{
title: () => t('common.label.operation'),
key: 'ops',
width: 90,
render: (r) =>
h(
NButton,
{ quaternary: true, circle: true, size: 'small', onClick: () => router.push(`/artworks/${r.id}`) },
{ icon: () => h(NIcon, null, { default: () => h(CreateOutline) }) },
),
},
];
async function load() {
loading.value = true;
try {
const res: any = await artworkApi.list({
keyword: query.keyword,
status: query.status || 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 goCreate() {
router.push('/artworks/new');
}
onMounted(load);
</script>
+152
View File
@@ -0,0 +1,152 @@
<template>
<div class="page">
<div class="stat-grid">
<n-card v-for="s in stats" :key="s.key" class="stat-card" :bordered="false">
<div class="stat-inner">
<div class="stat-icon" :style="{ background: s.color }">
<n-icon :component="s.icon" />
</div>
<div>
<div class="stat-value">{{ data?.[s.key] ?? 0 }}</div>
<div class="stat-label">{{ s.label }}</div>
</div>
</div>
</n-card>
</div>
<n-grid :cols="3" :x-gap="16" :y-gap="16" item-responsive responsive="screen" class="mt16">
<n-grid-item span="3 m:2">
<n-card :title="t('pages.dashboard.trendTitle')" :bordered="false">
<v-chart class="chart" :option="trendOption" autoresize />
</n-card>
</n-grid-item>
<n-grid-item span="3 m:1">
<n-card :title="t('pages.dashboard.topTitle')" :bordered="false">
<n-empty v-if="!data?.topArtworks?.length" :description="t('common.msg.noData')" />
<n-list v-else>
<n-list-item v-for="(item, i) in data.topArtworks" :key="i">
<div class="top-row">
<n-tag :type="i < 3 ? 'warning' : 'default'" size="small" round>{{ i + 1 }}</n-tag>
<span class="top-title text-ellipsis">{{ item.title }}</span>
<span class="top-count">{{ item.queryCount }}</span>
</div>
</n-list-item>
</n-list>
</n-card>
</n-grid-item>
</n-grid>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { use } from 'echarts/core';
import { LineChart } from 'echarts/charts';
import { GridComponent, TooltipComponent } from 'echarts/components';
import { CanvasRenderer } from 'echarts/renderers';
import VChart from 'vue-echarts';
import {
ImagesOutline,
QrCodeOutline,
CheckmarkCircleOutline,
SearchOutline,
TodayOutline,
WarningOutline,
} from '@vicons/ionicons5';
import { dashboardApi } from '@/api';
use([LineChart, GridComponent, TooltipComponent, CanvasRenderer]);
const { t } = useI18n();
const data = ref<any>(null);
const stats = computed(() => [
{ key: 'totalArtworks', label: t('pages.dashboard.totalArtworks'), icon: ImagesOutline, color: '#1f3864' },
{ key: 'boundCodes', label: t('pages.dashboard.boundCodes'), icon: QrCodeOutline, color: '#2e5496' },
{ key: 'activatedCodes', label: t('pages.dashboard.activatedCodes'), icon: CheckmarkCircleOutline, color: '#138a72' },
{ key: 'totalQueries', label: t('pages.dashboard.totalQueries'), icon: SearchOutline, color: '#3a7bd5' },
{ key: 'todayQueries', label: t('pages.dashboard.todayQueries'), icon: TodayOutline, color: '#b9851f' },
{ key: 'abnormalQueries', label: t('pages.dashboard.abnormalQueries'), icon: WarningOutline, color: '#c0392b' },
]);
const trendOption = computed(() => ({
tooltip: { trigger: 'axis' },
grid: { left: 40, right: 16, top: 24, bottom: 28 },
xAxis: {
type: 'category',
boundaryGap: false,
data: (data.value?.trend ?? []).map((d: any) => d.date),
},
yAxis: { type: 'value', minInterval: 1 },
series: [
{
name: t('pages.dashboard.queryCount'),
type: 'line',
smooth: true,
areaStyle: { opacity: 0.12 },
itemStyle: { color: '#2e5496' },
data: (data.value?.trend ?? []).map((d: any) => d.count),
},
],
}));
onMounted(async () => {
data.value = await dashboardApi.overview();
});
</script>
<style scoped>
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 16px;
}
.stat-card {
border-radius: 12px;
}
.stat-inner {
display: flex;
align-items: center;
gap: 16px;
}
.stat-icon {
width: 52px;
height: 52px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 26px;
}
.stat-value {
font-size: 28px;
font-weight: 700;
color: #1f2937;
line-height: 1.2;
}
.stat-label {
font-size: 13px;
color: #6b7280;
}
.mt16 {
margin-top: 16px;
}
.chart {
height: 320px;
}
.top-row {
display: flex;
align-items: center;
gap: 12px;
width: 100%;
}
.top-title {
flex: 1 1 auto;
}
.top-count {
font-weight: 600;
color: #2e5496;
}
</style>
+169
View File
@@ -0,0 +1,169 @@
<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"
/>
</div>
<div class="login-left">
<div class="login-left-inner">
<div class="logo">艺</div>
<h1>{{ t('pages.login.title') }}</h1>
<p>{{ t('pages.login.subtitle') }}</p>
</div>
</div>
<div class="login-right">
<n-card class="login-card" :bordered="false">
<h2 class="login-card-title">{{ t('pages.login.subtitle') }}</h2>
<n-form ref="formRef" :model="form" :rules="rules" @keyup.enter="onSubmit">
<n-form-item path="username" :label="t('pages.login.username')">
<n-input
v-model:value="form.username"
:placeholder="t('pages.login.placeholderUser')"
size="large"
>
<template #prefix><n-icon :component="PersonOutline" /></template>
</n-input>
</n-form-item>
<n-form-item path="password" :label="t('pages.login.password')">
<n-input
v-model:value="form.password"
type="password"
show-password-on="click"
:placeholder="t('pages.login.placeholderPass')"
size="large"
>
<template #prefix><n-icon :component="LockClosedOutline" /></template>
</n-input>
</n-form-item>
<n-button type="primary" size="large" block :loading="loading" @click="onSubmit">
{{ t('pages.login.submit') }}
</n-button>
</n-form>
</n-card>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
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';
const { t, locale } = 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();
} catch {
return;
}
loading.value = true;
try {
await auth.login(form.value.username, form.value.password);
message.success(t('pages.login.success'));
router.push({ name: 'dashboard' });
} catch {
/* 错误已由拦截器提示 */
} finally {
loading.value = false;
}
}
</script>
<style scoped>
.login-wrap {
position: relative;
display: flex;
height: 100vh;
background: #f0f2f5;
}
.login-lang {
position: absolute;
top: 20px;
right: 24px;
z-index: 2;
}
.login-left {
flex: 1 1 55%;
background: linear-gradient(135deg, #1f3864 0%, #2e5496 100%);
color: #fff;
display: flex;
align-items: center;
justify-content: center;
}
.login-left-inner {
text-align: center;
padding: 24px;
}
.login-left-inner .logo {
width: 72px;
height: 72px;
margin: 0 auto 24px;
border-radius: 18px;
background: rgba(255, 255, 255, 0.16);
display: flex;
align-items: center;
justify-content: center;
font-size: 38px;
font-weight: 700;
}
.login-left-inner h1 {
font-size: 28px;
margin: 0 0 12px;
}
.login-left-inner p {
font-size: 16px;
opacity: 0.85;
margin: 0;
}
.login-right {
flex: 1 1 45%;
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
}
.login-card {
width: 100%;
max-width: 380px;
}
.login-card-title {
margin: 0 0 24px;
font-size: 22px;
color: #1f2937;
text-align: center;
}
@media (max-width: 768px) {
.login-left {
display: none;
}
}
</style>
+87
View File
@@ -0,0 +1,87 @@
<template>
<div class="page">
<n-card :title="t('pages.outbound.import')" :bordered="false">
<n-alert type="info" :show-icon="true" style="margin-bottom: 16px">{{ t('pages.outbound.tip') }}</n-alert>
<n-space>
<n-button @click="downloadTemplate">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('common.action.downloadTemplate') }}
</n-button>
<n-upload
:show-file-list="false"
accept=".xlsx,.xls"
:custom-request="doImport"
:disabled="importing || !auth.canWrite"
>
<n-button type="primary" :loading="importing">
<template #icon><n-icon :component="CloudUploadOutline" /></template>
{{ t('pages.outbound.selectFile') }}
</n-button>
</n-upload>
</n-space>
<n-card v-if="result" embedded :title="t('pages.outbound.importResult')" style="margin-top: 16px">
<n-space align="center" size="large">
<n-statistic :label="t('common.label.total')" :value="result.total" />
<n-statistic :label="t('pages.outbound.successCount')">
<span style="color: #138a72">{{ result.successCount }}</span>
</n-statistic>
<n-statistic :label="t('pages.outbound.failCount')">
<span style="color: #c0392b">{{ result.failCount }}</span>
</n-statistic>
<n-tag :type="statusType(result.status)">{{ t(`common.status.${result.status}`) }}</n-tag>
<n-button v-if="result.resultFileUrl" text tag="a" :href="result.resultFileUrl" target="_blank" type="primary">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('pages.outbound.downloadResult') }}
</n-button>
</n-space>
</n-card>
</n-card>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import type { UploadCustomRequestOptions } from 'naive-ui';
import { DownloadOutline, CloudUploadOutline } from '@vicons/ionicons5';
import { jobApi, outboundApi, post } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { message } from '@/utils/feedback';
import { statusType } from '@/utils/format';
import { downloadFile } from '@/utils/download';
const { t } = useI18n();
const auth = useAuthStore();
const importing = ref(false);
const result = ref<any>(null);
async function downloadTemplate() {
await downloadFile('/outbound/import/template', 'outbound-import-template.xlsx');
}
async function doImport({ file, onFinish, onError }: UploadCustomRequestOptions) {
importing.value = true;
result.value = null;
try {
const fd = new FormData();
fd.append('file', file.file as File);
const res: any = await post('/outbound/import', fd, { headers: { 'Content-Type': 'multipart/form-data' } });
const jobId = res.jobId;
let job: any = null;
for (let i = 0; i < 40; i++) {
await new Promise((r) => setTimeout(r, 700));
job = await jobApi.get(jobId);
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
}
result.value = job;
message.success(t('common.msg.operationSuccess'));
onFinish();
} catch (e) {
message.error((e as Error)?.message || 'import failed');
onError();
} finally {
importing.value = false;
}
}
</script>
+68
View File
@@ -0,0 +1,68 @@
<template>
<div class="page">
<n-card :title="t('pages.profile.title')" :bordered="false" style="max-width: 520px">
<n-descriptions :column="1" label-placement="left" bordered style="margin-bottom: 20px">
<n-descriptions-item :label="t('pages.user.username')">{{ auth.user?.username }}</n-descriptions-item>
<n-descriptions-item :label="t('pages.user.realName')">{{ auth.user?.realName || '-' }}</n-descriptions-item>
<n-descriptions-item :label="t('pages.user.role')">{{ t(`common.role.${auth.user?.role}`) }}</n-descriptions-item>
</n-descriptions>
<n-divider>{{ t('common.action.changePassword') }}</n-divider>
<n-form ref="formRef" :model="form" :rules="rules" label-placement="top">
<n-form-item path="oldPassword" :label="t('pages.profile.oldPassword')">
<n-input v-model:value="form.oldPassword" type="password" show-password-on="click" />
</n-form-item>
<n-form-item path="newPassword" :label="t('pages.profile.newPassword')">
<n-input v-model:value="form.newPassword" type="password" show-password-on="click" />
</n-form-item>
<n-form-item path="confirmPassword" :label="t('pages.profile.confirmPassword')">
<n-input v-model:value="form.confirmPassword" type="password" show-password-on="click" />
</n-form-item>
<n-button type="primary" :loading="saving" @click="submit">{{ t('common.action.changePassword') }}</n-button>
</n-form>
</n-card>
</div>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import type { FormInst, FormRules } from 'naive-ui';
import { authApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { message } from '@/utils/feedback';
const { t } = useI18n();
const router = useRouter();
const auth = useAuthStore();
const formRef = ref<FormInst | null>(null);
const saving = ref(false);
const form = reactive({ oldPassword: '', newPassword: '', confirmPassword: '' });
const rules: FormRules = {
oldPassword: { required: true, message: () => t('pages.profile.oldPassword'), trigger: 'blur' },
newPassword: { required: true, min: 6, message: () => t('pages.profile.newPassword'), trigger: 'blur' },
confirmPassword: {
validator: (_r, v) => v === form.newPassword,
message: () => t('pages.profile.passwordMismatch'),
trigger: 'blur',
},
};
async function submit() {
try {
await formRef.value?.validate();
} catch {
return;
}
saving.value = true;
try {
await authApi.changePassword({ oldPassword: form.oldPassword, newPassword: form.newPassword });
message.success(t('pages.profile.changed'));
auth.logout();
router.push({ name: 'login' });
} finally {
saving.value = false;
}
}
</script>
+123
View File
@@ -0,0 +1,123 @@
<template>
<div class="page">
<div class="page-toolbar">
<n-input
v-model:value="query.keyword"
:placeholder="t('pages.traceCode.shortCode')"
clearable
style="width: 180px"
@keyup.enter="onSearch"
/>
<n-select
v-model:value="query.result"
:options="resultOptions"
clearable
:placeholder="t('pages.queryLog.result')"
style="width: 150px"
@update:value="onSearch"
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
clearable
style="width: 360px"
@update:value="onRange"
/>
<n-button type="primary" @click="onSearch">
<template #icon><n-icon :component="SearchOutline" /></template>
{{ t('common.action.search') }}
</n-button>
</div>
<n-data-table
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
remote
:row-key="(r) => r.id"
@update:page="onPage"
/>
</div>
</template>
<script setup lang="ts">
import { h, onMounted, reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { NTag, type DataTableColumns } from 'naive-ui';
import { SearchOutline } from '@vicons/ionicons5';
import dayjs from 'dayjs';
import { QueryResult } from '@artveris/shared';
import { queryLogApi } from '@/api';
import { fmt, statusType } from '@/utils/format';
const { t } = useI18n();
const rows = ref<any[]>([]);
const loading = ref(false);
const range = ref<[number, number] | null>(null);
const query = reactive<{ keyword: string; result: string | null; startTime?: string; endTime?: string; page: number; pageSize: number }>({
keyword: '',
result: null,
page: 1,
pageSize: 10,
});
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
const resultOptions = Object.values(QueryResult).map((v) => ({ label: t(`common.queryResult.${v}`), value: v }));
const columns: DataTableColumns<any> = [
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 130, render: (r) => r.shortCode || '-' },
{
title: () => t('pages.queryLog.result'),
key: 'queryResult',
width: 110,
render: (r) => h(NTag, { size: 'small', type: statusType(r.queryResult) }, { default: () => t(`common.queryResult.${r.queryResult}`) }),
},
{
title: () => t('pages.queryLog.ip'),
key: 'ip',
width: 200,
render: (r) => `${r.ip || '-'} / ${r.region || '-'}`,
},
{ title: () => t('pages.queryLog.device'), key: 'deviceType', width: 110, render: (r) => r.deviceType || '-' },
{ title: () => t('pages.queryLog.queriedAt'), key: 'queriedAt', width: 170, render: (r) => fmt(r.queriedAt) },
];
async function load() {
loading.value = true;
try {
const res: any = await queryLogApi.list({
keyword: query.keyword || undefined,
result: query.result || undefined,
startTime: query.startTime,
endTime: query.endTime,
page: query.page,
pageSize: query.pageSize,
});
rows.value = res.list;
pagination.itemCount = res.total;
pagination.page = res.page;
} finally {
loading.value = false;
}
}
function onRange(val: [number, number] | null) {
if (val) {
query.startTime = dayjs(val[0]).toISOString();
query.endTime = dayjs(val[1]).toISOString();
} else {
query.startTime = undefined;
query.endTime = undefined;
}
onSearch();
}
function onSearch() {
query.page = 1;
load();
}
function onPage(p: number) {
query.page = p;
load();
}
onMounted(load);
</script>
+54
View File
@@ -0,0 +1,54 @@
<template>
<div class="page">
<n-card :title="t('menu.settings')" :bordered="false" style="max-width: 640px">
<n-form label-placement="top">
<n-form-item :label="t('pages.settings.appName')">
<n-input v-model:value="form.appName" />
</n-form-item>
<n-form-item :label="t('pages.settings.logRetentionDays')">
<n-input-number v-model:value="form.logRetentionDays" :min="1" style="width: 220px" />
</n-form-item>
<n-form-item :label="t('pages.settings.watermarkText')">
<n-input v-model:value="form.watermarkText" />
</n-form-item>
<n-button type="primary" :loading="saving" @click="save">{{ t('common.action.save') }}</n-button>
</n-form>
</n-card>
</div>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { settingsApi } from '@/api';
import { message } from '@/utils/feedback';
const { t } = useI18n();
const saving = ref(false);
const form = reactive<{ appName: string; logRetentionDays: number; watermarkText: string }>({
appName: '',
logRetentionDays: 365,
watermarkText: '',
});
async function load() {
const s = await settingsApi.getAll();
form.appName = s.appName || '';
form.logRetentionDays = Number(s.logRetentionDays || 365);
form.watermarkText = s.watermarkText || '';
}
async function save() {
saving.value = true;
try {
await settingsApi.update({
appName: form.appName,
logRetentionDays: String(form.logRetentionDays),
watermarkText: form.watermarkText,
});
message.success(t('pages.settings.saved'));
} finally {
saving.value = false;
}
}
onMounted(load);
</script>
+226
View File
@@ -0,0 +1,226 @@
<template>
<div class="page">
<div class="page-toolbar">
<n-input
v-model:value="query.keyword"
:placeholder="t('common.label.keyword')"
clearable
style="width: 220px"
@keyup.enter="load"
/>
<n-button type="primary" @click="load">
<template #icon><n-icon :component="SearchOutline" /></template>
{{ t('common.action.search') }}
</n-button>
<div class="spacer" />
<n-button v-if="auth.canWrite" type="primary" @click="openCreate">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.template.create') }}
</n-button>
</div>
<n-data-table
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
remote
:row-key="(r) => r.id"
@update:page="onPage"
/>
<n-modal
v-model:show="showModal"
preset="card"
:title="editing ? t('pages.template.edit') : t('pages.template.create')"
style="width: 720px; max-width: 94vw"
>
<n-form ref="formRef" :model="form" :rules="rules">
<n-form-item path="name" :label="t('pages.template.name')">
<n-input v-model:value="form.name" :placeholder="t('pages.template.namePlaceholder')" />
</n-form-item>
<n-form-item :label="t('common.label.remark')">
<n-input v-model:value="form.remark" type="textarea" :rows="2" />
</n-form-item>
<n-form-item :label="t('pages.template.fields')">
<div style="width: 100%">
<div v-for="(f, i) in form.fields" :key="i" class="field-row">
<n-input v-model:value="f.fieldKey" :placeholder="t('pages.template.fieldKeyTip')" style="width: 130px" />
<n-input v-model:value="f.label" :placeholder="t('pages.template.fieldLabel')" style="width: 120px" />
<n-select v-model:value="f.type" :options="fieldTypeOptions" style="width: 120px" />
<n-checkbox v-model:checked="f.required">{{ t('pages.template.required') }}</n-checkbox>
<n-button quaternary circle type="error" @click="form.fields.splice(i, 1)">
<template #icon><n-icon :component="TrashOutline" /></template>
</n-button>
</div>
<n-button dashed block @click="addField">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.template.addField') }}
</n-button>
</div>
</n-form-item>
</n-form>
<template #footer>
<div style="text-align: right">
<n-button class="mr8" @click="showModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" :loading="saving" @click="save">{{ t('common.action.save') }}</n-button>
</div>
</template>
</n-modal>
</div>
</template>
<script setup lang="ts">
import { h, onMounted, reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { NButton, NIcon, NTag, type DataTableColumns, type FormInst, type FormRules } from 'naive-ui';
import { SearchOutline, AddOutline, TrashOutline, CreateOutline } from '@vicons/ionicons5';
import { FieldType } from '@artveris/shared';
import { templateApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { message, dialog } from '@/utils/feedback';
import { fmt, statusType } from '@/utils/format';
const { t } = useI18n();
const auth = useAuthStore();
const rows = ref<any[]>([]);
const loading = ref(false);
const query = reactive({ keyword: '', page: 1, pageSize: 10 });
const pagination = reactive({ page: 1, pageCount: 1, pageSize: 10, itemCount: 0 });
const fieldTypeOptions = Object.values(FieldType).map((v) => ({ label: t(`common.fieldType.${v}`), value: v }));
const showModal = ref(false);
const editing = ref<number | null>(null);
const saving = ref(false);
const formRef = ref<FormInst | null>(null);
const form = reactive<{ name: string; remark: string; fields: any[] }>({ name: '', remark: '', fields: [] });
const rules: FormRules = { name: { required: true, message: () => t('pages.template.namePlaceholder'), trigger: 'blur' } };
const columns: DataTableColumns<any> = [
{ title: 'ID', key: 'id', width: 70 },
{ title: () => t('pages.template.name'), key: 'name' },
{
title: () => t('pages.template.fields'),
key: 'fields',
render: (r) => (r.fields || []).map((f: any) => f.label).join('、') || '-',
},
{
title: () => t('common.label.status'),
key: 'status',
width: 90,
render: (r) => h(NTag, { type: statusType(r.status), size: 'small' }, { default: () => t(`common.status.${r.status}`) }),
},
{ title: () => t('pages.template.useCount'), key: 'useCount', width: 100, render: (r) => r._count?.artworks ?? 0 },
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 160, render: (r) => fmt(r.createdAt) },
{
title: () => t('common.label.operation'),
key: 'ops',
width: 130,
render: (r) =>
auth.canWrite
? h('div', { style: 'display:flex;gap:4px' }, [
h(
NButton,
{ quaternary: true, circle: true, size: 'small', onClick: () => openEdit(r) },
{ icon: () => h(NIcon, null, { default: () => h(CreateOutline) }) },
),
h(
NButton,
{ quaternary: true, circle: true, size: 'small', type: 'error', onClick: () => remove(r) },
{ icon: () => h(NIcon, null, { default: () => h(TrashOutline) }) },
),
])
: '-',
},
];
async function load() {
loading.value = true;
try {
const res: any = await templateApi.list({ keyword: query.keyword, page: query.page, pageSize: query.pageSize });
rows.value = res.list;
pagination.itemCount = res.total;
pagination.page = res.page;
pagination.pageSize = res.pageSize;
} finally {
loading.value = false;
}
}
function onPage(p: number) {
query.page = p;
load();
}
function addField() {
form.fields.push({ fieldKey: '', label: '', type: FieldType.TEXT, required: false });
}
function openCreate() {
editing.value = null;
form.name = '';
form.remark = '';
form.fields = [{ fieldKey: '', label: '', type: FieldType.TEXT, required: false }];
showModal.value = true;
}
function openEdit(r: any) {
editing.value = r.id;
form.name = r.name;
form.remark = r.remark || '';
form.fields = (r.fields || []).map((f: any) => ({ ...f }));
showModal.value = true;
}
async function save() {
try {
await formRef.value?.validate();
} catch {
return;
}
if (!form.fields.length || form.fields.some((f) => !f.fieldKey || !f.label)) {
message.error(t('pages.template.fields') + ' ✕');
return;
}
saving.value = true;
try {
const payload = { name: form.name, remark: form.remark, fields: form.fields };
if (editing.value) {
await templateApi.update(editing.value, payload);
message.success(t('common.msg.updated'));
} else {
await templateApi.create(payload);
message.success(t('common.msg.created'));
}
showModal.value = false;
load();
} finally {
saving.value = false;
}
}
function remove(r: 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 templateApi.remove(r.id);
message.success(t('common.msg.deleted'));
load();
},
});
}
onMounted(load);
</script>
<style scoped>
.field-row {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.mr8 {
margin-right: 8px;
}
</style>
+219
View File
@@ -0,0 +1,219 @@
<template>
<div class="page">
<div class="page-toolbar">
<n-select
v-model:value="query.batchId"
:options="batchOptions"
clearable
:placeholder="t('pages.traceCode.batchNo')"
style="width: 200px"
@update:value="onSearch"
/>
<n-select
v-model:value="query.status"
:options="statusOptions"
clearable
:placeholder="t('common.label.status')"
style="width: 140px"
@update:value="onSearch"
/>
<n-input
v-model:value="query.keyword"
:placeholder="t('pages.traceCode.shortCode')"
clearable
style="width: 180px"
@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 && query.batchId" @click="exportBatch">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('pages.traceCode.exportBatch') }}
</n-button>
<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-data-table
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
remote
:row-key="(r) => r.id"
@update:page="onPage"
/>
<n-modal v-model:show="genModal" preset="card" :title="t('pages.traceCode.generate')" 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>
<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; color: #6b7280; word-break: break-all">{{ qrUrl }}</div>
</div>
</n-modal>
</div>
</template>
<script setup lang="ts">
import { 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 { TraceCodeStatus } from '@artveris/shared';
import { traceCodeApi, jobApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { message } from '@/utils/feedback';
import { fmt, statusType } from '@/utils/format';
import { downloadFile } from '@/utils/download';
const { t } = useI18n();
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 }>({
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 genModal = ref(false);
const generating = ref(false);
const genForm = reactive<{ quantity: number; batchNo: string }>({ quantity: 100, batchNo: '' });
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 } },
{
title: () => t('pages.artwork.title'),
key: 'artwork',
width: 150,
render: (r) => r.artwork?.title || '-',
},
{
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('pages.traceCode.queryCount'), key: 'queryCount', width: 90 },
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 160, render: (r) => fmt(r.firstActivatedAt) },
{
title: () => t('common.label.operation'),
key: 'ops',
width: 80,
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 load() {
loading.value = true;
try {
const res: any = await traceCodeApi.list({
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() {
generating.value = true;
try {
const res: any = await traceCodeApi.generate({ quantity: genForm.quantity, batchNo: genForm.batchNo || 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;
}
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;
}
async function exportBatch() {
if (!query.batchId) return;
await downloadFile('/trace-codes/export', `trace-codes-${query.batchId}.xlsx`, { batchId: query.batchId });
}
onMounted(async () => {
await loadBatches();
await load();
});
</script>
<style scoped>
.mr8 {
margin-right: 8px;
}
</style>
+199
View File
@@ -0,0 +1,199 @@
<template>
<div class="page">
<div class="page-toolbar">
<n-input v-model:value="query.keyword" :placeholder="t('common.label.keyword')" clearable style="width: 200px" @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 type="primary" @click="openCreate">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.user.create') }}
</n-button>
</div>
<n-data-table :columns="columns" :data="rows" :loading="loading" :pagination="pagination" remote :row-key="(r) => r.id" @update:page="onPage" />
<n-modal v-model:show="showModal" preset="card" :title="editing ? t('pages.user.edit') : t('pages.user.create')" style="width: 460px">
<n-form ref="formRef" :model="form" :rules="rules" label-placement="top">
<n-form-item path="username" :label="t('pages.user.username')">
<n-input v-model:value="form.username" :disabled="!!editing" />
</n-form-item>
<n-form-item v-if="!editing" path="password" :label="t('pages.login.password')">
<n-input v-model:value="form.password" type="password" show-password-on="click" />
</n-form-item>
<n-form-item :label="t('pages.user.realName')">
<n-input v-model:value="form.realName" />
</n-form-item>
<n-form-item :label="t('pages.user.role')">
<n-select v-model:value="form.role" :options="roleOptions" />
</n-form-item>
<n-form-item v-if="editing" :label="t('common.label.status')">
<n-select v-model:value="form.status" :options="statusOptions" />
</n-form-item>
</n-form>
<template #footer>
<div style="text-align: right">
<n-button class="mr8" @click="showModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" :loading="saving" @click="save">{{ t('common.action.save') }}</n-button>
</div>
</template>
</n-modal>
<n-modal v-model:show="pwdModal" preset="card" :title="t('pages.user.resetPassword')" style="width: 380px">
<n-input v-model:value="newPwd" type="password" show-password-on="click" :placeholder="t('pages.user.newPassword')" />
<template #footer>
<div style="text-align: right">
<n-button class="mr8" @click="pwdModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" @click="doReset">{{ t('common.action.confirm') }}</n-button>
</div>
</template>
</n-modal>
</div>
</template>
<script setup lang="ts">
import { h, onMounted, reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { NButton, NIcon, NTag, type DataTableColumns, type FormInst, type FormRules } from 'naive-ui';
import { SearchOutline, AddOutline, CreateOutline, KeyOutline, TrashOutline } from '@vicons/ionicons5';
import { RoleType, UserStatus } from '@artveris/shared';
import { userApi } from '@/api';
import { message, dialog } from '@/utils/feedback';
import { fmt, statusType } from '@/utils/format';
const { t } = useI18n();
const rows = ref<any[]>([]);
const loading = ref(false);
const query = reactive({ keyword: '', page: 1, pageSize: 10 });
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
const roleOptions = Object.values(RoleType).map((v) => ({ label: t(`common.role.${v}`), value: v }));
const statusOptions = Object.values(UserStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
const showModal = ref(false);
const editing = ref<number | null>(null);
const saving = ref(false);
const formRef = ref<FormInst | null>(null);
const form = reactive<any>({ username: '', password: '', realName: '', role: RoleType.OPERATOR, status: UserStatus.ACTIVE });
const rules: FormRules = {
username: { required: true, message: () => t('pages.user.username'), trigger: 'blur' },
password: { required: true, message: () => t('pages.login.password'), trigger: 'blur' },
};
const pwdModal = ref(false);
const newPwd = ref('');
const pwdUserId = ref<number | null>(null);
const columns: DataTableColumns<any> = [
{ title: 'ID', key: 'id', width: 64 },
{ title: () => t('pages.user.username'), key: 'username' },
{ title: () => t('pages.user.realName'), key: 'realName', render: (r) => r.realName || '-' },
{ title: () => t('pages.user.role'), key: 'role', width: 120, render: (r) => t(`common.role.${r.role}`) },
{
title: () => t('common.label.status'),
key: 'status',
width: 90,
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
},
{ title: () => t('pages.user.lastLoginAt'), key: 'lastLoginAt', width: 160, render: (r) => fmt(r.lastLoginAt) },
{
title: () => t('common.label.operation'),
key: 'ops',
width: 140,
render: (r) =>
h('div', { style: 'display:flex;gap:2px' }, [
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => openEdit(r) }, { icon: () => h(NIcon, null, { default: () => h(CreateOutline) }) }),
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => openReset(r) }, { icon: () => h(NIcon, null, { default: () => h(KeyOutline) }) }),
h(NButton, { quaternary: true, circle: true, size: 'small', type: 'error', onClick: () => remove(r) }, { icon: () => h(NIcon, null, { default: () => h(TrashOutline) }) }),
]),
},
];
async function load() {
loading.value = true;
try {
const res: any = await userApi.list({ keyword: query.keyword, 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 openCreate() {
editing.value = null;
Object.assign(form, { username: '', password: '', realName: '', role: RoleType.OPERATOR, status: UserStatus.ACTIVE });
showModal.value = true;
}
function openEdit(r: any) {
editing.value = r.id;
Object.assign(form, { username: r.username, realName: r.realName || '', role: r.role, status: r.status });
showModal.value = true;
}
async function save() {
try {
await formRef.value?.validate();
} catch {
return;
}
saving.value = true;
try {
if (editing.value) {
await userApi.update(editing.value, { realName: form.realName, role: form.role, status: form.status });
message.success(t('common.msg.updated'));
} else {
await userApi.create({ username: form.username, password: form.password, realName: form.realName, role: form.role });
message.success(t('common.msg.created'));
}
showModal.value = false;
load();
} finally {
saving.value = false;
}
}
function openReset(r: any) {
pwdUserId.value = r.id;
newPwd.value = '';
pwdModal.value = true;
}
async function doReset() {
if (!pwdUserId.value || newPwd.value.length < 6) {
message.error(t('pages.user.newPassword'));
return;
}
await userApi.resetPassword(pwdUserId.value, newPwd.value);
message.success(t('common.msg.updated'));
pwdModal.value = false;
}
function remove(r: 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 userApi.remove(r.id);
message.success(t('common.msg.deleted'));
load();
},
});
}
onMounted(load);
</script>
<style scoped>
.mr8 {
margin-right: 8px;
}
</style>