This commit is contained in:
2026-06-18 17:49:54 +08:00
parent 3e110d466c
commit b0ee15d8c1
5 changed files with 609 additions and 0 deletions

View File

@@ -1,2 +1,3 @@
export * from './feature'; export * from './feature';
export * from './product'; export * from './product';
export * from './whitelist';

View File

@@ -0,0 +1,101 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace WhitelistApi {
export interface WhitelistItem {
id: string;
id_card: string;
feature_id: string;
feature_api_id: string;
feature_name: string;
user_id: string;
amount: number;
status: number;
status_text: string;
create_time: string;
update_time: string;
}
export interface WhitelistList {
total: number;
items: WhitelistItem[];
}
export interface CreateWhitelistRequest {
id_card: string;
feature_id: string;
amount?: number;
status?: number;
}
export interface BatchCreateWhitelistRequest {
id_card: string;
feature_ids: string[];
amount?: number;
status?: number;
}
export interface BatchCreateWhitelistResultItem {
feature_id: string;
feature_api_id: string;
feature_name: string;
action: string;
message?: string;
}
export interface BatchCreateWhitelistResponse {
success_count: number;
skip_count: number;
fail_count: number;
items: BatchCreateWhitelistResultItem[];
}
export interface UpdateWhitelistRequest {
status?: number;
amount?: number;
}
}
async function getWhitelistList(params: Recordable<any>) {
return requestClient.get<WhitelistApi.WhitelistList>('/whitelist/list', {
params,
});
}
async function createWhitelist(data: WhitelistApi.CreateWhitelistRequest) {
return requestClient.post<{ id: string }>('/whitelist/create', data);
}
async function batchCreateWhitelist(
data: WhitelistApi.BatchCreateWhitelistRequest,
) {
return requestClient.post<WhitelistApi.BatchCreateWhitelistResponse>(
'/whitelist/batch-create',
data,
);
}
async function updateWhitelist(
id: string,
data: WhitelistApi.UpdateWhitelistRequest,
) {
return requestClient.put<{ success: boolean }>(
`/whitelist/update/${id}`,
data,
);
}
async function deleteWhitelist(id: string) {
return requestClient.delete<{ success: boolean }>(
`/whitelist/delete/${id}`,
);
}
export {
batchCreateWhitelist,
createWhitelist,
deleteWhitelist,
getWhitelistList,
updateWhitelist,
};

View File

@@ -0,0 +1,207 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { WhitelistApi } from '#/api/product-manage';
/** 快捷勾选预设:按模块编号 api_id 匹配 */
export const WHITELIST_QUICK_PRESETS = [
{
label: '司法涉诉 + 违约失信',
apiIds: ['FLXG7E8F', 'JRZQ8A2D'],
},
{
label: '司法涉诉',
apiIds: ['FLXG7E8F'],
},
{
label: '违约失信',
apiIds: ['JRZQ8A2D'],
},
] as const;
export function useFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id_card',
label: '身份证号',
rules: 'required',
componentProps: {
placeholder: '请输入被屏蔽对象的身份证号',
},
},
{
component: 'Select',
fieldName: 'feature_ids',
label: '屏蔽模块',
rules: 'required',
formItemClass: 'items-start',
componentProps: {
mode: 'multiple',
showSearch: true,
optionFilterProp: 'label',
allowClear: true,
placeholder: '请选择要屏蔽的模块,支持多选',
options: [],
class: 'w-full',
},
},
{
component: 'InputNumber',
fieldName: 'amount',
label: '费用(元)',
defaultValue: 0,
componentProps: {
min: 0,
precision: 2,
},
},
{
component: 'Select',
fieldName: 'status',
label: '状态',
defaultValue: 1,
componentProps: {
options: [
{ label: '生效', value: 1 },
{ label: '已失效', value: 2 },
],
},
},
];
}
export function useEditFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id_card',
label: '身份证号',
componentProps: {
disabled: true,
},
},
{
component: 'Input',
fieldName: 'feature_name',
label: '屏蔽模块',
componentProps: {
disabled: true,
},
},
{
component: 'InputNumber',
fieldName: 'amount',
label: '费用(元)',
componentProps: {
min: 0,
precision: 2,
},
},
{
component: 'Select',
fieldName: 'status',
label: '状态',
componentProps: {
options: [
{ label: '生效', value: 1 },
{ label: '已失效', value: 2 },
],
},
},
];
}
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id_card',
label: '身份证号',
},
{
component: 'Input',
fieldName: 'feature_api_id',
label: '模块编号',
},
{
component: 'Select',
fieldName: 'status',
label: '状态',
componentProps: {
allowClear: true,
options: [
{ label: '生效', value: 1 },
{ label: '已失效', value: 2 },
],
},
},
];
}
export function useColumns<T = WhitelistApi.WhitelistItem>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [
{
field: 'id_card',
title: '身份证号',
minWidth: 180,
},
{
field: 'feature_api_id',
title: '模块编号',
minWidth: 140,
},
{
field: 'feature_name',
title: '模块名称',
minWidth: 160,
},
{
field: 'amount',
formatter: ({ cellValue }) => `¥${(cellValue || 0).toFixed(2)}`,
title: '费用(元)',
minWidth: 110,
},
{
field: 'status_text',
title: '状态',
minWidth: 90,
},
{
field: 'create_time',
title: '创建时间',
minWidth: 180,
},
{
field: 'update_time',
title: '更新时间',
minWidth: 180,
},
{
align: 'center',
cellRender: {
attrs: {
nameField: 'id_card',
nameTitle: '白名单',
onClick: onActionClick,
},
options: [
{
code: 'edit',
text: '编辑',
},
{
code: 'delete',
text: '删除',
},
],
name: 'CellOperation',
},
field: 'operation',
fixed: 'right',
title: '操作',
width: 140,
},
];
}

View File

@@ -0,0 +1,114 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { WhitelistApi } from '#/api/product-manage';
import { Page, useVbenDrawer } from '@vben/common-ui';
import { Plus } from '@vben/icons';
import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteWhitelist, getWhitelistList } from '#/api/product-manage';
import { useColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const [FormDrawer, formDrawerApi] = useVbenDrawer({
connectedComponent: Form,
destroyOnClose: true,
});
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
submitOnChange: true,
},
gridOptions: {
columns: useColumns(onActionClick),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getWhitelistList({
page: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
custom: true,
export: false,
refresh: { code: 'query' },
search: true,
zoom: true,
},
} as VxeTableGridOptions<WhitelistApi.WhitelistItem>,
});
function onActionClick(e: OnActionClickParams<WhitelistApi.WhitelistItem>) {
switch (e.code) {
case 'delete': {
onDelete(e.row);
break;
}
case 'edit': {
onEdit(e.row);
break;
}
}
}
function onEdit(row: WhitelistApi.WhitelistItem) {
formDrawerApi.setData(row).open();
}
function onDelete(row: WhitelistApi.WhitelistItem) {
const hideLoading = message.loading({
content: `正在删除 ${row.id_card} 的白名单记录`,
duration: 0,
key: 'whitelist_delete_msg',
});
deleteWhitelist(row.id)
.then(() => {
message.success({
content: '删除成功',
key: 'whitelist_delete_msg',
});
onRefresh();
})
.catch(() => {
hideLoading();
});
}
function onRefresh() {
gridApi.query();
}
function onCreate() {
formDrawerApi.setData({}).open();
}
</script>
<template>
<Page auto-content-height>
<FormDrawer @success="onRefresh" />
<Grid table-title="模块白名单">
<template #toolbar-tools>
<Button type="primary" @click="onCreate">
<Plus class="size-5" />
手动添加
</Button>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,186 @@
<script lang="ts" setup>
import type { FeatureApi, WhitelistApi } from '#/api/product-manage';
import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui';
import { Button, message, Space } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import {
batchCreateWhitelist,
getFeatureList,
updateWhitelist,
} from '#/api/product-manage';
import { useEditFormSchema, useFormSchema, WHITELIST_QUICK_PRESETS } from '../data';
const emit = defineEmits(['success']);
const formData = ref<WhitelistApi.WhitelistItem>();
const isEdit = ref(false);
const featureList = ref<FeatureApi.FeatureItem[]>([]);
const [Form, formApi] = useVbenForm({
schema: useFormSchema(),
showDefaultActions: false,
});
const id = ref<string>();
async function loadFeatureOptions() {
const result = await getFeatureList({ page: 1, pageSize: 500 });
featureList.value = result.items || [];
const options = featureList.value.map((item) => ({
label: `${item.api_id} - ${item.name}`,
value: item.id,
}));
formApi.updateSchema([
{
fieldName: 'feature_ids',
componentProps: {
options,
},
},
]);
}
function resolveFeatureIdsByApiIds(apiIds: string[]) {
const idMap = new Map(
featureList.value.map((item) => [item.api_id, item.id]),
);
return apiIds
.map((apiId) => idMap.get(apiId))
.filter((featureId): featureId is string => !!featureId);
}
async function applyPreset(apiIds: readonly string[]) {
if (featureList.value.length === 0) {
await loadFeatureOptions();
}
const selectedIds = resolveFeatureIdsByApiIds([...apiIds]);
if (selectedIds.length === 0) {
message.warning('未找到对应模块,请确认模块编号是否存在于系统中');
return;
}
const currentValues = await formApi.getValues();
const mergedIds = Array.from(
new Set([...(currentValues.feature_ids || []), ...selectedIds]),
);
formApi.setValues({
...currentValues,
feature_ids: mergedIds,
});
}
async function applyAllFeatures() {
if (featureList.value.length === 0) {
await loadFeatureOptions();
}
const allIds = featureList.value.map((item) => item.id);
const currentValues = await formApi.getValues();
formApi.setValues({
...currentValues,
feature_ids: allIds,
});
}
const [Drawer, drawerApi] = useVbenDrawer({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) return;
const values = await formApi.getValues();
drawerApi.lock();
try {
if (isEdit.value && id.value) {
await updateWhitelist(id.value, {
amount: values.amount,
status: values.status,
});
message.success('更新成功');
} else {
const featureIds = values.feature_ids || [];
if (featureIds.length === 0) {
message.warning('请至少选择一个屏蔽模块');
drawerApi.unlock();
return;
}
const result = await batchCreateWhitelist({
id_card: values.id_card,
feature_ids: featureIds,
amount: values.amount,
status: values.status,
});
const { success_count, skip_count, fail_count } = result;
if (fail_count > 0) {
message.warning(
`完成:成功 ${success_count} 条,跳过 ${skip_count} 条,失败 ${fail_count}`,
);
} else if (skip_count > 0) {
message.success(
`完成:成功 ${success_count} 条,跳过 ${skip_count} 条(已存在)`,
);
} else {
message.success(`已成功屏蔽 ${success_count} 个模块`);
}
}
emit('success');
drawerApi.close();
} catch {
drawerApi.unlock();
}
},
async onOpenChange(open) {
if (!open) return;
const data = drawerApi.getData<WhitelistApi.WhitelistItem>();
formApi.resetForm();
isEdit.value = !!data?.id;
id.value = data?.id;
if (isEdit.value && data) {
formData.value = data;
formApi.setState({ schema: useEditFormSchema() });
formApi.setValues({
id_card: data.id_card,
feature_name: `${data.feature_api_id} - ${data.feature_name || ''}`,
amount: data.amount,
status: data.status,
});
return;
}
formData.value = undefined;
formApi.setState({ schema: useFormSchema() });
await loadFeatureOptions();
},
});
const getDrawerTitle = computed(() =>
isEdit.value ? '编辑白名单' : '手动添加白名单',
);
</script>
<template>
<Drawer :title="getDrawerTitle">
<div v-if="!isEdit" class="mb-4">
<div class="mb-2 text-sm text-gray-500">快捷勾选</div>
<Space wrap>
<Button
v-for="preset in WHITELIST_QUICK_PRESETS"
:key="preset.label"
size="small"
@click="applyPreset(preset.apiIds)"
>
{{ preset.label }}
</Button>
<Button size="small" type="dashed" @click="applyAllFeatures">
全选模块
</Button>
</Space>
</div>
<Form />
</Drawer>
</template>