<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { DecisionKpiApi } from '#/api/bi/decision/kpi';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
|
import { message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { deleteKpiDefinition, getKpiDefinitionPage } from '#/api/bi/decision/kpi';
|
|
import { CATEGORY_MAP, useGridColumns, useGridFormSchema } from './data';
|
import Form from './modules/form.vue';
|
|
defineOptions({ name: 'DecisionKpiConfig' });
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
proxyConfig: {
|
ajax: {
|
query: async ({ page, form }: any) => {
|
const res = await getKpiDefinitionPage({ ...page, ...form });
|
return res;
|
},
|
},
|
},
|
} as VxeTableGridOptions<DecisionKpiApi.KpiDefinition>,
|
});
|
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
function handleCreate() {
|
formModalApi.setData(null).open();
|
}
|
|
function handleEdit(row: DecisionKpiApi.KpiDefinition) {
|
formModalApi.setData(row).open();
|
}
|
|
async function handleDelete(row: DecisionKpiApi.KpiDefinition) {
|
const hide = message.loading(`正在删除「${row.name}」...`, 0);
|
try {
|
await deleteKpiDefinition(row.id!);
|
message.success(`删除「${row.name}」成功`);
|
handleRefresh();
|
} finally {
|
hide();
|
}
|
}
|
</script>
|
|
<template>
|
<Page :auto-content-height="true">
|
<div class="mb-3 flex items-center justify-between">
|
<span class="text-lg font-bold">KPI指标定义</span>
|
<a-button type="primary" @click="handleCreate">新增</a-button>
|
</div>
|
<Grid>
|
<template #categorySlot="{ row }">
|
<Tag color="blue">{{ CATEGORY_MAP[row.category] || row.category }}</Tag>
|
</template>
|
<template #statusSlot="{ row }">
|
<Tag :color="row.status === 1 ? 'green' : 'default'">{{ row.status === 1 ? '启用' : '禁用' }}</Tag>
|
</template>
|
<template #actionSlot="{ row }">
|
<TableAction
|
:actions="[
|
{ label: '编辑', type: 'link', icon: ACTION_ICON.EDIT, onClick: handleEdit.bind(null, row) },
|
{ label: '删除', type: 'link', danger: true, icon: ACTION_ICON.DELETE, onClick: handleDelete.bind(null, row) },
|
]"
|
/>
|
</template>
|
</Grid>
|
<FormModal />
|
</Page>
|
</template>
|