diff --git a/src/api/system/role.ts b/src/api/system/role.ts new file mode 100644 index 0000000..506c65f --- /dev/null +++ b/src/api/system/role.ts @@ -0,0 +1,79 @@ +import { number } from "echarts"; +import request from "../../utils/request"; +interface paramsType { + createTime?: string, + dataScope?: string, + deptIds?: any[], + menuIds?: any[], + roleId?: number, + roleKey?: string, + roleName?: string, + state?: string, + endTime?: string, + startTime?: string, + pageNum?: number, + pageSize?: number +} +export const getRolesDataAPI = (params: paramsType) => { + const { endTime, roleKey, roleName, startTime, state, pageNum, pageSize } = params + // console.log('API',params); + + return request({ + url: '/admin/role', + method: 'get', + params: { + endTime, + roleKey, + roleName, + startTime, + state, + pageNum, + pageSize + } + }) +} +export const delRoleAPI = (params: paramsType) => { + let { roleId } = params + console.log(roleId); + + return request({ + url: `/admin/role/${roleId}`, + method: 'delete', + }) +} +export const getMenuLiseAPI = () => { + + return request({ + url: '/admin/menu', + method: 'get', + + }) +} +export const addRoleAPI = (data:any) => { + // data.menuIds=[] + console.log('addAPI',data); + return request({ + url: `/admin/role`, + method: 'post', + data + }) +} +export const getRoleAPI = (params:paramsType) => { + // data.menuIds=[] + const {roleId}=params + + return request({ + url: `/admin/role/${roleId}`, + method: 'get', + }) +} +export const setRoleDataAPI = (data:any) => { + // data.menuIds=[] + // const {roleId}=params + + return request({ + url: `/admin/role`, + method: 'put', + data:data + }) +} \ No newline at end of file diff --git a/src/view/system/role/RoleTable/index.scss b/src/view/system/role/RoleTable/index.scss new file mode 100644 index 0000000..7de746e --- /dev/null +++ b/src/view/system/role/RoleTable/index.scss @@ -0,0 +1,35 @@ +.tablebox{ + table{ + thead{ + th::before{ + + } + tr{ + .ant-table-cell{ + background: white; + color:#909399 + } + + } + } + tbody{ + tr{ + .ant-table-cell{ + background: white; + color:#606266 + } + + } + } + } + .ant-table-cell{ + button:focus + { + outline: none; + } + button:hover + { + border: 0px rgb(250, 250, 250); + } + } +} \ No newline at end of file diff --git a/src/view/system/role/RoleTable/index.tsx b/src/view/system/role/RoleTable/index.tsx new file mode 100644 index 0000000..c9b6b7e --- /dev/null +++ b/src/view/system/role/RoleTable/index.tsx @@ -0,0 +1,408 @@ +import React, { useEffect ,useMemo} from 'react' +import { useState } from 'react'; +import { Space, Table, Tag, Button, Pagination ,Modal,message ,Form,Radio,Input,InputNumber,Tree} from 'antd'; +import type { ColumnsType } from 'antd/es/table'; +import './index.scss' +import { getRolesDataAPI, delRoleAPI ,getMenuLiseAPI,getRoleAPI,setRoleDataAPI} from '../../../../api/system/role.ts' +import { number } from 'echarts' +import { ExclamationCircleFilled } from '@ant-design/icons'; +const { confirm } = Modal +interface getValueType { + valueSch: any +} +interface Values { + title: string; + description: string; + modifier: string; +} +interface CollectionCreateFormProps { + open: boolean; + onCreate: (values: Values) => void; + onCancel: () => void; +} +const fieldNames = { + key: 'menuId', + title: 'menuName', + value:'menuId', + children: 'children' +} +let treeData:any=[] +let thisrole:any={} +const CollectionCreateForm: React.FC = ({ + open, + onCreate, + onCancel, +}) => { + const [form] = Form.useForm(); + form.setFieldsValue({...thisrole}) + const [menulist, setMenulist] = useState([]) + const getMenuList = async () => { + try { + let menul = await getMenuLiseAPI() + treeData = menul.data + setMenulist(menul.data) + } catch (error) { + console.log(error); + + } + + } + const [expandedKeys, setExpandedKeys] = useState([]); + const [checkedKeys, setCheckedKeys] = useState([]); + const [selectedKeys, setSelectedKeys] = useState([]); + const [autoExpandParent, setAutoExpandParent] = useState(true); + + const onExpand = (expandedKeysValue: React.Key[]) => { + console.log('onExpand', expandedKeysValue); + // if not set autoExpandParent to false, if children expanded, parent can not collapse. + // or, you can remove all expanded children keys. + setExpandedKeys(expandedKeysValue); + setAutoExpandParent(false); + }; + const onCheck = (checkedKeysValue: any) => { + console.log('onCheck', checkedKeysValue); + form.setFieldsValue({menuIds:checkedKeysValue}) + setCheckedKeys(checkedKeysValue); + }; + + const onSelect = (selectedKeysValue: React.Key[], info: any) => { + console.log('onSelect', info); + + setSelectedKeys(selectedKeysValue); + }; + + useEffect(() => { + getMenuList() + form.setFieldsValue({menuIds:thisrole.menuIds}) + }, []) + + return ( + { + form + .validateFields() + .then((values) => { + form.resetFields() + onCreate(values); + setSelectedKeys([]) + }) + .catch((info) => { + console.log('Validate Failed:', info); + }); + }} + > +
+ + + + + + + + + + + + + 所有数据权限 + 自定义数据权限 + 本部门数据权限 + 本部门及以下数据权限 + + + + + 正常 + 停用 + + + + + +
+
+ ); +}; +const RoleTable: React.FC = ({ valueSch }) => { + const [messageApi,contextHolder]=message.useMessage(); + console.log('111', valueSch); + interface DataType { + createTime: string, + dataScope: string, + deptIds: any[], + menuIds: any[], + roleId: number, + roleKey: string, + roleName: string, + roleSort: string, + state: string, + updateTime: string, + key?: number, + total?: number + } + let [queryParams,setQueryParams]=useState({ + roleKey: undefined, + roleName: undefined, + state: undefined, + endTime: undefined, + startTime: undefined, + pageNum: undefined, + pageSize: undefined + }) + + // let queryParams: any = { + // roleKey: undefined, + // roleName: undefined, + // state: undefined, + // endTime: undefined, + // startTime: undefined, + // pageNum: undefined, + // pageSize: undefined + // } + + const handleClickDel = (role: DataType) => { + console.log(role); + let { roleId } = role + del(roleId); + } + const showDeleteConfirm = (role:any) => { + console.log(role); + + confirm({ + title: '系统提示', + icon: , + content: `确定删除角色名称为${role.roleName}的数据吗`, + okText: '确定', + okType: 'danger', + cancelText: '取消', + onOk() { + handleClickDel(role); + }, + onCancel() { + console.log('Cancel'); + }, + }); + }; + const del = async (roleId: number) => { + try { + let { code } = await delRoleAPI({ roleId }) + if (code === 1000) { + console.log('del',valueSch); + messageApi.open({ + type: 'success', + content: '操作成功', + }); + getRoleData1({pageNum:count}) + } + } catch (error) { + console.log(error); + } + } + + const setRoleData=async(role:any)=>{ + // const {roleId,roleKey,roleName,roleSort,dataScope,state,meunIds}=role + thisrole=role + try { + let { code ,data} = await getRoleAPI(role) + if (code === 1000) { + console.log('role:',data); + thisrole=data + } + } catch (error) { + console.log(error); + } + setOpen(true); + } + const columns: ColumnsType = [ + { + title: '序号', + dataIndex: 'key', + key: 'key', + }, + { + title: '角色名称', + dataIndex: 'roleName', + key: 'roleName', + }, + { + title: '角色权限', + dataIndex: 'roleKey', + key: 'roleKey', + }, + { + title: '数据范围', + key: 'dataScope', + dataIndex: 'dataScope', + render:(text)=>{ + switch(text){ + case '1': + return <>所有数据权限 + case '2': + return <>自定义数据权限 + case '3': + return <>本部门数据权限 + default: + return <>本部门及以下数据权限 + } + } + }, + { + title: '显示顺序', + key: 'roleSort', + dataIndex: 'roleSort' + }, + { + title: '状态', + key: 'state', + dataIndex: 'state', + render: (text) => ( + <>{ + text === '0' + ? + 正常 + + : + 停用 + + } + + ) + }, + { + title: '创建时间', + key: 'createTime', + dataIndex: 'createTime', + }, + { + title: '操作', + key: '', + dataIndex: '', + render: (text) => ( + <> + + {/* */} + + + + ), + } + ]; + let [data, setData] = useState([]) + let [total, setTotal] = useState(0) + const getRoleData1 = async (queryParams: any) => { + try { + const { code, data } = await getRolesDataAPI(queryParams) + if (code === 1000) { + const sortData=data.rows.sort((a:DataType,b:DataType)=>parseInt(a.roleSort)-parseInt(b.roleSort)) + sortData.forEach((element: DataType, i: number) => { + element.key = i + 1; + }); + setData(sortData) + setTotal(data.total) + } + } catch (err: any) { + console.log(err); + } + } + let [count, setCount] = useState(1) + const change = (page: number, pageSize: number) => { + console.log(page, pageSize); + queryParams={...queryParams,pageNum:page,pageSize} + // setQueryParams({...queryParams,pageNum:page,pageSize}) + console.log(queryParams); + getRoleData1(queryParams) + setCount(page) + } + const [open, setOpen] = useState(false); + const setDataapi=async(values:any)=>{ + try { + console.log('ssssss',values); + let {code}=await setRoleDataAPI(values) + if(code===1000){ + messageApi.open({ + type: 'success', + content: '操作成功', + }); + } + } catch (error) { + console.log(error); + + } + } + const onCreate = (values: any) => { + // values.menuIds=[] + values={...thisrole,...values} + console.log('Received values of form: ', values); + setDataapi(values) + getRoleData1({pageNum:count}) + setOpen(false); + }; + useEffect(() => { + // setQueryParams({...queryParams,...valueSch}) + queryParams={...queryParams,...valueSch,pageNum:count} + // setCount(1) + getRoleData1(queryParams); + // console.log(queryParams); + }, [valueSch]) + return ( + +
+ {contextHolder} + + change(page, pageSize)} + showTotal={(total) => `共 ${total} 条`} + /> + { + setOpen(false); + }} + /> + + ) +} +export default RoleTable \ No newline at end of file diff --git a/src/view/system/role/Search/index.scss b/src/view/system/role/Search/index.scss new file mode 100644 index 0000000..2802d22 --- /dev/null +++ b/src/view/system/role/Search/index.scss @@ -0,0 +1,28 @@ +.SearchBox{ + display: flex; + flex-wrap: wrap; + .ipt{ + margin-top: 10px; + margin-right: 10px; + height: 32px; + line-height: 32px; + display: flex; + span{ + font-weight: 700; + // line-height: 32px; + padding-right: 12px; + // color: #606266; + } + .item,input{ + flex: 1; + // font-weight: 300; + margin-right: 40px; + } + } + .btn{ + button{ + margin-right: 15px; + } + margin-top: 10px; + } +} \ No newline at end of file diff --git a/src/view/system/role/Search/index.tsx b/src/view/system/role/Search/index.tsx new file mode 100644 index 0000000..baac513 --- /dev/null +++ b/src/view/system/role/Search/index.tsx @@ -0,0 +1,121 @@ +import React, { useState ,useContext} from "react"; +import { Button, Input, Select, DatePicker, Space } from "antd"; +import type { DatePickerProps, RangePickerProps } from 'antd/es/date-picker'; +import './index.scss' +// import { valueType } from "antd/es/statistic/utils"; +import { SyncOutlined,SearchOutlined } from '@ant-design/icons'; +interface getValueType +{ + getValue:(value:any)=>void +} +const Serach:React.FC=({getValue})=>{ + const { RangePicker } = DatePicker + let [value, setValue] = useState({ + roleName: undefined, roleKey: undefined, startTime: undefined, state: undefined,endTime:undefined + }) + const handlClickSerach = () => { + console.log(value); + getValue(value); + } + const onDateChange = ( + valueDate: DatePickerProps['value'] | RangePickerProps['value'], + dateString: [string, string] | string, + ) => { + + setValue({...value,startTime:dateString[0]+':00',endTime:dateString[1]+':00'}) + }; + const onOk = (value: DatePickerProps['value'] | RangePickerProps['value']) => { + console.log('onOk: ', value); + }; + const handlClickSerachNew = () => { + + value={ + roleName: undefined, roleKey: undefined, startTime: undefined, state: undefined,endTime:undefined + } + setValue(value) + getValue(value) + } + // Filter `option.label` match the user type `input` + const filterOption = (input: string, option?: { label: string; value: string }) => + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()); + + interface valueType { + roleName: string | undefined, + roleKey: string | undefined, + state: string | undefined, + startTime: string | undefined, + endTime: string | undefined + } + const onStateChange = (values: string) => { + setValue({ ...value, state: values }) + // console.log(value); + + }; + const onSearch = (value: string) => { + console.log('search:', value); + }; + return ( +
+
+ 角色名称 +
+ { + setValue({ ...value, roleName: e.target.value }) + // console.log(value); + + }} /> +
+
+
+ 权限字符 +
+ { + setValue({ ...value, roleKey: e.target.value }) + }} /> +
+
+
+ 状态 +
+ + + + + + + + + + + + 所有数据权限 + 自定义数据权限 + 本部门数据权限 + 本部门及以下数据权限 + + + + + 正常 + 停用 + + + + {/* */} + + + + + ); +}; + +const Newadd: React.FC= () => { + const [messageApi,contextHolder]=message.useMessage(); + const [open, setOpen] = useState(false); + const postAdd=async(value:any)=>{ + try { + let {code}=await addRoleAPI(value); + console.log(code); + + if(code===1000){ + console.log('success'); + } + else if(code===2000){ + console.log('重名'); + + } + } catch (error) { + + } + } + const onCreate = (values: any) => { + // values.menuIds=[] + console.log('Received values of form: ', values); + messageApi.open({ + type: 'success', + content: '操作成功', + }); + postAdd(values) + setOpen(false); + }; + + return ( +
+ {contextHolder} + + { + setOpen(false); + }} + /> +
+ ); +}; + +export default Newadd; \ No newline at end of file