Become a sponsor

前端基于 Vue3 + NaiveUI + 自定义组件库构建。页面统一使用 n-card + BasicForm + BasicTable + TableAction 组件组合,分页由 BasicTable 内置处理,无需单独引入分页组件。
技术栈
<script setup>)ui/src/
├── api/ # API 接口定义
│ ├── data/ # 数据模块 API(param、dict、config、notice 等)
│ │ ├── param.ts
│ │ ├── dictionary.ts
│ │ └── ...
│ ├── system/ # 系统模块 API(user、role、dept、position、level)
│ │ ├── user.ts
│ │ ├── role.ts
│ │ └── ...
│ ├── content/ # 内容模块 API(article、category)
│ ├── common/ # 公共 API(city、upload、dict 按编码查询)
│ └── monitor/ # 监控模块 API(job、loginLog、operLog)
├── components/ # 公共组件(详见组件库文档)
├── views/ # 页面视图(按模块分目录)
│ ├── data/
│ │ ├── param/ # 参数管理
│ │ │ ├── index.vue # 列表页
│ │ │ ├── edit.vue # 编辑弹窗
│ │ │ ├── columns.ts # 表格列定义
│ │ │ └── querySchemas.ts # 搜索表单配置
│ │ ├── dict/
│ │ └── config/
│ ├── system/
│ │ ├── user/
│ │ ├── role/
│ │ ├── dept/
│ │ ├── position/
│ │ └── level/
│ ├── content/
│ │ ├── article/
│ │ └── category/
│ └── monitor/
│ ├── job/
│ ├── loginLog/
│ └── operLog/
├── store/ # Pinia 状态管理
├── router/ # 路由配置
├── utils/ # 工具函数
├── hooks/ # 组合式函数
├── styles/ # 全局样式
├── plugins/ # 插件注册(NaiveUI、自定义组件、指令)
└── main.ts # 入口文件每个业务模块统一包含以下文件:
| 文件 | 说明 | 示例 |
|---|---|---|
index.vue | 列表页(搜索 + 表格 + 操作) | views/data/param/index.vue |
edit.vue | 编辑弹窗(新增/编辑共用) | views/data/param/edit.vue |
columns.ts | 表格列定义 | views/data/param/columns.ts |
querySchemas.ts | 搜索表单配置 | views/data/param/querySchemas.ts |
以参数管理(views/data/param/index.vue)为标准模板:
<template>
<div>
<!-- 搜索表单 -->
<n-card :bordered="false" class="pt-3 mb-3 proCard">
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset" />
</n-card>
<!-- 数据表格 -->
<n-card :bordered="false" class="proCard">
<BasicTable
:columns="columns"
:request="loadDataTable"
:row-key="(row) => row.id"
ref="basicTableRef"
:actionColumn="actionColumn"
@update:checked-row-keys="onCheckedRow"
:auto-scroll-x="true"
>
<template #tableTitle>
<n-space>
<n-button type="primary" @click="handleAdd" v-perm="['sys:param:add']">
<template #icon><n-icon><PlusOutlined /></n-icon></template>
添加参数
</n-button>
<n-button
type="error"
@click="handleDelete()"
:disabled="!rowKeys.length"
v-perm="['sys:param:batchDelete']"
>
<template #icon><n-icon><DeleteOutlined /></n-icon></template>
删除
</n-button>
</n-space>
</template>
</BasicTable>
</n-card>
<!-- 编辑弹窗 -->
<editDialog
ref="editModalRef"
v-if="editVisible"
:paramId="paramId"
v-model:visible="editVisible"
@success="reloadTable('noRefresh')"
/>
</div>
</template>注意
BasicTable 内置处理,无需引入 <pagination> 组件:request="loadDataTable" 自动管理分页参数(pageNo / pageSize)和 loading 状态tableRef.value.reload({ pageNo: 1 }) 用于搜索/刷新时重置到第一页// views/data/param/columns.ts
import { h } from 'vue';
import { NTag } from 'naive-ui';
export const columns = [
{ type: 'selection', width: 50, fixed: 'left' }, // 多选列
{ title: 'ID', key: 'id', width: 50 }, // 固定列
{ title: '参数名称', key: 'name', width: 200 },
{ title: '参数编码', key: 'code', width: 250 },
{ title: '参数值', key: 'value', width: 200 },
{
title: '参数类型',
key: 'type',
width: 100,
render(record) {
return h(NTag,
{ bordered: false, type: record.type == 0 ? 'info' : 'warning' },
{ default: () => (record.type == 0 ? '系统' : '业务') }
);
},
},
{
title: '状态',
key: 'status',
width: 100,
render(record) {
return h(NTag,
{ bordered: false, type: record.status == 1 ? 'success' : 'error' },
{ default: () => (record.status == 1 ? '正常' : '禁用') }
);
},
},
{ title: '创建时间', key: 'createTime', width: 180 },
];// 状态标签
render(record) {
return h(NTag,
{ bordered: false, type: record.status == 1 ? 'success' : 'error' },
{ default: () => record.statusText } // 使用后端 serialize_maps 返回的 xxxText
);
}
// 链接
render(record) {
return h('a',
{ href: record.url, target: '_blank', class: 'text-blue-500' },
{ default: () => record.url }
);
}// views/data/param/querySchemas.ts
import { FormSchema } from '@/components/Form/index';
export const schemas: FormSchema[] = [
{
field: 'name',
component: 'NInput',
label: '参数名称',
componentProps: { placeholder: '请输入参数名称' },
},
{
field: 'type',
component: 'NSelect',
label: '参数类型',
componentProps: {
placeholder: '请选择参数类型',
clearable: true,
options: [
{ label: '系统', value: '0' },
{ label: '业务', value: '1' },
],
},
},
{
field: 'status',
component: 'NSelect',
label: '状态',
componentProps: {
placeholder: '请选择状态',
clearable: true,
options: [
{ label: '正常', value: '1' },
{ label: '禁用', value: '2' },
],
},
},
];import { FormOutlined, DeleteOutlined } from '@vicons/antd';
import { renderIcon } from '@/utils';
const actionColumn = reactive({
width: 200,
title: '操作',
align: 'center',
key: 'action',
fixed: 'right',
render(record) {
return h(TableAction as any, {
style: 'button',
actions: [
{
label: '编辑',
icon: renderIcon(FormOutlined),
type: 'info',
onClick: handleEdit.bind(null, record),
auth: ['sys:param:update'],
},
{
label: '删除',
icon: renderIcon(DeleteOutlined),
type: 'error',
onClick: handleDelete.bind(null, record),
auth: ['sys:param:delete'],
},
],
});
},
});// api/data/param.ts
import { http } from '@/utils/http/axios';
export function getParamList(params?) {
return http.request({ url: '/param/page', method: 'GET', params });
}
export function getParamDetail(id) {
return http.request({ url: '/param/detail/' + id, method: 'get' });
}
export function paramAdd(data: any) {
return http.request({ url: '/param/add', method: 'POST', data });
}
export function paramUpdate(data: any) {
return http.request({ url: '/param/update', method: 'PUT', data });
}
export function paramDelete(id) {
return http.request({ url: '/param/delete/' + id, method: 'DELETE' });
}
export function paramBatchDelete(data: any) {
return http.request({ url: '/param/batchDelete', method: 'DELETE', data });
}// 加载数据(BasicTable 的 :request 回调,自动传入分页参数)
const loadDataTable = async (res: any) => {
const result = await getParamList({ ...formParams, ...res });
return result; // 返回 { items, total } 或 R.ok(data=列表, count=总数)
};
// 刷新表格
function reloadTable(noRefresh = '') {
tableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
}
// 搜索提交
function handleSubmit(values: Recordable) {
handleReset();
for (const key in values) {
formParams[key] = values[key];
}
reloadTable(); // 重置到第一页
}
// 重置搜索
function handleReset() {
for (const key in formParams) {
formParams[key] = '';
}
}编辑弹窗使用 basicModal + useModal 模式,通过 v-model:visible 控制显示:
<!-- index.vue 中引用 -->
<editDialog
ref="editModalRef"
v-if="editVisible"
:paramId="paramId"
v-model:visible="editVisible"
@success="reloadTable('noRefresh')"
/>import editDialog from './edit.vue';
// 新增
const handleAdd = async () => {
paramId.value = 0;
editVisible.value = true;
await nextTick();
editModalRef.value?.openModal();
};
// 编辑
const handleEdit = async (record: Recordable) => {
paramId.value = record.id;
editVisible.value = true;
await nextTick();
editModalRef.value?.openModal();
};import { useMessage, useDialog } from 'naive-ui';
const message = useMessage();
const dialog = useDialog();
async function handleDelete(record?: Recordable) {
let ids = [];
if (!record) {
ids = rowKeys.value;
if (!ids.length) {
message.warning('请选择要删除的数据');
return;
}
}
dialog.warning({
title: '提示',
content: '确定要删除?',
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
record ? await paramDelete(record.id) : await paramBatchDelete(ids);
message.success('删除成功');
reloadTable();
},
});
}
// 多选变化
function onCheckedRow(keys: (string | number)[]) {
rowKeys.value = keys;
}| 前缀 | 用途 | 示例 |
|---|---|---|
handle | 事件处理 | handleAdd、handleEdit、handleDelete、handleSubmit、handleReset |
load | 数据加载 | loadDataTable |
reload | 刷新数据 | reloadTable |
on | 组件事件回调 | onSelectionChange、onSuccess、onError |
前端页面统一使用 n-card + BasicForm + BasicTable + TableAction 组件组合。分页由 BasicTable 内置处理,无需单独引入分页组件。每个模块包含 index.vue(列表页)、edit.vue(编辑弹窗)、columns.ts(列定义)、querySchemas.ts(搜索配置)四个文件。API 接口按模块分文件定义在 api/ 目录下。