Files
lgp-admin-plus-api/app/template/view/index.vue

131 lines
3.9 KiB
Vue
Raw Normal View History

2025-05-13 10:39:21 +08:00
<script lang="ts" setup>
import type { VxeGridListeners } from '#/adapter/vxe-table';
import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
2025-05-13 13:16:59 +08:00
import { Button, Image, message } from 'ant-design-vue';
2025-05-13 10:39:21 +08:00
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { TableAction } from '#/components/table-action';
2025-05-13 13:16:59 +08:00
import { deleteupperCamelCaseApi } from './api';
import FormModalDemo from './components/modal.vue';
2025-05-13 10:39:21 +08:00
import { formOptions } from './config/search';
import { gridOptions } from './config/table';
const hasTopTableDropDownActions = ref(false);
const gridEvents: VxeGridListeners<any> = {
2025-05-13 13:16:59 +08:00
checkboxChange() {
const records = gridApi.grid.getCheckboxRecords();
hasTopTableDropDownActions.value = records.length > 0;
},
checkboxAll() {
const records = gridApi.grid.getCheckboxRecords();
hasTopTableDropDownActions.value = records.length > 0;
},
2025-05-13 10:39:21 +08:00
};
const [Grid, gridApi] = useVbenVxeGrid({
2025-05-13 13:16:59 +08:00
formOptions,
gridOptions,
gridEvents,
2025-05-13 10:39:21 +08:00
});
const [FormModal, formModalApi] = useVbenModal({
2025-05-13 13:16:59 +08:00
connectedComponent: FormModalDemo,
2025-05-13 10:39:21 +08:00
});
const showModal = (data = {}, isUpdate = false) => {
2025-05-13 13:16:59 +08:00
formModalApi.setData({
// 表单值
values: data,
update: isUpdate,
gridApi,
});
formModalApi.open();
2025-05-13 10:39:21 +08:00
};
2025-05-13 13:16:59 +08:00
const hasDelete = (row: any) => {
let ids = [];
if (row) {
ids.push(row);
} else {
ids = gridApi.grid.getCheckboxRecords().map((item) => item.id);
}
deleteupperCamelCaseApi({ ids }).then(() => {
message.success('删除成功!');
gridApi.reload();
});
2025-05-13 10:39:21 +08:00
};
</script>
<template>
2025-05-13 13:16:59 +08:00
<Page auto-content-height title="模板名称管理">
<FormModal />
<Grid>
<template #toolbar-buttons>
<TableAction
:actions="[
2025-05-13 10:39:21 +08:00
{
label: '新增',
type: 'primary',
icon: 'ant-design:plus-outlined',
onClick: showModal.bind(null),
},
]"
2025-05-13 13:16:59 +08:00
:drop-down-actions="[
2025-05-13 10:39:21 +08:00
{
label: '删除',
icon: 'ant-design:delete-outlined',
ifShow: hasTopTableDropDownActions,
popConfirm: {
title: '确定删除吗?',
2025-05-13 13:16:59 +08:00
confirm: hasDelete.bind(null, false),
2025-05-13 10:39:21 +08:00
},
},
]"
2025-05-13 13:16:59 +08:00
>
<template #more>
<Button style="margin-left: 16px">
批量操作
</Button>
</template>
</TableAction>
</template>
<template #avatar="{ row }">
<Image :src="row.avatar" height="30" width="30" />
</template>
<template #toolbar-tools></template>
<template #action="{ row }">
<TableAction
:actions="[
{
label: '编辑',
type: 'link',
icon: 'uil:edit',
size: 'small',
// auth: ['admin', 'sys:role:detail'],
onClick: showModal.bind(null, row, true),
},
{
label: '删除',
type: 'link',
icon: 'ant-design:delete-outlined',
size: 'small',
// auth: ['admin', 'sys:role:detail'],
popConfirm: {
title: '确定删除吗?',
confirm: hasDelete.bind(null, row.id),
},
},
]"
:drop-down-actions="[]"
/>
</template>
</Grid>
</Page>
2025-05-13 10:39:21 +08:00
</template>