feat: 完成 PRD 差距与修复,新增审核流与日志清理功能,支持出库信息与动态字段,优化 C 端用户体验
This commit is contained in:
@@ -41,6 +41,8 @@ export const artworkApi = {
|
||||
listCerts: (artworkId: number) => get<any[]>(`/artworks/${artworkId}/certificates`),
|
||||
createCert: (artworkId: number, data: object) => post(`/artworks/${artworkId}/certificates`, data),
|
||||
removeCert: (id: number) => del(`/certificates/${id}`),
|
||||
// audit
|
||||
audit: (id: number, data: { approved: boolean; remark?: string }) => post(`/artworks/${id}/audit`, data),
|
||||
};
|
||||
|
||||
export const traceCodeApi = {
|
||||
@@ -70,6 +72,11 @@ export const outboundApi = {
|
||||
templateUrl: '/api/outbound/import/template',
|
||||
};
|
||||
|
||||
export const auditApi = {
|
||||
list: (params: object) => get<PageResult<any>>('/artworks', params),
|
||||
audit: (id: number, data: { approved: boolean; remark?: string }) => post(`/artworks/${id}/audit`, data),
|
||||
};
|
||||
|
||||
export const jobApi = {
|
||||
get: (id: string) => get(`/jobs/${id}`),
|
||||
list: (params: object) => get<PageResult<any>>('/jobs', params),
|
||||
|
||||
@@ -67,6 +67,7 @@ import {
|
||||
PersonCircleOutline,
|
||||
LogOutOutline,
|
||||
KeyOutline,
|
||||
ShieldCheckmarkOutline,
|
||||
} from '@vicons/ionicons5';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { settingsApi } from '@/api';
|
||||
@@ -87,17 +88,20 @@ function renderIcon(icon: unknown) {
|
||||
}
|
||||
|
||||
const menuOptions = computed<MenuOption[]>(() => {
|
||||
const items: Array<MenuOption & { superOnly?: boolean }> = [
|
||||
const items: Array<MenuOption & { superOnly?: boolean; auditOnly?: boolean }> = [
|
||||
{ label: t('menu.dashboard'), key: 'dashboard', icon: renderIcon(GridOutline) },
|
||||
{ label: t('menu.templates'), key: 'templates', icon: renderIcon(DocumentTextOutline) },
|
||||
{ label: t('menu.artworks'), key: 'artworks', icon: renderIcon(ImagesOutline) },
|
||||
{ label: t('menu.traceCodes'), key: 'traceCodes', icon: renderIcon(QrCodeOutline) },
|
||||
{ label: t('menu.outbound'), key: 'outbound', icon: renderIcon(CubeOutline) },
|
||||
{ label: t('menu.audit'), key: 'audit', icon: renderIcon(ShieldCheckmarkOutline), auditOnly: true },
|
||||
{ label: t('menu.queryLogs'), key: 'queryLogs', icon: renderIcon(ListOutline) },
|
||||
{ label: t('menu.users'), key: 'users', icon: renderIcon(PeopleOutline), superOnly: true },
|
||||
{ label: t('menu.settings'), key: 'settings', icon: renderIcon(SettingsOutline), superOnly: true },
|
||||
];
|
||||
return items.filter((i) => !i.superOnly || auth.isSuperAdmin);
|
||||
return items.filter(
|
||||
(i) => (!i.superOnly || auth.isSuperAdmin) && (!i.auditOnly || auth.canAudit),
|
||||
);
|
||||
});
|
||||
|
||||
const activeKey = computed(() => (route.name === 'artwork-detail' ? 'artworks' : (route.name as string)));
|
||||
|
||||
@@ -74,6 +74,11 @@
|
||||
"DISABLED": "Disabled",
|
||||
"ABNORMAL": "Abnormal"
|
||||
},
|
||||
"auditStatus": {
|
||||
"PENDING": "Pending",
|
||||
"APPROVED": "Approved",
|
||||
"REJECTED": "Rejected"
|
||||
},
|
||||
"fieldType": {
|
||||
"TEXT": "Text",
|
||||
"NUMBER": "Number",
|
||||
@@ -117,6 +122,7 @@
|
||||
"artworks": "Artworks",
|
||||
"traceCodes": "Trace Codes",
|
||||
"outbound": "Outbound & Chain",
|
||||
"audit": "Content Audit",
|
||||
"queryLogs": "Query Logs",
|
||||
"users": "Users",
|
||||
"settings": "Settings",
|
||||
@@ -158,7 +164,20 @@
|
||||
"create": "New Template",
|
||||
"edit": "Edit Template",
|
||||
"namePlaceholder": "Enter template name",
|
||||
"fieldKeyTip": "Unique key, e.g. craft"
|
||||
"fieldKeyTip": "Unique key, e.g. craft",
|
||||
"sortHint": "Field order = display order on consumer page; use arrows to reorder"
|
||||
},
|
||||
"audit": {
|
||||
"status": "Audit Status",
|
||||
"approve": "Approve",
|
||||
"reject": "Reject",
|
||||
"approved": "Approved",
|
||||
"rejected": "Rejected",
|
||||
"remark": "Audit Note",
|
||||
"remarkPlaceholder": "Enter rejection reason or suggestions",
|
||||
"approveConfirm": "Approve \"{title}\"? It will become visible on the consumer page.",
|
||||
"rejectedTip": "This artwork was rejected. Please revise per the notes, save and resubmit for audit.",
|
||||
"pendingTip": "Pending audit; visible on consumer page only after approval. Saving edits re-enters pending."
|
||||
},
|
||||
"artwork": {
|
||||
"title": "Title",
|
||||
@@ -202,6 +221,7 @@
|
||||
"shortCode": "Short Code",
|
||||
"code": "Trace Code",
|
||||
"url": "Short URL",
|
||||
"archiveNo": "Archive No.",
|
||||
"queryCount": "Queries",
|
||||
"firstActivatedAt": "First Activated",
|
||||
"exportBatch": "Export Batch",
|
||||
@@ -231,13 +251,18 @@
|
||||
"sku": "SKU",
|
||||
"archiveNo": "Archive No.",
|
||||
"outTime": "Outbound Time",
|
||||
"outImage": "Outbound Photo",
|
||||
"selectCode": "Select Trace Code",
|
||||
"selectCodePlaceholder": "Search by short code / SKU / archive no.",
|
||||
"onchainSection": "On-chain info (optional; filling a hash records the result)",
|
||||
"txHashTip": "Paste the on-chain transaction/attestation hash",
|
||||
"selectFile": "Select File",
|
||||
"importing": "Importing…",
|
||||
"importResult": "Import Result",
|
||||
"successCount": "Success",
|
||||
"failCount": "Failed",
|
||||
"downloadResult": "Download Details",
|
||||
"tip": "Download the template first, fill it in and upload (xlsx)"
|
||||
"tip": "Download the template first, fill it in and upload (xlsx). Includes outbound photo, on-chain hash/time/block height."
|
||||
},
|
||||
"blockchain": {
|
||||
"title": "Blockchain Attestation",
|
||||
@@ -255,7 +280,8 @@
|
||||
"device": "Device",
|
||||
"queriedAt": "Time",
|
||||
"startTime": "Start",
|
||||
"endTime": "End"
|
||||
"endTime": "End",
|
||||
"keywordPlaceholder": "Short code / trace code / SKU / archive no."
|
||||
},
|
||||
"user": {
|
||||
"username": "Username",
|
||||
|
||||
@@ -74,6 +74,11 @@
|
||||
"DISABLED": "停用",
|
||||
"ABNORMAL": "异常"
|
||||
},
|
||||
"auditStatus": {
|
||||
"PENDING": "待审核",
|
||||
"APPROVED": "已通过",
|
||||
"REJECTED": "已驳回"
|
||||
},
|
||||
"fieldType": {
|
||||
"TEXT": "文本",
|
||||
"NUMBER": "数字",
|
||||
@@ -117,6 +122,7 @@
|
||||
"artworks": "艺术品建档",
|
||||
"traceCodes": "追溯码管理",
|
||||
"outbound": "出库与上链",
|
||||
"audit": "内容审核",
|
||||
"queryLogs": "查询日志",
|
||||
"users": "用户管理",
|
||||
"settings": "系统设置",
|
||||
@@ -158,7 +164,20 @@
|
||||
"create": "新建模板",
|
||||
"edit": "编辑模板",
|
||||
"namePlaceholder": "请输入模板名称",
|
||||
"fieldKeyTip": "英文唯一标识,如 craft"
|
||||
"fieldKeyTip": "英文唯一标识,如 craft",
|
||||
"sortHint": "字段顺序即 C 端展示顺序,可用上下箭头调整"
|
||||
},
|
||||
"audit": {
|
||||
"status": "审核状态",
|
||||
"approve": "通过",
|
||||
"reject": "驳回",
|
||||
"approved": "已通过审核",
|
||||
"rejected": "已驳回",
|
||||
"remark": "审核意见",
|
||||
"remarkPlaceholder": "请填写驳回原因或修改建议",
|
||||
"approveConfirm": "确认通过《{title}》的审核?通过后将对 C 端可见。",
|
||||
"rejectedTip": "该作品审核未通过,请按意见修改后保存再次提交审核",
|
||||
"pendingTip": "该作品待审核,审核通过后方可在 C 端展示;保存修改会重新进入待审核"
|
||||
},
|
||||
"artwork": {
|
||||
"title": "作品名称",
|
||||
@@ -202,6 +221,7 @@
|
||||
"shortCode": "短码",
|
||||
"code": "追溯码",
|
||||
"url": "短链",
|
||||
"archiveNo": "档案编号",
|
||||
"queryCount": "查询次数",
|
||||
"firstActivatedAt": "首次激活时间",
|
||||
"exportBatch": "导出本批",
|
||||
@@ -231,13 +251,18 @@
|
||||
"sku": "SKU",
|
||||
"archiveNo": "档案编号",
|
||||
"outTime": "出库时间",
|
||||
"outImage": "出库实况图",
|
||||
"selectCode": "选择追溯码",
|
||||
"selectCodePlaceholder": "输入短码 / SKU / 档案号搜索",
|
||||
"onchainSection": "上链信息(选填,填写哈希即登记上链结果)",
|
||||
"txHashTip": "粘贴链上交易/存证哈希",
|
||||
"selectFile": "选择文件",
|
||||
"importing": "导入中…",
|
||||
"importResult": "导入结果",
|
||||
"successCount": "成功",
|
||||
"failCount": "失败",
|
||||
"downloadResult": "下载结果明细",
|
||||
"tip": "请先下载模板,按模板填写后上传(支持 xlsx)"
|
||||
"tip": "请先下载模板,按模板填写后上传(支持 xlsx)。模板含出库实况图、上链哈希/时间/区块高度等字段。"
|
||||
},
|
||||
"blockchain": {
|
||||
"title": "区块链存证",
|
||||
@@ -255,7 +280,8 @@
|
||||
"device": "设备信息",
|
||||
"queriedAt": "查询时间",
|
||||
"startTime": "开始时间",
|
||||
"endTime": "结束时间"
|
||||
"endTime": "结束时间",
|
||||
"keywordPlaceholder": "短码 / 追溯码 / SKU / 档案号"
|
||||
},
|
||||
"user": {
|
||||
"username": "用户名",
|
||||
|
||||
@@ -21,9 +21,10 @@ export const routes: RouteRecordRaw[] = [
|
||||
{ path: 'artworks/:id', name: 'artwork-detail', component: () => import('@/views/ArtworkEdit.vue') },
|
||||
{ path: 'trace-codes', name: 'traceCodes', component: () => import('@/views/TraceCodes.vue') },
|
||||
{ path: 'outbound', name: 'outbound', component: () => import('@/views/Outbound.vue') },
|
||||
{ path: 'audit', name: 'audit', component: () => import('@/views/Audit.vue'), meta: { roles: ['SUPER_ADMIN', 'AUDITOR'] } },
|
||||
{ path: 'query-logs', name: 'queryLogs', component: () => import('@/views/QueryLogs.vue') },
|
||||
{ path: 'users', name: 'users', component: () => import('@/views/Users.vue') },
|
||||
{ path: 'settings', name: 'settings', component: () => import('@/views/Settings.vue') },
|
||||
{ path: 'users', name: 'users', component: () => import('@/views/Users.vue'), meta: { roles: ['SUPER_ADMIN'] } },
|
||||
{ path: 'settings', name: 'settings', component: () => import('@/views/Settings.vue'), meta: { roles: ['SUPER_ADMIN'] } },
|
||||
{ path: 'profile', name: 'profile', component: () => import('@/views/Profile.vue') },
|
||||
],
|
||||
},
|
||||
@@ -53,6 +54,11 @@ router.beforeEach(async (to) => {
|
||||
return { name: 'login' };
|
||||
}
|
||||
}
|
||||
// 角色守卫:受限路由仅允许指定角色访问,越权回看板
|
||||
const roles = to.meta.roles as string[] | undefined;
|
||||
if (roles && roles.length && !roles.includes(auth.role)) {
|
||||
return { name: 'dashboard' };
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ export const useAuthStore = defineStore('auth', {
|
||||
isLoggedIn: (state) => !!state.token,
|
||||
isSuperAdmin: (state) => state.user?.role === 'SUPER_ADMIN',
|
||||
canWrite: (state) => state.user?.role === 'SUPER_ADMIN' || state.user?.role === 'OPERATOR',
|
||||
canAudit: (state) => state.user?.role === 'SUPER_ADMIN' || state.user?.role === 'AUDITOR',
|
||||
isViewer: (state) => state.user?.role === 'VIEWER',
|
||||
role: (state) => state.user?.role || '',
|
||||
},
|
||||
actions: {
|
||||
async login(username: string, password: string) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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>
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user