董国庆
2026-02-24 4a180c0ef43733522a0d39aec6289f4a7bdf23bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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;