政策启用禁用全系爱你功能开发
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
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:
@@ -1,4 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useAccess } from '@umijs/max';
|
||||
import { Modal, Form, Input, DatePicker, Upload, Button, message, Row, Col, Select, Switch } from 'antd';
|
||||
import { UploadOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||
import type { UploadFile } from 'antd/es/upload/interface';
|
||||
@@ -17,6 +18,7 @@ interface EditModalProps {
|
||||
}
|
||||
|
||||
const EditModal: React.FC<EditModalProps> = ({ open, values, onCancel, onSubmit }) => {
|
||||
const access = useAccess();
|
||||
const [form] = Form.useForm();
|
||||
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
@@ -95,12 +97,14 @@ const EditModal: React.FC<EditModalProps> = ({ open, values, onCancel, onSubmit
|
||||
const handleOk = async () => {
|
||||
const formValues = await form.validateFields();
|
||||
const { policyTag, publishTime, status, ...rest } = formValues;
|
||||
const canChangeStatus = access.hasPerms('cms:policyInfo:status');
|
||||
onSubmit({
|
||||
...rest,
|
||||
id: values?.id,
|
||||
publishTime: publishTime?.format('YYYY-MM-DD'),
|
||||
policyTag: Array.isArray(policyTag) ? policyTag.join(',') : policyTag,
|
||||
status: status ? '0' : '1',
|
||||
// 有权限时取表单 Switch 值,无权限时保持原状态(新增默认启用,编辑保持原值)
|
||||
status: canChangeStatus ? (status ? '0' : '1') : (values?.status || '0'),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -208,11 +212,13 @@ const EditModal: React.FC<EditModalProps> = ({ open, values, onCancel, onSubmit
|
||||
)}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="status" label="状态" valuePropName="checked" initialValue={true}>
|
||||
<Switch checkedChildren="启用" unCheckedChildren="禁用" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
{access.hasPerms('cms:policyInfo:status') && (
|
||||
<Col span={12}>
|
||||
<Form.Item name="status" label="状态" valuePropName="checked" initialValue={true}>
|
||||
<Switch checkedChildren="启用" unCheckedChildren="禁用" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
)}
|
||||
<Col span={24}>
|
||||
<Form.Item name="remark" label="备注">
|
||||
<TextArea rows={2} placeholder="请输入备注" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { useAccess } from '@umijs/max';
|
||||
import { Button, message, Modal, Switch } from 'antd';
|
||||
import { Button, message, Modal, Switch, Tag } from 'antd';
|
||||
import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
|
||||
import { PlusOutlined, DeleteOutlined, FormOutlined, EyeOutlined } from '@ant-design/icons';
|
||||
import {
|
||||
@@ -137,14 +137,24 @@ const PolicyMgmt: React.FC = () => {
|
||||
'1': { text: '禁用', status: 'Error' },
|
||||
},
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<Switch
|
||||
checked={record.status === '0'}
|
||||
checkedChildren="启用"
|
||||
unCheckedChildren="禁用"
|
||||
onChange={(checked) => handleStatusChange(record.id, checked)}
|
||||
/>
|
||||
),
|
||||
render: (_, record) => {
|
||||
const canChangeStatus = access.hasPerms('cms:policyInfo:status');
|
||||
if (canChangeStatus) {
|
||||
return (
|
||||
<Switch
|
||||
checked={record.status === '0'}
|
||||
checkedChildren="启用"
|
||||
unCheckedChildren="禁用"
|
||||
onChange={(checked) => handleStatusChange(record.id, checked)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Tag color={record.status === '0' ? 'success' : 'error'}>
|
||||
{record.status === '0' ? '启用' : '禁用'}
|
||||
</Tag>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
|
||||
Reference in New Issue
Block a user