feat: 实现后台管理前端全部页面与登录布局
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user