AuthModal.jsx 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2021-12-23 17:51:09
 * @LastEditTime: 2022-03-18 10:07:06
 * @LastEditors: leizhe
 */
import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, notification, message, Radio, Checkbox, Space } from 'antd';
import { AddUserAuthSetting, GetUserAuthSet } from '@/services/database/api';
mayongxin's avatar
mayongxin committed
11
import SiteModal from '@/components/Modal/SiteModa';
mayongxin's avatar
mayongxin committed
12 13

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

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  useEffect(() => {
    currentUser.userID && visible;
    GetUserAuthSet({
      UserId: currentUser.userID,
    }).then(res => {
      if (res.code === 0) {
        setSelctValue(res.data);
      }
    });
  }, [currentUser]);
  const onTypeChange = value => {
    setSelctValue(value);
  };
  const onSubmit = () => {
    AddUserAuthSetting({ userId: currentUser.userID }).then(res => {
      if (res.code === 0) {
        message.info('提交成功');
      }
    });
  };
mayongxin's avatar
mayongxin committed
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
  return (
    <SiteModal
      title={title}
      visible={visible}
      onCancel={onCancel}
      onOk={onSubmit}
      okText="确认"
      cancelText="取消"
      width="800px"
    >
      <div style={{ width: '800px' }}>
        <Form form={form}>
          <Item label="数据权限" name="operate_type">
            <Radio.Group
              defaultValue={selectValue}
              options={plainOptions}
              onChange={onTypeChange}
            />
          </Item>
        </Form>
      </div>
    </SiteModal>
  );
};
export default AuthModal;