AuthModal.jsx 2.13 KB
Newer Older
mayongxin's avatar
mayongxin committed
1
import React, { useEffect, useState } from 'react'
2
import { Modal, Form, Input, notification, message, Radio, Checkbox, Space} from 'antd';
mayongxin's avatar
mayongxin committed
3
import { AddUserAuthSetting, GetUserAuthSet, } from '@/services/database/api'
mayongxin's avatar
mayongxin committed
4
import SiteModal from '@/components/Modal/SiteModa';
mayongxin's avatar
mayongxin committed
5 6 7 8



const AuthModal = props => {
mayongxin's avatar
mayongxin committed
9 10 11 12 13 14
    const plainOptions = [
        { label: '访客', value: 0 },
        { label: '普通用户', value: 1 },
        { label: '管理员', value: 2 },
        { label: '超级管理员', value: 3 },
    ];
mayongxin's avatar
mayongxin committed
15 16
    const [form] = Form.useForm();
    const { Item } = Form;
mayongxin's avatar
mayongxin committed
17 18
    const { title, visible, onCancel, onSelect, currentUser } = props;
    const [selectValue,setSelctValue] = useState(1)
mayongxin's avatar
mayongxin committed
19 20


mayongxin's avatar
mayongxin committed
21 22
    useEffect(() => {
        currentUser.userID && visible
mayongxin's avatar
mayongxin committed
23
        GetUserAuthSet({
mayongxin's avatar
mayongxin committed
24
            UserId: currentUser.userID
mayongxin's avatar
mayongxin committed
25
        }).then(
mayongxin's avatar
mayongxin committed
26
            res => {
皮倩雯's avatar
皮倩雯 committed
27
                if(res.code === 0){
mayongxin's avatar
mayongxin committed
28 29
                    setSelctValue(res.data)
                }
mayongxin's avatar
mayongxin committed
30 31
            }
        )
mayongxin's avatar
mayongxin committed
32 33 34
    }, [currentUser])
    const onTypeChange = (value) => {
        setSelctValue(value)
mayongxin's avatar
mayongxin committed
35 36
    }
    const onSubmit = () => {
mayongxin's avatar
mayongxin committed
37 38
        AddUserAuthSetting({userId:currentUser.userID}).then(
            res =>{
皮倩雯's avatar
皮倩雯 committed
39
                if(res.code === 0){
mayongxin's avatar
mayongxin committed
40 41 42 43
                    message.info("提交成功")
                }
            }
        )
mayongxin's avatar
mayongxin committed
44 45 46 47
    }


    return (
mayongxin's avatar
mayongxin committed
48
        <SiteModal
mayongxin's avatar
mayongxin committed
49 50 51 52 53 54
            title={title}
            visible={visible}
            onCancel={onCancel}
            onOk={onSubmit}
            okText="确认"
            cancelText="取消"
mayongxin's avatar
mayongxin committed
55
            width="800px"
mayongxin's avatar
mayongxin committed
56
        >
mayongxin's avatar
mayongxin committed
57
            <div style={{ width: '800px' }}>
mayongxin's avatar
mayongxin committed
58 59 60 61 62
                <Form form={form}>
                    <Item
                        label="数据权限"
                        name="operate_type"
                    >
63
                        
mayongxin's avatar
mayongxin committed
64 65
                        <Radio.Group
                            defaultValue={selectValue}
mayongxin's avatar
mayongxin committed
66 67 68
                            options={plainOptions}
                            onChange={onTypeChange}
                        />
69
                        
mayongxin's avatar
mayongxin committed
70 71 72 73
                    </Item>
                </Form>
            </div>
        </SiteModal>
mayongxin's avatar
mayongxin committed
74 75 76 77

    )
}
export default AuthModal