HW преди 4 години
родител
ревизия
42f322cb76

+ 2 - 2
config/config.ts

@@ -14,14 +14,14 @@ export default defineConfig({
   },
   layout: {
     name: 'Ant Design Pro',
-    locale: true,
+    locale: false,
     siderWidth: 208,
     ...defaultSettings,
   },
   locale: {
     // default zh-CN
     default: 'zh-CN',
-    antd: true,
+    antd: false,
     // default true, when it is true, will use `navigator.language` overwrite default
     baseNavigator: true,
   },

+ 5 - 0
config/routes.ts

@@ -11,6 +11,11 @@
     access: 'jurisdiction',
   },
   {
+    path: '/roleManage',
+    component: './admin/user/roleManage',
+    access: 'roleManage',
+  },
+  {
     path: '/welcome',
     name: 'welcome',
     component: './Welcome',

+ 1 - 1
src/pages/ListTableList/components/UpdateForm.tsx

@@ -8,7 +8,7 @@ import {
   ProFormRadio,
   ProFormDateTimePicker,
 } from '@ant-design/pro-form';
-import { useIntl, FormattedMessage } from 'umi';
+import { useIntl } from 'umi';
 import { TableListItem } from '../data.d';
 export interface FormValueType extends Partial<TableListItem> {
   target?: string;

+ 1 - 1
src/pages/ListTableList/index.tsx

@@ -1,7 +1,7 @@
 import { PlusOutlined } from '@ant-design/icons';
 import { Button, Divider, message, Input, Drawer } from 'antd';
 import React, { useState, useRef } from 'react';
-import { useIntl, FormattedMessage } from 'umi';
+import { useIntl } from 'umi';
 import { PageContainer, FooterToolbar } from '@ant-design/pro-layout';
 import ProTable, { ProColumns, ActionType } from '@ant-design/pro-table';
 import ProDescriptions, { ProDescriptionsItemProps } from '@ant-design/pro-descriptions';

+ 159 - 0
src/pages/admin/user/roleManage/components/editRole.jsx

@@ -0,0 +1,159 @@
+import React,{Component} from 'react';
+import ProForm, {ModalForm, ProFormText} from "@ant-design/pro-form";
+import {addRole,getPermissions,getRolePermission} from '../services/API';
+import {Button, message,Tree,Form} from "antd";
+
+class EditRole extends Component{
+  constructor(props) {
+    super(props);
+    this.state={
+      permissionsList:[],
+      expandedKeys:'',
+      checkedKeys: '',
+      selectedKeys: '',
+      rolePermission: {},
+    }
+    this.finishAddRole = this.finishAddRole.bind(this);
+    this.onSelect = this.onSelect.bind(this);
+    this.onExpand = this.onExpand.bind(this);
+    this.onCheck = this.onCheck.bind(this);
+    this.getPermissionsList = this.getPermissionsList.bind(this);
+    this.handlePermissionsList = this.handlePermissionsList.bind(this);
+  }
+
+  finishAddRole= async (value)=>{
+    let obj = Object.assign({permissions:this.state.checkedKeys || []},value)
+    message.loading({content:'加载中...',key:'finishAddRole'})
+    const msg = await addRole({data:JSON.stringify(obj)});
+    if(msg.error.length === 0){
+      message.success({content:'添加成功',key:'finishAddRole',duration:2.5});
+      this.props.tableRef.current.reload();
+      this.props.onCancel();
+    }else{
+      message.error({content:msg.error[0].message,key:'finishAddRole',duration:2.5});
+    }
+  }
+
+  onExpand=(expandedKeys)=>{
+    this.setState({
+      expandedKeys:expandedKeys,
+      autoExpandParent:false,
+    })
+  }
+
+  onCheck=(checkedKeys)=>{
+    this.setState({
+      checkedKeys: checkedKeys
+    })
+  }
+
+  onSelect=(selectedKeys)=>{
+    this.setState({
+      selectedKeys: selectedKeys
+    })
+  }
+
+  getPermissionsList= async ()=>{
+    const msg = await getPermissions();
+    if(msg.error.length === 0){
+      let data = await this.handlePermissionsList(msg.data.one);
+      this.setState({
+        permissionsList: data
+      })
+    }else{
+      message.error(msg.error[0].message)
+    }
+  }
+
+  handlePermissionsList=(menuList)=>{
+    menuList.map((value)=>{
+      value.title = value.name;
+      value.key = value.id;
+      if(value.children){
+        this.handlePermissionsList(value.children);
+      }
+      return value
+    })
+    return menuList;
+  }
+
+  componentDidMount() {
+    this.getPermissionsList();
+  }
+
+  getRolePermission =async ()=>{
+    const msg = await getRolePermission(this.props.roleData.id);
+    if(msg.error.length === 0){
+      let idList=[];
+      msg.data.map((item)=>{
+        idList.push(
+          item.pid
+        )
+      })
+      this.setState({
+        rolePermission:msg.data,
+        checkedKeys:idList,
+      })
+      this.formRef.current.setFieldsValue({
+        roleName:msg.data[0].rname
+      });
+    }else{
+      message.error(msg.error[0].message);
+    }
+  }
+
+  componentDidUpdate(prevProps, prevState, snapshot) {
+    if(!prevProps.visible && this.props.roleData){
+      this.getRolePermission();
+    }
+  }
+
+
+  formRef = React.createRef();
+
+  render() {
+    const {roleData} = this.props;
+    return (
+      <ModalForm
+        formRef={this.formRef}
+        visible={this.props.visible}
+        preserve={false}
+        title={roleData?'编辑角色':'添加角色'}
+        modalProps={{
+          onCancel: (e) => {e.stopPropagation();this.props.onCancel();},
+        }}
+        onFinish={this.finishAddRole}
+      >
+        <ProForm.Group>
+          <ProFormText
+            rules={
+              [{
+                required: true,
+                message: '请输入角色名称!',
+              }]
+            }
+            width="xl"
+            name="roleName"
+            label="角色名称:"
+            placeholder="请输入角色名称"
+          />
+        </ProForm.Group>
+        <Form.Item name='tree'>
+          <Tree
+            checkable
+            onExpand={this.onExpand}
+            expandedKeys={this.state.expandedKeys}
+            autoExpandParent={this.state.autoExpandParent}
+            onCheck={this.onCheck}
+            checkedKeys={this.state.checkedKeys}
+            onSelect={this.onSelect}
+            selectedKeys={this.state.selectedKeys}
+            treeData={this.state.permissionsList}
+          />
+        </Form.Item>
+      </ModalForm>
+    )
+  }
+}
+
+export default EditRole;

+ 128 - 0
src/pages/admin/user/roleManage/index.jsx

@@ -0,0 +1,128 @@
+import React,{Component} from 'react';
+import {Button, message, Popconfirm, Table} from "antd";
+import DataTable from "@/components/common/DataTable";
+import EditRole from './components/editRole';
+import {PlusOutlined} from "@ant-design/icons";
+import {deleteRole} from './services/API';
+
+class RoleManage extends Component{
+  constructor(props) {
+    super(props);
+    this.state={
+      columns: [
+        {
+          title: '角色名称',
+          dataIndex: "roleName",
+          key: "roleName",
+          searchBool: true,
+        }, {
+          title: '创建人',
+          dataIndex: 'creater',
+          key: 'creater',
+        }, {
+          title: '创建时间',
+          dataIndex: 'createTime',
+          key: 'createTime',
+        },
+        {
+          title: '离职转交配置',
+          dataIndex: 'id',
+          key: 'id',
+          render: (text ,record, key ,action)=>{
+            return (
+              <Button type='primary'>
+                离职转交配置
+              </Button>
+            )
+          }
+        },
+        {
+          title: '操作',
+          dataIndex: 'id',
+          key: 'deleteRole',
+          render: (text ,record, key ,action)=>{
+            return (
+              <Popconfirm
+                title="是否真的删除?"
+                onConfirm={(e)=>{e.stopPropagation();this.deleteRole(text,action)}}
+                okText="确认"
+                cancelText="取消"
+                placement="topLeft">
+                  <Button type="primary" danger onClick={(e)=>e.stopPropagation()}>
+                    删除
+                  </Button>
+              </Popconfirm>
+            )
+          }
+        }
+      ],
+      visible: false,
+      roleData: '',
+    }
+  }
+
+  deleteRole= async (id,action)=>{
+    message.loading({content:'删除中...',key:'deleteRole'})
+    const msg = await deleteRole({data:JSON.stringify([id])});
+    if(msg.error.length === 0){
+      message.success({content:'删除成功',key:'deleteRole',duration:2.5});
+      action.reload();
+    }else{
+      message.error({content:msg.error[0].message,key:'deleteRole',duration:2.5});
+    }
+  }
+
+
+
+  render() {
+    const ref = React.createRef();
+    return(
+      <>
+        <DataTable
+          ref={ref}
+          headerTitle='角色管理'
+          url='/api/admin/roles'
+          method='post'
+          rowKey='id'
+          columns={this.state.columns}
+          search={{
+            filterType: 'query',
+            labelWidth: 'auto',
+            defaultCollapsed: false,
+          }}
+          onRow={(record)=>({
+            onClick:(e)=>{
+              e.stopPropagation();
+              this.setState({
+                visible:true,
+                roleData:record,
+              })
+            }
+          })}
+          toolBarRender={[
+            <Button
+              type="primary"
+              key='addRoles'
+              icon={<PlusOutlined />}
+              onClick={(e)=>{e.stopPropagation();this.setState({visible:true})}}>
+              新增角色
+            </Button>
+          ]}
+        />
+        <EditRole
+          key='addRoles'
+          roleData={this.state.roleData}
+          tableRef={ref}
+          visible={this.state.visible}
+          onCancel={()=>{
+            this.setState({
+              visible: false,
+              roleData: '',
+            })
+          }}/>
+      </>
+    )
+  }
+}
+
+export default RoleManage;

+ 31 - 0
src/pages/admin/user/roleManage/services/API.ts

@@ -0,0 +1,31 @@
+import { request } from 'umi';
+
+export async function addRole(data: string){
+  return request('/api/admin/role',{
+    method:'post',
+    data,
+  });
+}
+
+export async function getPermissions(){
+  return request('/api/admin/permissions',{
+    method:'post',
+  });
+}
+
+export async function deleteRole(data: string){
+  return request('/api/admin/role/delete',{
+    method:'post',
+    data
+  });
+}
+
+export async function getRolePermission(id: string){
+  return request('/api/admin/role/rolePermission',{
+    method:'post',
+    data:{
+      id
+    }
+  });
+}
+