229 lines
8.3 KiB
Vue
229 lines
8.3 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>
|
|
|
|
<n-data-table
|
|
:columns="columns"
|
|
:data="rows"
|
|
:loading="loading"
|
|
:pagination="false"
|
|
class="table-fill"
|
|
flex-height
|
|
remote
|
|
:scroll-x="1750"
|
|
:row-key="(r) => r.id"
|
|
@update:sorter="onSorterChange"
|
|
/>
|
|
<div class="table-pagination">
|
|
<n-pagination v-bind="pagination" :disabled="loading" />
|
|
</div>
|
|
|
|
<n-modal v-model:show="rejectModal" preset="card" :title="t('pages.audit.reject')" style="width: 420px">
|
|
<n-form label-placement="top">
|
|
<n-form-item :label="t('pages.audit.remark')">
|
|
<n-input v-model:value="rejectRemark" type="textarea" :rows="3" :placeholder="t('pages.audit.remarkPlaceholder')" />
|
|
</n-form-item>
|
|
</n-form>
|
|
<template #footer>
|
|
<div style="text-align: right">
|
|
<n-button class="mr8" @click="rejectModal = false">{{ t('common.action.cancel') }}</n-button>
|
|
<n-button type="error" :loading="acting" @click="doReject">{{ t('pages.audit.reject') }}</n-button>
|
|
</div>
|
|
</template>
|
|
</n-modal>
|
|
</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, EyeOutline, CheckmarkCircleOutline, CloseCircleOutline } from '@vicons/ionicons5';
|
|
import { AuditStatus } from '@artveris/shared';
|
|
import { auditApi } from '@/api';
|
|
import { message, dialog } from '@/utils/feedback';
|
|
import { fmt } from '@/utils/format';
|
|
import { useTablePage } from '@/composables/useTablePage';
|
|
import { renderTableFilterTitle } from '@/utils/tableFilter';
|
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
|
import { useRemoteSort } from '@/utils/tableSort';
|
|
|
|
const { t } = useI18n();
|
|
const router = useRouter();
|
|
|
|
const rows = ref<any[]>([]);
|
|
const loading = ref(false);
|
|
const acting = ref(false);
|
|
const query = reactive<{ keyword: string; auditStatus: string | null }>({
|
|
keyword: '',
|
|
auditStatus: AuditStatus.PENDING,
|
|
});
|
|
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load);
|
|
const { sortProps, onSorterChange, sortParams } = useRemoteSort(onSearch);
|
|
const auditStatusOptions = Object.values(AuditStatus).map((v) => ({ label: t(`common.auditStatus.${v}`), value: v }));
|
|
|
|
function auditTagType(s: string) {
|
|
return s === 'APPROVED' ? 'success' : s === 'REJECTED' ? 'error' : 'warning';
|
|
}
|
|
|
|
const rejectModal = ref(false);
|
|
const rejectRemark = ref('');
|
|
const rejectId = ref<number | null>(null);
|
|
|
|
const columns: DataTableColumns<any> = [
|
|
{
|
|
title: () => t('pages.artwork.images'),
|
|
key: 'cover',
|
|
width: 70,
|
|
align: 'center',
|
|
render: (r) =>
|
|
r.images?.[0]?.url
|
|
? h(NAvatar, {
|
|
src: r.images[0].url,
|
|
size: 40,
|
|
style: 'border-radius:8px;cursor:zoom-in',
|
|
onClick: () => previewArtworkImages(r.images),
|
|
})
|
|
: h(NAvatar, { size: 40, 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('common.action.detail'), onClick: () => goDetail(r) },
|
|
{ default: () => r.archiveNo || '-' },
|
|
),
|
|
},
|
|
{
|
|
title: () => t('pages.artwork.title'),
|
|
key: 'title',
|
|
minWidth: 240,
|
|
ellipsis: { tooltip: true },
|
|
render: (r) =>
|
|
h(
|
|
NButton,
|
|
{ text: true, type: 'primary', title: t('common.action.detail'), onClick: () => goDetail(r) },
|
|
{ default: () => r.title },
|
|
),
|
|
},
|
|
{ title: () => t('pages.artwork.artist'), key: 'artist', minWidth: 140, ellipsis: { tooltip: true }, render: (r) => r.artist || '-' },
|
|
{ title: () => t('pages.artwork.changeTitle'), key: 'revisionTitle', minWidth: 150, ellipsis: { tooltip: true }, render: (r) => r.revisionTitle || '-' },
|
|
{ title: () => t('pages.artwork.changeReason'), key: 'revisionReason', minWidth: 220, ellipsis: { tooltip: true }, render: (r) => r.revisionReason || '-' },
|
|
{
|
|
title: () => renderTableFilterTitle(t('pages.audit.status'), query.auditStatus, auditStatusOptions, (value) => setAuditFilter(value)),
|
|
key: 'auditStatus',
|
|
width: 130,
|
|
align: 'center',
|
|
render: (r) => h(NTag, { size: 'small', type: auditTagType(r.auditStatus) }, { default: () => t(`common.auditStatus.${r.auditStatus}`) }),
|
|
},
|
|
{ title: () => t('pages.artwork.submitter'), key: 'submittedBy', width: 130, align: 'center', ellipsis: { tooltip: true }, render: (r) => r.submittedBy?.realName || r.submittedBy?.username || '-' },
|
|
{ title: () => t('pages.artwork.submittedAt'), key: 'submittedAt', width: 160, align: 'center', render: (r) => fmt(r.submittedAt) },
|
|
{ title: () => t('pages.audit.remark'), key: 'auditRemark', minWidth: 200, ellipsis: { tooltip: true }, render: (r) => r.auditRemark || '-' },
|
|
{ title: () => t('common.label.updatedAt'), key: 'updatedAt', width: 160, align: 'center', render: (r) => fmt(r.updatedAt), ...sortProps('updatedAt') },
|
|
{
|
|
title: () => t('common.label.operation'),
|
|
key: 'ops',
|
|
width: 150,
|
|
fixed: 'right',
|
|
align: 'center',
|
|
render: (r) =>
|
|
h('div', { class: 'row-actions' }, [
|
|
h(NButton, { quaternary: true, circle: true, size: 'small', title: t('common.action.detail'), onClick: () => goDetail(r) }, { icon: () => h(NIcon, null, { default: () => h(EyeOutline) }) }),
|
|
h(NButton, { quaternary: true, circle: true, size: 'small', type: 'success', title: t('pages.audit.approve'), disabled: r.auditStatus === 'APPROVED', onClick: () => approve(r) }, { icon: () => h(NIcon, null, { default: () => h(CheckmarkCircleOutline) }) }),
|
|
h(NButton, { quaternary: true, circle: true, size: 'small', type: 'error', title: t('pages.audit.reject'), disabled: r.auditStatus === 'REJECTED', onClick: () => openReject(r) }, { icon: () => h(NIcon, null, { default: () => h(CloseCircleOutline) }) }),
|
|
]),
|
|
},
|
|
];
|
|
|
|
async function load() {
|
|
loading.value = true;
|
|
try {
|
|
const res: any = await auditApi.list({
|
|
keyword: query.keyword || undefined,
|
|
status: 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 previewArtworkImages(images: any[]) {
|
|
void openMediaViewer(
|
|
(images || []).map((item) => ({ url: item.url || item.key, name: item.name || item.key, type: item.type || 'image' })),
|
|
0,
|
|
);
|
|
}
|
|
function goDetail(r: any) {
|
|
router.push(`/artworks/${r.id}${r.revisionId ? `?revisionId=${r.revisionId}` : ''}`);
|
|
}
|
|
function setAuditFilter(value: string | number | null) {
|
|
query.auditStatus = value ? String(value) : null;
|
|
onSearch();
|
|
}
|
|
function approve(r: any) {
|
|
dialog.success({
|
|
title: t('pages.audit.approve'),
|
|
content: t('pages.audit.approveConfirm', { title: r.title }),
|
|
positiveText: t('common.action.confirm'),
|
|
negativeText: t('common.action.cancel'),
|
|
onPositiveClick: async () => {
|
|
await auditApi.audit(r.id, { approved: true, revisionId: r.revisionId });
|
|
message.success(t('pages.audit.approved'));
|
|
load();
|
|
},
|
|
});
|
|
}
|
|
function openReject(r: any) {
|
|
rejectId.value = r.id;
|
|
rejectRemark.value = '';
|
|
rejectModal.value = true;
|
|
}
|
|
async function doReject() {
|
|
if (rejectId.value === null) return;
|
|
acting.value = true;
|
|
try {
|
|
const row = rows.value.find((item) => item.id === rejectId.value);
|
|
await auditApi.audit(rejectId.value, { approved: false, remark: rejectRemark.value, revisionId: row?.revisionId });
|
|
message.success(t('pages.audit.rejected'));
|
|
rejectModal.value = false;
|
|
load();
|
|
} finally {
|
|
acting.value = false;
|
|
}
|
|
}
|
|
|
|
onMounted(load);
|
|
</script>
|
|
|
|
<style scoped>
|
|
.mr8 {
|
|
margin-right: 8px;
|
|
}
|
|
</style>
|