签入脚本
This commit is contained in:
@@ -0,0 +1,337 @@
|
||||
<template>
|
||||
<PageWrapper>
|
||||
<!-- 搜索表单卡片 -->
|
||||
<el-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset" />
|
||||
</el-card>
|
||||
|
||||
<!-- 数据表格卡片 -->
|
||||
<el-card :bordered="false" class="proCard">
|
||||
<BasicTable
|
||||
:columns="columns"
|
||||
:request="loadDataTable"
|
||||
:row-key="(row) => row.id"
|
||||
ref="tableRef"
|
||||
:actionColumn="actionColumn"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<!-- 表格顶部工具栏 -->
|
||||
<template #tableTitle>
|
||||
<!-- 新增按钮 -->
|
||||
<el-button type="primary" @click="handleAdd" v-perm="['[[$.PermissionPrefix]]:add']">
|
||||
<template #icon>
|
||||
<el-icon class="el-input__icon">
|
||||
<PlusOutlined />
|
||||
</el-icon>
|
||||
</template>
|
||||
添加[[$.ModuleComment]]
|
||||
</el-button>
|
||||
|
||||
<!-- 批量删除按钮 -->
|
||||
<el-button
|
||||
type="danger"
|
||||
@click="handleDelete()"
|
||||
:disabled="!selectionData.length"
|
||||
v-perm="['[[$.PermissionPrefix]]:batchDelete']"
|
||||
>
|
||||
<template #icon>
|
||||
<el-icon class="el-input__icon">
|
||||
<Delete />
|
||||
</el-icon>
|
||||
</template>
|
||||
批量删除
|
||||
</el-button>
|
||||
[[- if $.HasImport]]
|
||||
<!-- 导入按钮 -->
|
||||
<el-button type="" @click="importVisible = true" v-perm="['[[$.PermissionPrefix]]:import']">
|
||||
<template #icon>
|
||||
<el-icon class="el-input__icon">
|
||||
<Upload />
|
||||
</el-icon>
|
||||
</template>
|
||||
导入
|
||||
</el-button>
|
||||
[[- end]]
|
||||
[[- if $.HasExport]]
|
||||
<!-- 导出按钮 -->
|
||||
<el-button
|
||||
type=""
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
:disabled="exportLoading"
|
||||
v-perm="['[[$.PermissionPrefix]]:export']"
|
||||
>
|
||||
<template #icon>
|
||||
<el-icon class="el-input__icon">
|
||||
<Download />
|
||||
</el-icon>
|
||||
</template>
|
||||
导出
|
||||
</el-button>
|
||||
[[- end]]
|
||||
</template>
|
||||
</BasicTable>
|
||||
</el-card>
|
||||
|
||||
<!-- 新增/编辑弹窗,主键为 0 时表示新增 -->
|
||||
<editDialog
|
||||
v-if="editVisible"
|
||||
:[[$.PrimaryPk]]="currentId"
|
||||
v-model:visible="editVisible"
|
||||
@success="reloadTable('noRefresh')"
|
||||
/>
|
||||
<!-- 详情弹窗 -->
|
||||
<detailDialog
|
||||
v-if="detailVisible"
|
||||
:[[$.PrimaryPk]]="currentId"
|
||||
v-model:visible="detailVisible"
|
||||
@success="reloadTable('noRefresh')"
|
||||
/>
|
||||
[[- if $.HasImport]]
|
||||
<!-- 导入弹窗,templateCode 对应后端模板编码 -->
|
||||
<fileUpload
|
||||
v-if="importVisible"
|
||||
v-model:visible="importVisible"
|
||||
api="/api/[[$.RoutePrefix]]/import"
|
||||
templateCode="[[$.Module]]_import"
|
||||
dialogTitle="导入[[$.ModuleComment]]"
|
||||
@success="reloadTable()"
|
||||
/>
|
||||
[[- end]]
|
||||
</PageWrapper>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref, h, nextTick, defineAsyncComponent } from 'vue';
|
||||
import { ColProps } from 'element-plus';
|
||||
import { schemas } from './querySchemas';
|
||||
import { useForm } from '@/components/Form/index';
|
||||
import { TableAction } from '@/components/Table';
|
||||
import { get[[$.ModelClass]]Page, [[$.ModuleCamel]]Delete, [[$.ModuleCamel]]BatchDelete[[if $.HasExport]], [[$.ModuleCamel]]Export[[end]] } from '@/api/[[$.ApiPath]]';
|
||||
import { columns } from './columns';
|
||||
import { PlusOutlined } from '@vicons/antd';
|
||||
import { message, confirm } from '@/utils/auth';
|
||||
|
||||
// 动态导入编辑对话框组件
|
||||
const editDialog = defineAsyncComponent(() => import('./edit.vue'));
|
||||
// 动态导入详情对话框组件
|
||||
const detailDialog = defineAsyncComponent(() => import('./detail.vue'));
|
||||
[[- if $.HasImport]]
|
||||
// 动态导入文件上传组件
|
||||
const fileUpload = defineAsyncComponent(() => import('@/components/importFile/index.vue'));
|
||||
[[- end]]
|
||||
// 响应式状态定义
|
||||
const currentId = ref(0); // 当前操作的ID
|
||||
const editVisible = ref(false); // 编辑对话框显示状态
|
||||
const detailVisible = ref(false); // 详情对话框显示状态
|
||||
[[- if $.HasImport]]
|
||||
const importVisible = ref(false); // 导入对话框显示状态
|
||||
[[- end]]
|
||||
[[- if $.HasExport]]
|
||||
const exportLoading = ref(false); // 导出按钮加载状态
|
||||
[[- end]]
|
||||
const selectionData = ref([]); // 表格选中数据
|
||||
const tableRef = ref(); // 表格组件引用
|
||||
|
||||
/**
|
||||
* 查询参数
|
||||
*
|
||||
* 与搜索表单字段一一对应,提交后合并到分页请求中。
|
||||
*/
|
||||
const formParams = reactive({
|
||||
[[- range .FilterFields]]
|
||||
[[.Name]]: '',
|
||||
[[- end]]
|
||||
});
|
||||
|
||||
/**
|
||||
* 操作栏配置
|
||||
*
|
||||
* 固定右侧显示,包含编辑、详情、删除三个按钮;
|
||||
* 每个按钮通过 auth 声明所需权限,由 v-perm 指令控制显隐。
|
||||
*/
|
||||
const actionColumn = reactive({
|
||||
width: 300,
|
||||
label: '操作',
|
||||
prop: 'action',
|
||||
fixed: 'right',
|
||||
render(record) {
|
||||
return h(TableAction, {
|
||||
style: 'button',
|
||||
actions: [
|
||||
{
|
||||
label: '编辑',
|
||||
icon: 'Edit',
|
||||
type: 'warning',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: ['[[$.PermissionPrefix]]:update'],
|
||||
},
|
||||
{
|
||||
label: '详情',
|
||||
icon: 'View',
|
||||
type: '',
|
||||
onClick: handleDetail.bind(null, record),
|
||||
auth: ['[[$.PermissionPrefix]]:detail'],
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
icon: 'Delete',
|
||||
type: 'danger',
|
||||
onClick: handleDelete.bind(null, record),
|
||||
auth: ['[[$.PermissionPrefix]]:delete'],
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 加载表格数据
|
||||
*
|
||||
* 合并搜索条件与分页参数后请求分页接口,
|
||||
* 返回值直接交给 BasicTable 渲染。
|
||||
*
|
||||
* @param params 分页参数,含 pageNo、pageSize
|
||||
* @returns 分页结果
|
||||
*/
|
||||
const loadDataTable = async (params: any) => {
|
||||
const result = await get[[$.ModelClass]]Page({ ...formParams, ...params });
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 刷新表格数据
|
||||
*
|
||||
* @param noRefresh 传入非空值时保持当前页码,否则回到第一页
|
||||
*/
|
||||
function reloadTable(noRefresh = '') {
|
||||
tableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册搜索表单
|
||||
*
|
||||
* 配置表单布局、字段来源与提交重置行为,
|
||||
* 返回 register 供模板绑定、getFieldsValue 供导出取值。
|
||||
*/
|
||||
const [register, { getFieldsValue }] = useForm({
|
||||
labelWidth: 80,
|
||||
layout: 'horizontal',
|
||||
colProps: { span: 6 } as ColProps,
|
||||
submitOnReset: true,
|
||||
schemas,
|
||||
});
|
||||
|
||||
/**
|
||||
* 提交搜索
|
||||
*
|
||||
* 先把当前条件写回 formParams,再从第一页重新加载。
|
||||
*
|
||||
* @param values 表单值
|
||||
*/
|
||||
function handleSubmit(values: Recordable) {
|
||||
handleReset();
|
||||
for (const key in values) {
|
||||
formParams[key] = values[key];
|
||||
}
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置搜索条件
|
||||
*
|
||||
* 清空 formParams 中的所有筛选项,回到无条件状态。
|
||||
*/
|
||||
function handleReset() {
|
||||
for (const key in formParams) {
|
||||
formParams[key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开新增弹窗
|
||||
*
|
||||
* 主键置 0 表示新增,nextTick 保证弹窗组件重新创建后再显示。
|
||||
*/
|
||||
const handleAdd = async () => {
|
||||
currentId.value = 0;
|
||||
await nextTick();
|
||||
editVisible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开编辑弹窗
|
||||
*
|
||||
* @param record 当前行数据
|
||||
*/
|
||||
const handleEdit = async (record: Recordable) => {
|
||||
currentId.value = record.row.id;
|
||||
await nextTick();
|
||||
editVisible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开详情弹窗
|
||||
*
|
||||
* @param record 当前行数据
|
||||
*/
|
||||
const handleDetail = async (record: Recordable) => {
|
||||
currentId.value = record.row.id;
|
||||
await nextTick();
|
||||
detailVisible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* 不传 record 时为批量删除,从选中行取 ID 并做非空校验;
|
||||
* 传 record 时为单条删除。两种情况都先弹出确认框。
|
||||
*
|
||||
* @param record 当前行数据(可选)
|
||||
*/
|
||||
async function handleDelete(record: Recordable) {
|
||||
let ids = [];
|
||||
if (!record) {
|
||||
// 批量删除:获取选中行的ID
|
||||
ids = selectionData.value.map(({ id }) => id);
|
||||
if (!ids.length) {
|
||||
message('请选择要删除的数据', 'warning');
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 确认删除
|
||||
await confirm('确定要删除选中的[[$.ModuleComment]]吗?');
|
||||
// 执行删除操作
|
||||
record ? await [[$.ModuleCamel]]Delete(record.row.id) : await [[$.ModuleCamel]]BatchDelete(ids);
|
||||
message('删除成功');
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格选中项变化回调
|
||||
*
|
||||
* 把选中行同步到 selectionData,供批量删除使用。
|
||||
*
|
||||
* @param value 选中的数据
|
||||
*/
|
||||
function onSelectionChange(value) {
|
||||
selectionData.value = value;
|
||||
}
|
||||
[[- if $.HasExport]]
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* 以当前搜索条件请求导出接口,拿到文件 URL 后新窗口打开;
|
||||
* 导出期间按钮保持 loading,避免重复点击。
|
||||
*/
|
||||
const handleExport = async () => {
|
||||
exportLoading.value = true;
|
||||
const data = await [[$.ModuleCamel]]Export(getFieldsValue());
|
||||
window.open(data);
|
||||
exportLoading.value = false;
|
||||
message('导出成功');
|
||||
};
|
||||
[[- end]]
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
Reference in New Issue
Block a user