admin-vben5/apps/web-antd/src/views/system/config/index.vue

188 lines
4.5 KiB
Vue
Raw Normal View History

2024-08-07 08:57:56 +08:00
<script setup lang="ts">
2024-09-11 21:32:30 +08:00
import type { Recordable } from '@vben/types';
2024-10-05 22:59:14 +08:00
import { ref } from 'vue';
2024-10-05 14:36:21 +08:00
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils';
2024-09-11 21:32:30 +08:00
2024-10-05 14:36:21 +08:00
import { Modal, Popconfirm, Space } from 'ant-design-vue';
2024-09-11 21:32:30 +08:00
import {
tableCheckboxEvent,
useVbenVxeGrid,
type VxeGridProps,
} from '#/adapter/vxe-table';
2024-10-05 14:36:21 +08:00
import {
configExport,
configList,
configRefreshCache,
configRemove,
} from '#/api/system/config';
import { commonDownloadExcel } from '#/utils/file/download';
2024-09-11 20:23:44 +08:00
import configModal from './config-modal.vue';
2024-10-05 14:36:21 +08:00
import { columns, querySchema } from './data';
const formOptions: VbenFormProps = {
2024-10-05 22:59:14 +08:00
commonConfig: {
labelWidth: 80,
componentProps: {
allowClear: true,
},
2024-10-05 22:59:14 +08:00
},
2024-10-05 14:36:21 +08:00
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
// 日期选择格式化
fieldMappingTime: [
[
'createTime',
['params[beginTime]', 'params[endTime]'],
['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
],
],
2024-10-05 14:36:21 +08:00
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
},
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
2024-10-06 09:53:00 +08:00
query: async ({ page }, formValues = {}) => {
2024-10-05 14:36:21 +08:00
return await configList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
isHover: true,
keyField: 'configId',
},
id: 'system-config-index',
2024-10-05 14:36:21 +08:00
};
2024-10-05 22:59:14 +08:00
const checked = ref(false);
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
gridEvents: {
checkboxChange: tableCheckboxEvent(checked),
checkboxAll: tableCheckboxEvent(checked),
2024-10-05 22:59:14 +08:00
},
});
2024-09-11 20:23:44 +08:00
const [ConfigModal, modalApi] = useVbenModal({
connectedComponent: configModal,
});
function handleAdd() {
2024-09-23 09:55:40 +08:00
modalApi.setData({});
2024-09-11 20:23:44 +08:00
modalApi.open();
}
2024-09-11 21:32:30 +08:00
async function handleEdit(record: Recordable<any>) {
2024-09-23 09:55:40 +08:00
modalApi.setData({ id: record.configId });
2024-09-11 21:32:30 +08:00
modalApi.open();
2024-09-11 20:23:44 +08:00
}
2024-09-11 21:32:30 +08:00
2024-10-05 14:36:21 +08:00
async function handleDelete(row: Recordable<any>) {
await configRemove(row.configId);
2024-10-06 09:53:00 +08:00
await tableApi.query();
2024-09-11 21:32:30 +08:00
}
2024-10-05 14:36:21 +08:00
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: any) => row.configId);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await configRemove(ids);
2024-10-06 09:53:00 +08:00
await tableApi.query();
2024-10-06 10:15:17 +08:00
checked.value = false;
2024-09-12 08:43:56 +08:00
},
2024-10-05 14:36:21 +08:00
});
}
2024-09-24 11:23:02 +08:00
function handleDownloadExcel() {
commonDownloadExcel(configExport, '参数配置', tableApi.formApi.form.values, {
fieldMappingTime: formOptions.fieldMappingTime,
});
}
2024-10-05 14:36:21 +08:00
async function handleRefreshCache() {
await configRefreshCache();
2024-10-06 09:53:00 +08:00
await tableApi.query();
2024-10-05 14:36:21 +08:00
}
2024-08-07 08:57:56 +08:00
</script>
<template>
2024-10-05 14:36:21 +08:00
<Page :auto-content-height="true">
2024-10-25 08:09:53 +08:00
<BasicTable table-title="参数列表">
2024-10-05 14:36:21 +08:00
<template #toolbar-tools>
<Space>
<a-button @click="handleRefreshCache"> 刷新缓存 </a-button>
<a-button
v-access:code="['system:config:export']"
@click="handleDownloadExcel"
2024-10-05 14:36:21 +08:00
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
2024-10-05 22:59:14 +08:00
:disabled="!checked"
2024-10-05 14:36:21 +08:00
danger
type="primary"
2024-10-05 22:59:14 +08:00
v-access:code="['system:config:remove']"
2024-10-05 14:36:21 +08:00
@click="handleMultiDelete"
>
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['system:config:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
2024-10-07 16:56:32 +08:00
<Space>
<ghost-button
v-access:code="['system:config:edit']"
@click.stop="handleEdit(row)"
2024-10-05 14:36:21 +08:00
>
2024-10-07 16:56:32 +08:00
{{ $t('pages.common.edit') }}
</ghost-button>
<Popconfirm
:get-popup-container="getVxePopupContainer"
2024-10-07 16:56:32 +08:00
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<ghost-button
danger
v-access:code="['system:config:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
2024-09-11 21:32:30 +08:00
</template>
2024-10-05 14:36:21 +08:00
</BasicTable>
2024-10-06 09:53:00 +08:00
<ConfigModal @reload="tableApi.query()" />
2024-09-11 20:23:44 +08:00
</Page>
2024-08-07 08:57:56 +08:00
</template>