261 lines
8.5 KiB
Vue
261 lines
8.5 KiB
Vue
<template>
|
|
<div class="page table-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-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="false"
|
|
class="table-fill"
|
|
flex-height
|
|
remote
|
|
:scroll-x="1400"
|
|
:row-key="(r) => r.id"
|
|
@update:sorter="onSorterChange"
|
|
/>
|
|
<div class="table-pagination">
|
|
<n-pagination v-bind="pagination" :disabled="loading" />
|
|
</div>
|
|
</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, BarChartOutline, TrashOutline } from '@vicons/ionicons5';
|
|
import { ArtworkStatus, AuditStatus } from '@artveris/shared';
|
|
import { artworkApi } from '@/api';
|
|
import { useAuthStore } from '@/stores/auth';
|
|
import { fmt, statusType } from '@/utils/format';
|
|
import { useTablePage } from '@/composables/useTablePage';
|
|
import { dialog, message } from '@/utils/feedback';
|
|
import { renderTableFilterTitle } from '@/utils/tableFilter';
|
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
|
import { useRemoteSort } from '@/utils/tableSort';
|
|
|
|
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; auditStatus: string | null }>({
|
|
keyword: '',
|
|
status: null,
|
|
auditStatus: null,
|
|
});
|
|
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load);
|
|
const { sortProps, onSorterChange, sortParams } = useRemoteSort(onSearch);
|
|
const statusOptions = Object.values(ArtworkStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
|
const auditStatusOptions = Object.values(AuditStatus).map((v) => ({ label: t(`common.auditStatus.${v}`), value: v }));
|
|
|
|
const columns: DataTableColumns<any> = [
|
|
{
|
|
title: () => t('pages.artwork.images'),
|
|
key: 'cover',
|
|
width: 76,
|
|
align: 'center',
|
|
render: (r) =>
|
|
r.images?.[0]?.url
|
|
? h(NAvatar, {
|
|
src: r.images[0].url,
|
|
size: 44,
|
|
style: 'border-radius:8px;cursor:zoom-in',
|
|
onClick: () => previewArtworkImages(r.images),
|
|
})
|
|
: h(NAvatar, { size: 44, style: 'border-radius:8px' }, { default: () => '—' }),
|
|
},
|
|
{
|
|
title: () => t('pages.artwork.archiveNo'),
|
|
key: 'archiveNo',
|
|
width: 170,
|
|
align: 'center',
|
|
ellipsis: { tooltip: true },
|
|
render: (r) =>
|
|
h(
|
|
NButton,
|
|
{ text: true, type: 'primary', title: t('pages.artwork.editDetail'), onClick: () => router.push(`/artworks/${r.id}`) },
|
|
{ default: () => r.archiveNo || '-' },
|
|
),
|
|
},
|
|
{ title: () => t('pages.artwork.title'), key: 'title', minWidth: 220, ellipsis: { tooltip: true } },
|
|
{ title: () => t('pages.artwork.artist'), key: 'artist', minWidth: 130, ellipsis: { tooltip: true }, render: (r) => r.artist || '-' },
|
|
{ title: () => t('pages.artwork.template'), key: 'template', minWidth: 150, ellipsis: { tooltip: true }, render: (r) => r.template?.name || '-' },
|
|
{ title: () => t('pages.artwork.codeCount'), key: 'codeCount', width: 100, align: 'center', render: (r) => r.codeCount ?? 0 },
|
|
{ title: () => t('pages.artwork.queryTotal'), key: 'queryTotal', width: 100, align: 'center', render: (r) => r.queryTotal ?? 0 },
|
|
{
|
|
title: () => renderTableFilterTitle(t('common.label.status'), query.status, statusOptions, (value) => setFilter('status', value)),
|
|
key: 'status',
|
|
width: 96,
|
|
align: 'center',
|
|
render: (r) => h(NTag, { type: statusType(r.status), size: 'small' }, { default: () => t(`common.status.${r.status}`) }),
|
|
},
|
|
{
|
|
title: () => renderTableFilterTitle(t('pages.audit.status'), query.auditStatus, auditStatusOptions, (value) => setFilter('auditStatus', value)),
|
|
key: 'auditStatus',
|
|
width: 124,
|
|
align: 'center',
|
|
render: (r) => {
|
|
const display = auditDisplay(r);
|
|
return h(
|
|
NTag,
|
|
{
|
|
size: 'small',
|
|
type: display.type,
|
|
title: display.tip,
|
|
},
|
|
{ default: () => display.label },
|
|
);
|
|
},
|
|
},
|
|
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 150, align: 'center', ellipsis: { tooltip: true }, render: (r) => fmt(r.createdAt), ...sortProps('createdAt') },
|
|
{
|
|
title: () => t('common.label.operation'),
|
|
key: 'ops',
|
|
width: 148,
|
|
fixed: 'right',
|
|
align: 'center',
|
|
render: (r) =>
|
|
h('div', { class: 'row-actions' }, [
|
|
h(
|
|
NButton,
|
|
{
|
|
quaternary: true,
|
|
circle: true,
|
|
size: 'small',
|
|
title: t('pages.artwork.editDetail'),
|
|
onClick: () => router.push(`/artworks/${r.id}`),
|
|
},
|
|
{ icon: () => h(NIcon, null, { default: () => h(CreateOutline) }) },
|
|
),
|
|
h(
|
|
NButton,
|
|
{
|
|
quaternary: true,
|
|
circle: true,
|
|
size: 'small',
|
|
title: t('pages.artwork.dataManage'),
|
|
onClick: () => router.push(`/artworks/${r.id}/trace-codes`),
|
|
},
|
|
{ icon: () => h(NIcon, null, { default: () => h(BarChartOutline) }) },
|
|
),
|
|
auth.canWrite
|
|
? h(
|
|
NButton,
|
|
{
|
|
quaternary: true,
|
|
circle: true,
|
|
size: 'small',
|
|
type: 'error',
|
|
disabled: (r.codeCount ?? 0) > 0,
|
|
title: (r.codeCount ?? 0) > 0 ? t('pages.artwork.deleteDisabledTip') : t('common.action.delete'),
|
|
onClick: () => remove(r),
|
|
},
|
|
{ icon: () => h(NIcon, null, { default: () => h(TrashOutline) }) },
|
|
)
|
|
: null,
|
|
]),
|
|
},
|
|
];
|
|
|
|
async function load() {
|
|
loading.value = true;
|
|
try {
|
|
const res: any = await artworkApi.list({
|
|
keyword: query.keyword,
|
|
status: query.status || undefined,
|
|
auditStatus: query.auditStatus || undefined,
|
|
page: page.value,
|
|
pageSize: pageSize.value,
|
|
...sortParams(),
|
|
});
|
|
rows.value = res.list;
|
|
setPageResult(res);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
function onSearch() {
|
|
resetPage();
|
|
load();
|
|
}
|
|
function setFilter(field: 'status' | 'auditStatus', value: string | number | null) {
|
|
query[field] = value ? String(value) : null;
|
|
onSearch();
|
|
}
|
|
function auditDisplay(r: any) {
|
|
if (r.latestRevision?.status === 'PENDING') {
|
|
return {
|
|
label: t('pages.artwork.pendingChange'),
|
|
type: 'warning' as const,
|
|
tip: t('pages.audit.pendingRevisionTip'),
|
|
};
|
|
}
|
|
if (r.latestRevision?.status === 'REJECTED') {
|
|
return {
|
|
label: t('pages.artwork.rejectedChange'),
|
|
type: 'error' as const,
|
|
tip: r.latestRevision.auditRemark || t('pages.audit.rejectedRevisionTip'),
|
|
};
|
|
}
|
|
const status = r.auditStatus || 'PENDING';
|
|
return {
|
|
label: t(`common.auditStatus.${status}`),
|
|
type: status === 'APPROVED' ? ('success' as const) : status === 'REJECTED' ? ('error' as const) : ('warning' as const),
|
|
tip: r.auditRemark || t('pages.audit.formalStatus'),
|
|
};
|
|
}
|
|
function goCreate() {
|
|
router.push('/artworks/new');
|
|
}
|
|
function previewArtworkImages(images: any[]) {
|
|
void openMediaViewer(
|
|
(images || []).map((item) => ({ url: item.url || item.key, name: item.name || item.key, type: item.type || 'image' })),
|
|
0,
|
|
);
|
|
}
|
|
function remove(r: any) {
|
|
dialog.warning({
|
|
title: t('common.action.delete'),
|
|
content: t('pages.artwork.deleteConfirm'),
|
|
positiveText: t('common.action.confirm'),
|
|
negativeText: t('common.action.cancel'),
|
|
onPositiveClick: async () => {
|
|
await artworkApi.remove(r.id);
|
|
message.success(t('common.msg.deleted'));
|
|
await load();
|
|
},
|
|
});
|
|
}
|
|
|
|
onMounted(load);
|
|
</script>
|
|
|
|
<style scoped>
|
|
.row-actions {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
}
|
|
</style>
|