import BraftEditor from '@/components/BraftEditor';
|
import { sendRequest } from '@/utils/antdUtils';
|
import { PageContainer } from '@ant-design/pro-components';
|
import { Button, Card, Space } from 'antd';
|
import { useEffect, useState } from 'react';
|
import { Access, useAccess } from 'umi';
|
import { getDetail, edit } from './service';
|
|
const Agreement = () => {
|
const [info, setInfo] = useState({ content: '' });
|
const [type, setType] = useState(1); // 1=隐私协议 2=用户协议 3=注销协议
|
const [loading, setLoading] = useState(false)
|
const access = useAccess();
|
|
//获取协议内容
|
const getContent = (value) => {
|
setLoading(true)
|
getDetail({ type: value }).then((res) => {
|
|
if (res.code == 200) {
|
setLoading(false)
|
if (!res.msg) {
|
res.msg = {}
|
}
|
setInfo({ content: res.msg });
|
} else {
|
setLoading(false)
|
}
|
});
|
};
|
//切换协议
|
const changeType = (value) => {
|
if (value === type) return;
|
setType(value);
|
getContent(value);
|
};
|
const braftCallBack = (value) => {
|
// 监听富文本的值
|
let params = info;
|
params.content = value;
|
setInfo(params);
|
};
|
//保存
|
const save = async () => {
|
let obj = { type, content: info.content }
|
const staut = await sendRequest(getDetail, obj);
|
// if (staut) {
|
// getContent(type);
|
// }
|
};
|
useEffect(() => {
|
getContent(type);
|
}, []);
|
return (
|
<PageContainer loading={loading}>
|
<Card>
|
<Space style={{ marginBottom: '20px' }}>
|
{/* <Access accessible={access.agreement_userAgreement}> */}
|
<Button onClick={() => changeType(1)} type="primary" ghost={type == 1 ? false : true}>
|
用户协议
|
</Button>
|
{/* </Access> */}
|
{/* <Access accessible={access.agreement_PrivacyAgreement}> */}
|
<Button onClick={() => changeType(2)} type="primary" ghost={type == 2 ? false : true}>
|
隐私协议
|
</Button>
|
{/* </Access> */}
|
{/* <Access accessible={access.agreement_cancellationAgreement}> */}
|
<Button onClick={() => changeType(3)} type="primary" ghost={type == 3 ? false : true}>
|
注销协议
|
</Button>
|
{/* </Access> */}
|
</Space>
|
<BraftEditor data={info.content} resultCallback={braftCallBack} />
|
<Space
|
size="large"
|
style={{ marginTop: '20px', display: 'flex', justifyContent: 'center' }}
|
>
|
{/* <Access accessible={access.agreement_save}> */}
|
<Button onClick={save} type="primary">
|
保存
|
</Button>
|
{/* </Access> */}
|
</Space>
|
</Card>
|
</PageContainer>
|
);
|
};
|
export default Agreement;
|