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
+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;
}