feat: 完成 PRD 差距与修复,新增审核流与日志清理功能,支持出库信息与动态字段,优化 C 端用户体验

This commit is contained in:
Nixevol
2026-06-29 23:41:39 +08:00
parent d18b7c592d
commit 2fba42c9fd
39 changed files with 1247 additions and 185 deletions
+60 -1
View File
@@ -12,6 +12,27 @@
<!-- 基础信息 -->
<n-grid-item>
<n-card :title="t('pages.artwork.basicInfo')" :bordered="false">
<template v-if="!isNew" #header-extra>
<n-tag :type="auditTagType(artwork?.auditStatus)" size="small">
{{ t('pages.audit.status') }}:{{ t(`common.auditStatus.${artwork?.auditStatus || 'PENDING'}`) }}
</n-tag>
</template>
<n-alert
v-if="!isNew && artwork?.auditStatus === 'REJECTED'"
type="error"
:show-icon="true"
style="margin-bottom: 12px"
>
{{ t('pages.audit.rejectedTip') }}{{ artwork?.auditRemark ? ':' + artwork.auditRemark : '' }}
</n-alert>
<n-alert
v-else-if="!isNew && artwork?.auditStatus === 'PENDING'"
type="info"
:show-icon="true"
style="margin-bottom: 12px"
>
{{ t('pages.audit.pendingTip') }}
</n-alert>
<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')">
@@ -35,12 +56,18 @@
<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-form-item-gi
v-for="f in currentFields"
:key="f.fieldKey"
span="2 m:1"
:label="f.required ? `${f.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"
clearable
style="width: 100%"
/>
<n-input
@@ -49,6 +76,30 @@
type="textarea"
:rows="2"
/>
<n-input-number
v-else-if="f.type === 'NUMBER'"
v-model:value="form.dynamicFields[f.fieldKey]"
style="width: 100%"
/>
<n-input
v-else-if="f.type === 'LINK'"
v-model:value="form.dynamicFields[f.fieldKey]"
placeholder="https://"
/>
<media-upload
v-else-if="f.type === 'IMAGE'"
:model-value="toMedia(form.dynamicFields[f.fieldKey])"
type="image"
:max="1"
@update:model-value="(v) => (form.dynamicFields[f.fieldKey] = v[0]?.url || '')"
/>
<media-upload
v-else-if="f.type === 'FILE'"
:model-value="toMedia(form.dynamicFields[f.fieldKey])"
type="file"
:max="1"
@update:model-value="(v) => (form.dynamicFields[f.fieldKey] = v[0]?.url || '')"
/>
<n-input v-else v-model:value="form.dynamicFields[f.fieldKey]" />
</n-form-item-gi>
</n-grid>
@@ -299,6 +350,14 @@ function onTemplateChange() {
form.dynamicFields = {};
}
// 动态字段 IMAGE/FILE 适配:dynamicFields 存 url 字符串,MediaUpload 需要 MediaItem[]
function toMedia(url: unknown) {
return url ? [{ key: String(url), url: String(url), name: String(url) }] : [];
}
function auditTagType(s?: string) {
return s === 'APPROVED' ? 'success' : s === 'REJECTED' ? 'error' : 'warning';
}
async function loadTemplates() {
templates.value = await templateApi.options();
}
+13 -2
View File
@@ -90,10 +90,21 @@ const columns: DataTableColumns<any> = [
{
title: () => t('common.label.status'),
key: 'status',
width: 90,
width: 84,
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('pages.audit.status'),
key: 'auditStatus',
width: 90,
render: (r) =>
h(
NTag,
{ size: 'small', type: r.auditStatus === 'APPROVED' ? 'success' : r.auditStatus === 'REJECTED' ? 'error' : 'warning' },
{ default: () => t(`common.auditStatus.${r.auditStatus || 'PENDING'}`) },
),
},
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 150, render: (r) => fmt(r.createdAt) },
{
title: () => t('common.label.operation'),
key: 'ops',
+180
View File
@@ -0,0 +1,180 @@
<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.auditStatus"
:options="auditStatusOptions"
clearable
:placeholder="t('pages.audit.status')"
style="width: 150px"
@update:value="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="pagination"
remote
:row-key="(r) => r.id"
@update:page="onPage"
/>
<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';
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; page: number; pageSize: number }>({
keyword: '',
auditStatus: AuditStatus.PENDING,
page: 1,
pageSize: 10,
});
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
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,
render: (r) =>
r.images?.[0]?.url
? h(NAvatar, { src: r.images[0].url, size: 40, style: 'border-radius:8px' })
: h(NAvatar, { size: 40, style: 'border-radius:8px' }, { default: () => '—' }),
},
{ title: () => t('pages.artwork.title'), key: 'title', ellipsis: { tooltip: true } },
{ title: () => t('pages.artwork.artist'), key: 'artist', width: 110, render: (r) => r.artist || '-' },
{
title: () => t('pages.audit.status'),
key: 'auditStatus',
width: 100,
render: (r) => h(NTag, { size: 'small', type: auditTagType(r.auditStatus) }, { default: () => t(`common.auditStatus.${r.auditStatus}`) }),
},
{ title: () => t('pages.audit.remark'), key: 'auditRemark', ellipsis: { tooltip: true }, render: (r) => r.auditRemark || '-' },
{ title: () => t('common.label.updatedAt'), key: 'updatedAt', width: 160, render: (r) => fmt(r.updatedAt) },
{
title: () => t('common.label.operation'),
key: 'ops',
width: 150,
render: (r) =>
h('div', { style: 'display:flex;gap:2px' }, [
h(NButton, { quaternary: true, circle: true, size: 'small', title: t('common.action.detail'), onClick: () => router.push(`/artworks/${r.id}`) }, { 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,
auditStatus: query.auditStatus || 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 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 });
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 {
await auditApi.audit(rejectId.value, { approved: false, remark: rejectRemark.value });
message.success(t('pages.audit.rejected'));
rejectModal.value = false;
load();
} finally {
acting.value = false;
}
}
onMounted(load);
</script>
<style scoped>
.mr8 {
margin-right: 8px;
}
</style>
+159 -38
View File
@@ -1,65 +1,186 @@
<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 :bordered="false">
<n-tabs type="line" animated>
<!-- 单条录入 -->
<n-tab-pane name="single" :tab="t('pages.outbound.single')">
<n-form label-placement="top" style="max-width: 560px">
<n-form-item :label="t('pages.outbound.selectCode')" required>
<n-select
v-model:value="form.traceCodeId"
filterable
remote
clearable
:loading="searching"
:options="codeOptions"
:placeholder="t('pages.outbound.selectCodePlaceholder')"
@search="searchCodes"
@update:value="onPickCode"
/>
</n-form-item>
<n-grid :cols="2" :x-gap="16">
<n-form-item-gi :label="t('pages.outbound.sku')">
<n-input v-model:value="form.sku" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.outbound.archiveNo')">
<n-input v-model:value="form.archiveNo" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.outbound.outTime')">
<n-date-picker v-model:formatted-value="form.outTime" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
</n-form-item-gi>
<n-form-item-gi :label="t('common.label.remark')">
<n-input v-model:value="form.remark" />
</n-form-item-gi>
</n-grid>
<n-form-item :label="t('pages.outbound.outImage')">
<media-upload v-model="outImages" type="image" :max="1" />
</n-form-item>
<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-divider style="margin: 4px 0 14px">{{ t('pages.outbound.onchainSection') }}</n-divider>
<n-grid :cols="2" :x-gap="16">
<n-form-item-gi span="2" :label="t('pages.blockchain.txHash')">
<n-input v-model:value="form.txHash" :placeholder="t('pages.outbound.txHashTip')" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.blockchain.onchainAt')">
<n-date-picker v-model:formatted-value="form.onchainAt" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.blockchain.blockHeight')">
<n-input-number v-model:value="form.blockHeight" :min="0" style="width: 100%" />
</n-form-item-gi>
</n-grid>
<n-button type="primary" :loading="saving" :disabled="!auth.canWrite || !form.traceCodeId" @click="saveSingle">
{{ t('common.action.save') }}
</n-button>
</n-form>
</n-tab-pane>
<!-- 批量导入 -->
<n-tab-pane name="import" :tab="t('pages.outbound.import')">
<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', { n: result.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-tab-pane>
</n-tabs>
</n-card>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { reactive, 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 { jobApi, outboundApi, traceCodeApi, post } from '@/api';
import { useAuthStore } from '@/stores/auth';
import MediaUpload from '@/components/MediaUpload.vue';
import { message } from '@/utils/feedback';
import { statusType } from '@/utils/format';
import { downloadFile } from '@/utils/download';
const { t } = useI18n();
const auth = useAuthStore();
/* 单条录入 */
const saving = ref(false);
const searching = ref(false);
const codeOptions = ref<{ label: string; value: string }[]>([]);
const outImages = ref<any[]>([]);
const form = reactive<any>({
traceCodeId: null,
sku: '',
archiveNo: '',
outTime: null,
remark: '',
txHash: '',
onchainAt: null,
blockHeight: null,
});
let searchTimer: ReturnType<typeof setTimeout> | null = null;
function searchCodes(keyword: string) {
if (searchTimer) clearTimeout(searchTimer);
searchTimer = setTimeout(async () => {
searching.value = true;
try {
const res: any = await traceCodeApi.list({ keyword: keyword || undefined, pageSize: 20 });
codeOptions.value = res.list.map((c: any) => ({
label: `${c.shortCode}${c.artwork ? ' · ' + c.artwork.title : ''}${c.sku ? ' · ' + c.sku : ''}`,
value: String(c.id),
raw: c,
}));
} finally {
searching.value = false;
}
}, 300);
}
function onPickCode(_id: string, opt: any) {
const c = opt?.raw;
if (!c) return;
form.sku = c.sku || '';
form.archiveNo = c.archiveNo || '';
form.remark = c.remark || '';
outImages.value = c.outImage ? [{ key: c.outImage, url: c.outImage, name: c.outImage }] : [];
}
async function saveSingle() {
if (!form.traceCodeId) return;
saving.value = true;
try {
await outboundApi.updateSingle(form.traceCodeId, {
sku: form.sku || undefined,
archiveNo: form.archiveNo || undefined,
outTime: form.outTime ? new Date(form.outTime).toISOString() : undefined,
outImageKey: outImages.value[0]?.key || undefined,
txHash: form.txHash || undefined,
onchainAt: form.onchainAt ? new Date(form.onchainAt).toISOString() : undefined,
blockHeight: form.blockHeight ?? undefined,
remark: form.remark || undefined,
});
message.success(t('common.msg.saved'));
} finally {
saving.value = false;
}
}
/* 批量导入 */
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;
+38 -10
View File
@@ -3,9 +3,23 @@
<div class="page-toolbar">
<n-input
v-model:value="query.keyword"
:placeholder="t('pages.traceCode.shortCode')"
:placeholder="t('pages.queryLog.keywordPlaceholder')"
clearable
style="width: 180px"
style="width: 200px"
@keyup.enter="onSearch"
/>
<n-input
v-model:value="query.sku"
placeholder="SKU"
clearable
style="width: 130px"
@keyup.enter="onSearch"
/>
<n-input
v-model:value="query.batchNo"
:placeholder="t('pages.traceCode.batchNo')"
clearable
style="width: 150px"
@keyup.enter="onSearch"
/>
<n-select
@@ -13,14 +27,14 @@
:options="resultOptions"
clearable
:placeholder="t('pages.queryLog.result')"
style="width: 150px"
style="width: 140px"
@update:value="onSearch"
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
clearable
style="width: 360px"
style="width: 340px"
@update:value="onRange"
/>
<n-button type="primary" @click="onSearch">
@@ -55,8 +69,10 @@ 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 }>({
const query = reactive<{ keyword: string; sku: string; batchNo: string; result: string | null; startTime?: string; endTime?: string; page: number; pageSize: number }>({
keyword: '',
sku: '',
batchNo: '',
result: null,
page: 1,
pageSize: 10,
@@ -65,21 +81,31 @@ 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.traceCode.shortCode'), key: 'shortCode', width: 120, render: (r) => r.shortCode || '-' },
{ title: 'SKU', key: 'sku', width: 120, render: (r) => r.sku || '-' },
{ title: () => t('pages.traceCode.archiveNo'), key: 'archiveNo', width: 110, render: (r) => r.archiveNo || '-' },
{ title: () => t('pages.traceCode.batchNo'), key: 'batchNo', width: 130, render: (r) => r.batchNo || '-' },
{
title: () => t('pages.queryLog.result'),
key: 'queryResult',
width: 110,
width: 104,
render: (r) => h(NTag, { size: 'small', type: statusType(r.queryResult) }, { default: () => t(`common.queryResult.${r.queryResult}`) }),
},
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 90, render: (r) => (r.queryCount ?? '-') },
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 160, render: (r) => fmt(r.firstActivatedAt) },
{
title: () => t('pages.queryLog.ip'),
key: 'ip',
width: 200,
width: 190,
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) },
{
title: () => t('pages.queryLog.device'),
key: 'deviceType',
width: 150,
render: (r) => [r.deviceType, r.os, r.browser].filter(Boolean).join(' / ') || '-',
},
{ title: () => t('pages.queryLog.queriedAt'), key: 'queriedAt', width: 160, render: (r) => fmt(r.queriedAt) },
];
async function load() {
@@ -87,6 +113,8 @@ async function load() {
try {
const res: any = await queryLogApi.list({
keyword: query.keyword || undefined,
sku: query.sku || undefined,
batchNo: query.batchNo || undefined,
result: query.result || undefined,
startTime: query.startTime,
endTime: query.endTime,
+82 -12
View File
@@ -42,16 +42,32 @@
<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 v-if="editing" :label="t('common.label.status')">
<n-switch v-model:value="form.status" :checked-value="'ENABLED'" :unchecked-value="'DISABLED'">
<template #checked>{{ t('common.status.ENABLED') }}</template>
<template #unchecked>{{ t('common.status.DISABLED') }}</template>
</n-switch>
</n-form-item>
<n-form-item :label="t('pages.template.fields')">
<div style="width: 100%">
<div class="field-hint">{{ t('pages.template.sortHint') }}</div>
<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" />
<span class="field-order">{{ i + 1 }}</span>
<n-input v-model:value="f.fieldKey" :placeholder="t('pages.template.fieldKeyTip')" style="width: 120px" />
<n-input v-model:value="f.label" :placeholder="t('pages.template.fieldLabel')" style="width: 110px" />
<n-select v-model:value="f.type" :options="fieldTypeOptions" style="width: 110px" />
<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>
<span class="field-ops">
<n-button quaternary circle size="small" :disabled="i === 0" @click="moveField(i, -1)">
<template #icon><n-icon :component="ArrowUpOutline" /></template>
</n-button>
<n-button quaternary circle size="small" :disabled="i === form.fields.length - 1" @click="moveField(i, 1)">
<template #icon><n-icon :component="ArrowDownOutline" /></template>
</n-button>
<n-button quaternary circle type="error" size="small" @click="form.fields.splice(i, 1)">
<template #icon><n-icon :component="TrashOutline" /></template>
</n-button>
</span>
</div>
<n-button dashed block @click="addField">
<template #icon><n-icon :component="AddOutline" /></template>
@@ -74,8 +90,16 @@
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 {
SearchOutline,
AddOutline,
TrashOutline,
CreateOutline,
ArrowUpOutline,
ArrowDownOutline,
PowerOutline,
} from '@vicons/ionicons5';
import { FieldType, TemplateStatus } from '@artveris/shared';
import { templateApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import { message, dialog } from '@/utils/feedback';
@@ -95,7 +119,7 @@ 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 form = reactive<{ name: string; remark: string; status: string; fields: any[] }>({ name: '', remark: '', status: 'ENABLED', fields: [] });
const rules: FormRules = { name: { required: true, message: () => t('pages.template.namePlaceholder'), trigger: 'blur' } };
const columns: DataTableColumns<any> = [
@@ -123,12 +147,24 @@ const columns: DataTableColumns<any> = [
? h('div', { style: 'display:flex;gap:4px' }, [
h(
NButton,
{ quaternary: true, circle: true, size: 'small', onClick: () => openEdit(r) },
{ quaternary: true, circle: true, size: 'small', title: t('common.action.edit'), onClick: () => openEdit(r) },
{ icon: () => h(NIcon, null, { default: () => h(CreateOutline) }) },
),
h(
NButton,
{ quaternary: true, circle: true, size: 'small', type: 'error', onClick: () => remove(r) },
{
quaternary: true,
circle: true,
size: 'small',
title: r.status === 'ENABLED' ? t('common.status.DISABLED') : t('common.status.ENABLED'),
type: r.status === 'ENABLED' ? 'warning' : 'success',
onClick: () => toggleStatus(r),
},
{ icon: () => h(NIcon, null, { default: () => h(PowerOutline) }) },
),
h(
NButton,
{ quaternary: true, circle: true, size: 'small', type: 'error', title: t('common.action.delete'), onClick: () => remove(r) },
{ icon: () => h(NIcon, null, { default: () => h(TrashOutline) }) },
),
])
@@ -136,6 +172,13 @@ const columns: DataTableColumns<any> = [
},
];
async function toggleStatus(r: any) {
const next = r.status === TemplateStatus.ENABLED ? TemplateStatus.DISABLED : TemplateStatus.ENABLED;
await templateApi.update(r.id, { status: next });
message.success(t('common.msg.updated'));
load();
}
async function load() {
loading.value = true;
try {
@@ -156,10 +199,17 @@ function onPage(p: number) {
function addField() {
form.fields.push({ fieldKey: '', label: '', type: FieldType.TEXT, required: false });
}
function moveField(i: number, dir: -1 | 1) {
const j = i + dir;
if (j < 0 || j >= form.fields.length) return;
const arr = form.fields;
[arr[i], arr[j]] = [arr[j], arr[i]];
}
function openCreate() {
editing.value = null;
form.name = '';
form.remark = '';
form.status = 'ENABLED';
form.fields = [{ fieldKey: '', label: '', type: FieldType.TEXT, required: false }];
showModal.value = true;
}
@@ -167,6 +217,7 @@ function openEdit(r: any) {
editing.value = r.id;
form.name = r.name;
form.remark = r.remark || '';
form.status = r.status || 'ENABLED';
form.fields = (r.fields || []).map((f: any) => ({ ...f }));
showModal.value = true;
}
@@ -182,7 +233,10 @@ async function save() {
}
saving.value = true;
try {
const payload = { name: form.name, remark: form.remark, fields: form.fields };
// 排序:按当前顺序写 sortOrder
const fields = form.fields.map((f, i) => ({ ...f, sortOrder: i }));
const payload: any = { name: form.name, remark: form.remark, fields };
if (editing.value) payload.status = form.status;
if (editing.value) {
await templateApi.update(editing.value, payload);
message.success(t('common.msg.updated'));
@@ -220,6 +274,22 @@ onMounted(load);
gap: 8px;
margin-bottom: 8px;
}
.field-order {
width: 18px;
text-align: center;
color: #9ca3af;
font-size: 12px;
flex-shrink: 0;
}
.field-ops {
display: inline-flex;
gap: 2px;
}
.field-hint {
font-size: 12px;
color: #9ca3af;
margin-bottom: 8px;
}
.mr8 {
margin-right: 8px;
}