278 lines
7.4 KiB
Smarty
278 lines
7.4 KiB
Smarty
<template>
|
|
<PageWrapper>
|
|
<!-- 搜索表单卡片 -->
|
|
<a-card :bordered="false" class="pt-3 mb-3 proCard">
|
|
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset" />
|
|
</a-card>
|
|
|
|
<!-- 数据表格卡片 -->
|
|
<a-card :bordered="false" class="proCard">
|
|
<BasicTable
|
|
:columns="columns"
|
|
:request="loadDataTable"
|
|
:row-key="(row) => row.id"
|
|
ref="tableRef"
|
|
:row-selection="{ onChange: onSelectionChange }"
|
|
scroll-x="1200"
|
|
>
|
|
<!-- 表格顶部工具栏 -->
|
|
<template #tableTitle>
|
|
<a-space>
|
|
<!-- 新增按钮 -->
|
|
<a-button type="primary" @click="handleAdd" v-perm="['{{ permission_prefix }}:add']">
|
|
<template #icon>
|
|
<PlusOutlined />
|
|
</template>
|
|
添加{{ module_comment }}
|
|
</a-button>
|
|
|
|
<!-- 批量删除按钮 -->
|
|
<a-button
|
|
type="danger"
|
|
@click="handleDelete()"
|
|
:disabled="!selectionData.length"
|
|
v-perm="['{{ permission_prefix }}:batchDelete']"
|
|
>
|
|
<template #icon>
|
|
<DeleteOutlined />
|
|
</template>
|
|
批量删除
|
|
</a-button>
|
|
{% if has_export %}
|
|
<!-- 导出按钮 -->
|
|
<a-button
|
|
type="primary"
|
|
@click="handleExport"
|
|
v-perm="['{{ permission_prefix }}:export']"
|
|
>
|
|
<template #icon>
|
|
<DownloadOutlined />
|
|
</template>
|
|
导出
|
|
</a-button>
|
|
{% endif %}
|
|
</a-space>
|
|
</template>
|
|
|
|
<!-- 操作列渲染 -->
|
|
<template #bodyCell="{ column, record }">
|
|
<template v-if="column.key === 'action'">
|
|
<a-space>
|
|
<a-button
|
|
type="primary"
|
|
@click="handleEdit(record)"
|
|
v-perm="['{{ permission_prefix }}:update']"
|
|
>
|
|
<template #icon><EditOutlined /></template>
|
|
编辑
|
|
</a-button>
|
|
<a-button
|
|
type="primary"
|
|
@click="handleDetail(record)"
|
|
v-perm="['{{ permission_prefix }}:detail']"
|
|
>
|
|
<template #icon><EyeOutlined /></template>
|
|
详情
|
|
</a-button>
|
|
<a-button
|
|
type="primary"
|
|
danger
|
|
@click="handleDelete(record)"
|
|
v-perm="['{{ permission_prefix }}:delete']"
|
|
>
|
|
<template #icon><DeleteOutlined /></template>
|
|
删除
|
|
</a-button>
|
|
</a-space>
|
|
</template>
|
|
</template>
|
|
</BasicTable>
|
|
</a-card>
|
|
|
|
<!-- 编辑对话框组件 -->
|
|
<editDialog
|
|
v-if="editVisible"
|
|
:{{ primary_key }}="currentId"
|
|
v-model:visible="editVisible"
|
|
@success="reloadTable('noRefresh')"
|
|
/>
|
|
<!-- 查看详情对话框组件 -->
|
|
<detailDialog
|
|
v-if="detailVisible"
|
|
:{{ primary_key }}="currentId"
|
|
v-model:visible="detailVisible"
|
|
@success="reloadTable('noRefresh')"
|
|
/>
|
|
</PageWrapper>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { reactive, ref, nextTick, defineAsyncComponent } from 'vue';
|
|
import { PlusOutlined, EditOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons-vue';
|
|
import { useForm } from '@/components/Form/index';
|
|
import { get{{ model_class_name }}Page, {{ model_class_name_camel }}Delete, {{ model_class_name_camel }}BatchDelete } from '@/api/{{ api_path }}';
|
|
import { columns } from './columns';
|
|
import { schemas } from './querySchemas';
|
|
import { message, Modal } from 'ant-design-vue';
|
|
|
|
// 动态导入编辑对话框组件
|
|
const editDialog = defineAsyncComponent(() => import('./edit.vue'));
|
|
// 动态导入详情对话框组件
|
|
const detailDialog = defineAsyncComponent(() => import('./detail.vue'));
|
|
|
|
// 响应式状态定义
|
|
const currentId = ref(0); // 当前操作的ID
|
|
const editVisible = ref(false); // 编辑对话框显示状态
|
|
const detailVisible = ref(false); // 详情对话框显示状态
|
|
const selectionData = ref([]); // 表格选中数据
|
|
const tableRef = ref(); // 表格组件引用
|
|
|
|
/**
|
|
* 定义查询参数
|
|
* 用于存储搜索表单的值
|
|
*/
|
|
const formParams = reactive({
|
|
{% for field in filter_fields %}
|
|
{{ field.name }}: '',
|
|
{% endfor %}
|
|
});
|
|
|
|
/**
|
|
* 加载数据列表
|
|
* @param params 分页参数
|
|
* @returns 表格数据
|
|
*/
|
|
const loadDataTable = async (params: any) => {
|
|
const result = await get{{ model_class_name }}Page({ ...formParams, ...params });
|
|
return result;
|
|
};
|
|
|
|
/**
|
|
* 刷新表格数据
|
|
* @param noRefresh 是否重置页码
|
|
*/
|
|
function reloadTable(noRefresh = '') {
|
|
tableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
|
}
|
|
|
|
/**
|
|
* 注册搜索表单
|
|
*/
|
|
const [register, {}] = useForm({
|
|
rowProps: { gutter: [16, 0] },
|
|
colProps: {
|
|
xs: 24,
|
|
sm: 24,
|
|
md: 12,
|
|
lg: 8,
|
|
xl: 6,
|
|
},
|
|
labelCol: { span: 6, offset: 0 },
|
|
schemas,
|
|
});
|
|
|
|
/**
|
|
* 提交搜索表单
|
|
* @param values 表单值
|
|
*/
|
|
function handleSubmit(values: Recordable) {
|
|
handleReset();
|
|
for (const key in values) {
|
|
formParams[key] = values[key];
|
|
}
|
|
reloadTable();
|
|
}
|
|
|
|
/**
|
|
* 重置搜索表单
|
|
*/
|
|
function handleReset() {
|
|
for (const key in formParams) {
|
|
formParams[key] = '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 处理新增按钮点击
|
|
*/
|
|
const handleAdd = async () => {
|
|
currentId.value = 0;
|
|
await nextTick();
|
|
editVisible.value = true;
|
|
};
|
|
|
|
/**
|
|
* 处理编辑按钮点击
|
|
* @param record 当前行数据
|
|
*/
|
|
const handleEdit = async (record: Recordable) => {
|
|
currentId.value = record.id;
|
|
await nextTick();
|
|
editVisible.value = true;
|
|
};
|
|
|
|
/**
|
|
* 处理详情按钮点击
|
|
* @param record 当前行数据
|
|
*/
|
|
const handleDetail = async (record: Recordable) => {
|
|
currentId.value = record.id;
|
|
await nextTick();
|
|
detailVisible.value = true;
|
|
};
|
|
|
|
/**
|
|
* 处理删除操作
|
|
* @param record 当前行数据(可选,不传时表示批量删除)
|
|
*/
|
|
async function handleDelete(record: Recordable) {
|
|
let ids = [];
|
|
if (!record) {
|
|
// 批量删除:获取选中行的ID
|
|
ids = selectionData.value.map(({ id }) => id);
|
|
if (!ids.length) {
|
|
message.warning('请选择要删除的数据');
|
|
return;
|
|
}
|
|
}
|
|
|
|
Modal.confirm({
|
|
title: '提示',
|
|
content: '确定要删除选中的{{ module_comment }}吗?',
|
|
onOk: async () => {
|
|
record
|
|
? await {{ model_class_name_camel }}Delete(record.id)
|
|
: await {{ model_class_name_camel }}BatchDelete(ids);
|
|
message.success('删除成功');
|
|
reloadTable();
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 表格选择项变化时的回调
|
|
* @param selectedRowKeys 选中的key
|
|
* @param selectedRows 选中的数据
|
|
*/
|
|
function onSelectionChange(selectedRowKeys, selectedRows) {
|
|
selectionData.value = selectedRows;
|
|
}
|
|
|
|
{% if has_export %}
|
|
/**
|
|
* 处理导出操作
|
|
*/
|
|
async function handleExport() {
|
|
Modal.confirm({
|
|
title: '提示',
|
|
content: '确定要导出{{ module_comment }}数据吗?',
|
|
onOk: async () => {
|
|
// TODO: 调用导出API
|
|
message.success('导出成功');
|
|
},
|
|
});
|
|
}
|
|
{% endif %}
|
|
</script>
|
|
|
|
<style lang="scss" scoped></style> |