Commit 52a98657 authored by TZW's avatar TZW

11221744

parent 6b908e96
import React, { useState, useEffect, useReducer } from 'react';
import { Button, Tree, message } from 'antd';
import { roleTree, adminDataqueryAll } from '@/services/system';
import { doFetch } from '@/utils/doFetch';
import { useRequest } from 'ahooks';
const TreeNode = Tree.TreeNode;
const initState = {
pcTree: [],
pcCheckedKeys: [],
pcHalfCheckedKeys: [],
appTree: [],
appCheckedKeys: [],
appHalfCheckedKeys: [],
daauthTree: [],
daauthCheckkedKeys: [],
daauthHalfCheckedKeys: [],
};
function reducer(state, action) {
let { type } = action,
newState = {};
switch (type) {
case 'changePc':
newState = {
...state,
pcCheckedKeys: [...action.checkedKeys],
pcHalfCheckedKeys: [...action.halfCheckedKeys],
};
break;
case 'changeApp':
newState = {
...state,
appCheckedKeys: [...action.checkedKeys],
appHalfCheckedKeys: [...action.halfCheckedKeys],
};
break;
case 'changeDaauth':
newState = {
...state,
daauthCheckkedKeys: [...action.checkedKeys],
daauthHalfCheckedKeys: [...action.halfCheckedKeys],
};
break;
case 'reset':
newState = {
...state,
pcTree: [...action.pcTree],
pcCheckedKeys: [...action.pcCheckedKeys],
pcHalfCheckedKeys: [...action.pcHalfCheckedKeys],
// appTree: [...action.appTree],
// appCheckedKeys: [...action.appCheckedKeys],
// appHalfCheckedKeys: [...action.appHalfCheckedKeys]
};
break;
case 'daauth':
newState = {
...state,
daauthTree: action.nodeList ? [...action.nodeList] : [],
daauthCheckkedKeys: action.havepremIdList ? [...action.havepremIdList] : [],
daauthHalfCheckedKeys: action.haveParentIdList ? [...action.haveParentIdList] : [],
};
break;
}
return newState;
}
const Permissiontree = (props) => {
const { id, close, treeType } = props,
[state, dispatch] = useReducer(reducer, initState),
{
pcTree,
pcCheckedKeys,
pcHalfCheckedKeys,
appTree,
appCheckedKeys,
appHalfCheckedKeys,
daauthCheckkedKeys,
daauthHalfCheckedKeys,
daauthTree,
} = state;
const loop = (data) => {
return data.map((item) => {
if (item.children) {
return (
<TreeNode key={item.key} title={item.title}>
{loop(item.children)}
</TreeNode>
);
}
return <TreeNode key={item.key} title={item.title} />;
});
},
pcCheck = (checkedKeys, info) => {
dispatch({ type: 'changePc', checkedKeys, halfCheckedKeys: info.halfCheckedKeys });
},
appCheck = (checkedKeys, info) => {
dispatch({ type: 'changeApp', checkedKeys, halfCheckedKeys: info.halfCheckedKeys });
},
daauthCheck = (checkedKeys, info) => {
dispatch({ type: 'changeDaauth', checkedKeys, halfCheckedKeys: info.halfCheckedKeys });
},
{ run, loading } = useRequest(doFetch, {
manual: true,
onSuccess: (result, params) => {
if (result.code == '0000') {
message.success('权限配置成功!')
close();
}
},
});
useEffect(() => {
resetData();
}, []);
function resetData() {
if (!id) {
return;
}
if (treeType == 'auth') {
roleTree({ roleId: id }).then((res) => {
if (res.code == '0000') {
let data = res?.data || {};
const { pcTree, pcCheckedKeys, pcHalfCheckedKeys } = data;
dispatch({ type: 'reset', pcTree, pcCheckedKeys, pcHalfCheckedKeys });
}
});
} else {
// adminDataqueryAll({ roleId: id }).then(res => {
// if (res.code == "0000") {
// let data = res?.data || {};
// const { nodeList, havepremIdList, haveParentIdList } = data;
// dispatch({ type: "daauth", nodeList, havepremIdList, haveParentIdList })
// }
// })
}
}
const saveData = () => {
run({
url: '/sysRolePermission/save',
params: {
roleId: id,
permissionIds: [...pcCheckedKeys, ...pcHalfCheckedKeys],
},
});
};
return (
<div>
<div style={{ width: '100%', display: 'flex', overflow: 'hidden', minHeight: 100 }}>
{treeType == 'auth' ? (
<>
<div style={{ flex: 1, minHeight: 100 }}>
<h3 style={{ marginBottom: 16 }}>请配置角色权限:</h3>
<Tree
checkable
defaultExpandAll={false}
checkedKeys={pcCheckedKeys}
onCheck={pcCheck}
>
{loop(pcTree || [])}
</Tree>
</div>
{/* <div style={{ flex: 1, minHeight: 100 }}>
<div style={{ marginBottom: 10 }}>app权限:</div>
<Tree
checkable
defaultExpandAll={false}
checkedKeys={appCheckedKeys}
onCheck={appCheck}
>
{loop(appTree || [])}
</Tree>
</div> */}
</>
) : (
<Tree
checkable
defaultExpandAll={false}
checkedKeys={daauthCheckkedKeys}
onCheck={daauthCheck}
>
{loop(daauthTree || [])}
</Tree>
)}
</div>
<Button
loading={loading}
type="primary"
style={{ width: '100%', marginTop: 15 }}
onClick={saveData}
>
提交
</Button>
</div>
);
};
export default Permissiontree;
/* 用户管理 function getcolumns(setdrawer) {
* @Author: Li Hanlin return [
* @Date: 2022-11-09 14:44:44 {
* @Last Modified by: Li Hanlin title: '角色名称',
* @Last Modified time: 2022-11-18 15:43:51 dataIndex: 'roleName',
*/ width: 120,
key: 'roleName',
import * as React from 'react'; formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
import { useState, useMemo, useRef } from 'react'; },
import DrawerPro from '@/components/DrawerPro'; { title: '备注', hideInTable: true, dataIndex: 'remark', key: 'remarks' },
import AutoTable from '@/components/AutoTable'; ];
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { doFetch } from '@/utils/doFetch';
import { message } from 'antd';
function User(props) {
const actionRef = useRef(),
formRef = useRef();
const [drawer, setDrawer] = useState({
visible: false,
});
const urlParams = {
save: '/auth/sysFactory/saveOrUpdate',
remove: '/auth/sysFactory/delete',
list: '/auth/sysUser/queryList',
detail: '/auth/sysFactory/getById',
};
const detail = (text, row, _, action) => {
return (
<PremButton
btn={{
size: 'small',
type: 'link',
onClick: () => {
setDrawer((s) => ({
...s,
visible: true,
item: row,
title: '详情',
val: 'detail',
title: row.userName + '的详细信息',
}));
},
}}
>
详情
</PremButton>
);
};
const edit = (text, row, _, action) => {
return (
<PremButton
btn={{
size: 'small',
onClick: () => {
setDrawer((s) => ({
...s,
visible: true,
item: row,
title: '编辑',
val: 'edit',
onFinish: async (vals) => {
console.log(1);
let params = {
...vals,
id: row.id,
};
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('新增成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
}));
},
}}
>
编辑
</PremButton>
);
};
const remove = (text, row, _, action) => {
return (
<PremButton
pop={{
title: '是否删除该工厂?',
okText: '确认',
cancelText: '取消',
onConfirm: async () => {
let res = await doFetch({ url: urlParams.remove, params: { id: row.id } });
if (res.code === '0000') {
message.success('删除成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
}}
btn={{
size: 'small',
type: 'danger',
}}
>
删除
</PremButton>
);
};
const columns = useMemo(() => {
let defcolumn = getcolumns(setDrawer);
return defcolumn.concat({
title: '操作',
valueType: 'option',
width: 150,
render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
});
}, []);
return (
<div style={{ position: 'relative' }}>
<AutoTable
pagetitle={<h3 className="page-title">角色管理</h3>}
columns={columns}
path={urlParams.list}
actionRef={actionRef}
pageextra={'add'}
resizeable={false}
addconfig={{
// access: 'sysDepartment_save',
btn: {
type: 'primary',
disabled: false,
onClick: () => {
setDrawer((s) => ({
...s,
visible: true,
item: null,
detailpath: null,
title: '新增',
val: 'add',
onFinish: async (vals) => {
console.log(1);
let params = {
...vals,
};
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('新增成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
}));
},
},
}}
/>
<DrawerPro
fields={columns}
// detailpath={urlParams.detail}
// params={{ id: drawer?.item?.id }}
defaultFormValue={drawer?.item ?? {}}
formRef={formRef}
placement="right"
onClose={() => {
setDrawer((s) => ({
...s,
visible: false,
}));
}}
{...drawer}
/>
</div>
);
} }
export default User; export default getcolumns;
/* 角色管理
* @Author: Li Hanlin
* @Date: 2022-11-09 14:44:44
* @Last Modified by: Li Hanlin
* @Last Modified time: 2022-11-22 17:21:24
*/
import * as React from 'react'; import * as React from 'react';
import { useState, useMemo, useRef } from 'react'; import { useState, useMemo, useRef } from 'react';
import DrawerPro from '@/components/DrawerPro'; import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable'; import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton'; import PremButton from '@/components/PremButton';
import getcolumns from './columns'; import getcolumns from './columns';
import { doFetch } from '@/utils/doFetch';
import { message } from 'antd';
import { Drawer } from 'antd';
import PermissionTree from '@/components/PermissionTree/Permissiontree';
function Role(props) { function User(props) {
const actionRef = useRef(), const actionRef = useRef(),
formRef = useRef(); formRef = useRef();
const [drawer, setdrawer] = useState({ const [drawer, setDrawer] = useState({
visible: false, visible: false,
authorityOpen: false,
}); });
const urlParams = {
save: '/auth/sysFactory/saveOrUpdate',
remove: '/auth/sysFactory/delete',
list: '/auth/sysUser/queryList',
detail: '/auth/sysFactory/getById',
};
const detail = (text, row, _, action) => { const detail = (text, row, _, action) => {
return ( return (
<PremButton <PremButton
...@@ -19,7 +38,7 @@ function Role(props) { ...@@ -19,7 +38,7 @@ function Role(props) {
size: 'small', size: 'small',
type: 'link', type: 'link',
onClick: () => { onClick: () => {
setdrawer((s) => ({ setDrawer((s) => ({
...s, ...s,
visible: true, visible: true,
item: row, item: row,
...@@ -41,12 +60,31 @@ function Role(props) { ...@@ -41,12 +60,31 @@ function Role(props) {
btn={{ btn={{
size: 'small', size: 'small',
onClick: () => { onClick: () => {
setdrawer((s) => ({ setDrawer((s) => ({
...s, ...s,
visible: true, visible: true,
item: row, item: row,
title: '编辑', title: '编辑',
val: 'edit', val: 'edit',
onFinish: async (vals) => {
console.log(1);
let params = {
...vals,
id: row.id,
};
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('新增成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
})); }));
}, },
}} }}
...@@ -60,11 +98,19 @@ function Role(props) { ...@@ -60,11 +98,19 @@ function Role(props) {
return ( return (
<PremButton <PremButton
pop={{ pop={{
title: '是否删除该用户?', title: '是否删除该工厂?',
okText: '确认', okText: '确认',
cancelText: '取消', cancelText: '取消',
onConfirm: () => { onConfirm: async () => {
alert(0); let res = await doFetch({ url: urlParams.remove, params: { id: row.id } });
if (res.code === '0000') {
message.success('删除成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
}, },
}} }}
btn={{ btn={{
...@@ -77,41 +123,101 @@ function Role(props) { ...@@ -77,41 +123,101 @@ function Role(props) {
); );
}; };
// 权限配置
const authority = (text, row, _, action) => {
return (
<PremButton
btn={{
size: 'small',
onClick: () => {
// const { data } = doFetch({
// url: '/sysRolePermission/queryAll',
// params: { roleId: row.id },
// });
// console.log(data);
console.log(row);
setdrawer((s) => ({
...s,
authorityOpen: true,
item: row,
onFinish: async (vals) => {
console.log(vals);
let res = await doFetch({
url: '/sysEnterprise/save',
params: { ...vals },
});
console.log(res);
if (res.code === '0000') {
message.success('修改成功!');
setdrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
}));
},
}}
>
权限配置
</PremButton>
);
};
// 数据分权
const distribution = (text, row, _, action) => {};
const columns = useMemo(() => { const columns = useMemo(() => {
let defcolumn = getcolumns(setdrawer); let defcolumn = getcolumns(setDrawer);
return defcolumn.concat({ return defcolumn.concat({
title: '操作', title: '操作',
valueType: 'option', valueType: 'option',
width: 150, width: 150,
render: (text, row, _, action) => [ render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
detail(text, row, _, action),
edit(text, row, _, action),
remove(text, row, _, action),
],
}); });
}, []); }, []);
return ( return (
<div style={{ position: 'relative' }}> <div style={{ position: 'relative' }}>
<AutoTable <AutoTable
pagetitle="角色管理" pagetitle={<h3 className="page-title">用户管理</h3>}
columns={columns} columns={columns}
path="/ngic-auth/sysUser/query/page" path={urlParams.list}
actionRef={actionRef} actionRef={actionRef}
pageextra={'add'} pageextra={'add'}
resizeable={true} resizeable={false}
addconfig={{ addconfig={{
// access: 'sysDepartment_save', // access: 'sysDepartment_save',
btn: { btn: {
type: 'primary', type: 'primary',
disabled: false, disabled: false,
onClick: () => { onClick: () => {
setdrawer((s) => ({ setDrawer((s) => ({
...s, ...s,
visible: true, visible: true,
item: null, item: null,
detailpath: null,
title: '新增', title: '新增',
val: 'add', val: 'add',
onFinish: async (vals) => {
console.log(1);
let params = {
...vals,
};
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('新增成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
})); }));
}, },
}, },
...@@ -120,20 +226,45 @@ function Role(props) { ...@@ -120,20 +226,45 @@ function Role(props) {
<DrawerPro <DrawerPro
fields={columns} fields={columns}
detailpath="/ngic-auth/sysUser/query/detail" // detailpath={urlParams.detail}
params={{ id: drawer?.item?.id }} // params={{ id: drawer?.item?.id }}
defaultFormValue={drawer?.item ?? {}}
formRef={formRef} formRef={formRef}
placement="right" placement="right"
onClose={() => { onClose={() => {
setdrawer((s) => ({ setDrawer((s) => ({
...s, ...s,
visible: false, visible: false,
})); }));
}} }}
{...drawer} {...drawer}
/> />
<Drawer
title="角色权限"
onClose={() => {
setdrawer((s) => ({
...s,
authorityOpen: false,
}));
}}
open={drawer.authorityOpen}
>
<PermissionTree
id={drawer?.item?.id}
close={() => {
setdrawer((s) => ({
...s,
authorityOpen: false,
item: null,
}));
actionRef.current.reload();
}}
treeType="auth"
/>
</Drawer>
</div> </div>
); );
} }
export default Role; export default User;
...@@ -3,17 +3,19 @@ function getcolumns(setdrawer) { ...@@ -3,17 +3,19 @@ function getcolumns(setdrawer) {
{ {
title: '用户名', title: '用户名',
dataIndex: 'username', dataIndex: 'username',
width: 120,
key: 'username', key: 'username',
formItemProps: { rules: [{ required: true, message: '此项为必填项' }] }, formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
}, },
{ {
title: '姓名', title: '姓名',
dataIndex: 'fullName', dataIndex: 'fullName',
width: 100,
key: 'fullName', key: 'fullName',
formItemProps: { rules: [{ required: true, message: '此项为必填项' }] }, formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
}, },
{ title: '手机号', dataIndex: 'telephone', key: 'telephone' }, { title: '手机号', hideInTable: true, dataIndex: 'telephone', key: 'telephone' },
{ title: '邮箱', dataIndex: 'mailNo', key: 'mailNo' }, { title: '邮箱', dataIndex: 'mailNo', key: 'mailNo', hideInTable: true, search: false },
{ {
title: '公司名称', title: '公司名称',
align: 'center', align: 'center',
...@@ -40,8 +42,8 @@ function getcolumns(setdrawer) { ...@@ -40,8 +42,8 @@ function getcolumns(setdrawer) {
}, },
{ {
title: '负责工厂', title: '负责工厂',
dataIndex: 'factoryName', dataIndex: 'factoryNames',
key: 'factoryId', key: 'factoryNames',
width: 120, width: 120,
align: 'center', align: 'center',
valueType: 'select', valueType: 'select',
...@@ -50,7 +52,7 @@ function getcolumns(setdrawer) { ...@@ -50,7 +52,7 @@ function getcolumns(setdrawer) {
}, },
{ {
title: '负责车间', title: '负责车间',
dataIndex: 'shopName', dataIndex: 'shopNames',
align: 'center', align: 'center',
width: 120, width: 120,
valueType: 'select', valueType: 'select',
...@@ -93,10 +95,11 @@ function getcolumns(setdrawer) { ...@@ -93,10 +95,11 @@ function getcolumns(setdrawer) {
}, },
}, },
{ title: '角色配置', dataIndex: 'roleNames', key: 'roleNames' }, { title: '角色配置', dataIndex: 'roleNames', key: 'roleNames' },
{ title: '直属领导名称', dataIndex: 'parentName', key: 'parentId' }, { title: '直属领导', dataIndex: 'parentName', key: 'parentId' },
{ title: '状态', dataIndex: 'status', key: 'status' }, { title: '状态', hideInTable: true, dataIndex: 'status', key: 'status' },
{ title: '状态名', dataIndex: 'statusName', key: 'status', search: false }, { title: '状态', dataIndex: 'statusName', key: 'status', search: false },
{ title: '备注', dataIndex: 'remarks', key: 'remarks' }, { title: '备注', hideInTable: true, dataIndex: 'remarks', key: 'remarks' },
{ title: '个人图片', hideInTable: true, dataIndex: 'userImgList', key: 'userImgList' },
]; ];
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: Li Hanlin * @Author: Li Hanlin
* @Date: 2022-11-09 14:44:44 * @Date: 2022-11-09 14:44:44
* @Last Modified by: Li Hanlin * @Last Modified by: Li Hanlin
* @Last Modified time: 2022-11-18 14:23:58 * @Last Modified time: 2022-11-22 15:50:02
*/ */
import * as React from 'react'; import * as React from 'react';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment