政策启用禁用功能开发
Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled

This commit is contained in:
冯辉
2026-06-28 02:12:36 +08:00
parent 4412d752d5
commit 312dd9ac9d
7 changed files with 78 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState } from 'react';
import { useAccess } from '@umijs/max';
import { Button, message, Modal } from 'antd';
import { Button, message, Modal, Switch } from 'antd';
import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
import { PlusOutlined, DeleteOutlined, FormOutlined, EyeOutlined } from '@ant-design/icons';
import {
@@ -9,6 +9,7 @@ import {
addPolicyInfo,
updatePolicyInfo,
deletePolicyInfo,
changePolicyStatus,
} from '@/services/cms/policyInfo';
import { getDictValueEnum } from '@/services/system/dict';
import DictTag, { DictValueEnumObj } from '@/components/DictTag';
@@ -47,6 +48,24 @@ const PolicyMgmt: React.FC = () => {
});
};
const handleStatusChange = async (id: number, checked: boolean) => {
const newStatus = checked ? '0' : '1';
const statusLabel = checked ? '启用' : '禁用';
Modal.confirm({
title: `确认${statusLabel}`,
content: `确定要${statusLabel}该政策吗?`,
onOk: async () => {
const res = await changePolicyStatus(id, newStatus);
if (res.code === 200) {
message.success(`${statusLabel}成功`);
actionRef.current?.reload();
} else {
message.error(res.msg || `${statusLabel}失败`);
}
},
});
};
const columns: ProColumns<API.PolicyInfo.PolicyInfoItem>[] = [
{
title: '政策名称',
@@ -108,6 +127,25 @@ const PolicyMgmt: React.FC = () => {
hideInSearch: true,
width: 80,
},
{
title: '状态',
dataIndex: 'status',
width: 80,
valueType: 'select',
valueEnum: {
'0': { text: '启用', status: 'Success' },
'1': { text: '禁用', status: 'Error' },
},
fixed: 'right',
render: (_, record) => (
<Switch
checked={record.status === '0'}
checkedChildren="启用"
unCheckedChildren="禁用"
onChange={(checked) => handleStatusChange(record.id, checked)}
/>
),
},
{
title: '创建时间',
dataIndex: 'createTime',