Commit 9a9fadc9 authored by 李腾's avatar 李腾

feat: 新增小程序权限过滤处理&&优化系统管理页面细节

parent eaa6b851
import { getMenuData } from '@/services/menu'; import { getMenuData } from '@/services/menu';
import { APPLETS_PERMISSION_IDENTIFIER } from '@/utils/constants';
export const filterPermission = list => { export const filterPermission = list => {
const permissionData = {}; const permissionData = {};
...@@ -46,7 +47,12 @@ const MenuModel = { ...@@ -46,7 +47,12 @@ const MenuModel = {
const value = []; const value = [];
const data = [...tableData]; const data = [...tableData];
data data
.filter(item => item.node && item.node.type.value < 3) .filter(
item =>
item.node &&
item.node.code !== APPLETS_PERMISSION_IDENTIFIER &&
item.node.type.value < 3,
)
.forEach(item => { .forEach(item => {
let obj = {}; let obj = {};
obj = { ...item.node }; obj = { ...item.node };
......
import React, { useRef, useState, useEffect } from 'react'; import React, { useRef, useState, useEffect } from 'react';
import { Input, Checkbox, Button, notification } from 'antd'; import { Input, Checkbox, Button, notification, Spin } from 'antd';
import { Form } from '@ant-design/compatible'; import { Form } from '@ant-design/compatible';
import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { PageHeaderWrapper } from '@ant-design/pro-layout';
import RolePermissionsModal from '../components/RolePermissionsModal'; import RolePermissionsModal from '../components/RolePermissionsModal';
import style from './index.less'; import style from './index.less';
import { getRoleList, addUser } from '../../service'; import { getRoleList, addUser, getUserDetail } from '../../service';
import { shopGetBySupplierId } from '@/pages/ServiceGoods/service'; import { shopGetBySupplierId } from '@/pages/ServiceGoods/service';
const AddUser = props => { const AddUser = props => {
const { getFieldDecorator, validateFields, getFieldValue } = props.form; const { getFieldDecorator, validateFields, getFieldValue, setFieldsValue } = props.form;
const { id } = props.location.query; const { id } = props.location.query;
const [title, setTitle] = useState('新增用户'); const [title, setTitle] = useState('新增用户');
const [inputType, setInputType] = useState('text'); const [inputType, setInputType] = useState('text');
const [confirmInputType, setConfirmInputType] = useState('text'); const [confirmInputType, setConfirmInputType] = useState('text');
const [roleList, setRoleList] = useState([]); const [roleList, setRoleList] = useState([]);
const [supplierList, setSupplierList] = useState([]); const [supplierList, setSupplierList] = useState([]);
const [detailInfo, setDetailInfo] = useState({});
const [loading, setLoading] = useState(false);
const rolePermissionsModalRef = useRef(); const rolePermissionsModalRef = useRef();
...@@ -51,7 +53,7 @@ const AddUser = props => { ...@@ -51,7 +53,7 @@ const AddUser = props => {
{ required: true, message: '请确认登录密码' }, { required: true, message: '请确认登录密码' },
{ validator: handleConfirmPassword, message: '两次密码不一致' }, { validator: handleConfirmPassword, message: '两次密码不一致' },
], ],
role: [{ required: true, type: 'array', message: '请选择用户角色' }], roleId: [{ required: true, type: 'array', message: '请选择用户角色' }],
}; };
// 角色权限 modal // 角色权限 modal
...@@ -60,10 +62,8 @@ const AddUser = props => { ...@@ -60,10 +62,8 @@ const AddUser = props => {
}; };
// 获取所有门店列表 // 获取所有门店列表
const getAllSupplier = async () => { const getAllSupplier = res => {
const res = await shopGetBySupplierId(); if (res.code !== '0000') {
console.log(res);
if (res.code !== 2000) {
notification.warning({ notification.warning({
message: res.detail, message: res.detail,
}); });
...@@ -73,13 +73,7 @@ const AddUser = props => { ...@@ -73,13 +73,7 @@ const AddUser = props => {
}; };
// 获取所有角色列表 // 获取所有角色列表
const getAllRoleList = async () => { const getAllRoleList = res => {
const params = {
page: 1,
size: 1000,
};
const res = await getRoleList(params);
if (res.code !== 2000) { if (res.code !== 2000) {
notification.warning({ message: res.detail }); notification.warning({ message: res.detail });
return; return;
...@@ -89,6 +83,25 @@ const AddUser = props => { ...@@ -89,6 +83,25 @@ const AddUser = props => {
setRoleList(content); setRoleList(content);
}; };
// 获取账户详情
const getAccountDetail = res => {
setLoading(false);
if (res.code !== 2000) {
notification.warning({ message: res.detail });
return;
}
console.log(res);
setDetailInfo(res.data);
const { account, name, password } = res.data;
setFieldsValue({
account,
name,
password,
confirmPassword: password,
roleId: [],
});
};
// 用户角色多选框 // 用户角色多选框
const userRoleCheckbox = () => const userRoleCheckbox = () =>
roleList.map(item => ( roleList.map(item => (
...@@ -135,9 +148,26 @@ const AddUser = props => { ...@@ -135,9 +148,26 @@ const AddUser = props => {
} }
}; };
const initData = async () => {
const roleListParams = {
page: 1,
size: 1000,
};
setLoading(true);
const roleListRes = await getRoleList(roleListParams);
const supplierListRes = await shopGetBySupplierId();
let accountDetailRes = null;
if (id) {
accountDetailRes = await getUserDetail({ id });
getAccountDetail(accountDetailRes);
}
setLoading(false);
getAllRoleList(roleListRes);
getAllSupplier(supplierListRes);
};
useEffect(() => { useEffect(() => {
getAllRoleList(); initData();
getAllSupplier();
if (id) { if (id) {
setTitle('编辑用户'); setTitle('编辑用户');
} }
...@@ -146,10 +176,11 @@ const AddUser = props => { ...@@ -146,10 +176,11 @@ const AddUser = props => {
return ( return (
<PageHeaderWrapper title={title}> <PageHeaderWrapper title={title}>
<div className={style['user-info']}> <div className={style['user-info']}>
<Spin spinning={loading}>
<Form className={style['user-info--form']} {...formLayout}> <Form className={style['user-info--form']} {...formLayout}>
<Form.Item label="用户名" extra="限35字符以内,限英文/数字/“@”“ .”"> <Form.Item label="用户名" extra="限35字符以内,限英文/数字/“@”“ .”">
{getFieldDecorator('account', rulesHandler('account'))( {getFieldDecorator('account', rulesHandler('account'))(
<Input placeholder="请输入用户名" maxLength={35} />, <Input disabled={!!id} placeholder="请输入用户名" maxLength={35} />,
)} )}
</Form.Item> </Form.Item>
<Form.Item label="姓名" extra="限10字符以内"> <Form.Item label="姓名" extra="限10字符以内">
...@@ -160,6 +191,7 @@ const AddUser = props => { ...@@ -160,6 +191,7 @@ const AddUser = props => {
<Form.Item label="初始密码" extra="限13-18字符,包含大小写字母、数字和特殊字符"> <Form.Item label="初始密码" extra="限13-18字符,包含大小写字母、数字和特殊字符">
{getFieldDecorator('password', rulesHandler('password'))( {getFieldDecorator('password', rulesHandler('password'))(
<Input <Input
disabled={!!id}
type={inputType} type={inputType}
onChange={e => handlePasswordChange(e, setInputType)} onChange={e => handlePasswordChange(e, setInputType)}
placeholder="请设置登录密码" placeholder="请设置登录密码"
...@@ -169,6 +201,7 @@ const AddUser = props => { ...@@ -169,6 +201,7 @@ const AddUser = props => {
<Form.Item label="确认密码"> <Form.Item label="确认密码">
{getFieldDecorator('confirmPassword', rulesHandler('confirmPassword'))( {getFieldDecorator('confirmPassword', rulesHandler('confirmPassword'))(
<Input <Input
disabled={!!id}
type={confirmInputType} type={confirmInputType}
onChange={e => handlePasswordChange(e, setConfirmInputType)} onChange={e => handlePasswordChange(e, setConfirmInputType)}
placeholder="请确认登录密码" placeholder="请确认登录密码"
...@@ -178,7 +211,7 @@ const AddUser = props => { ...@@ -178,7 +211,7 @@ const AddUser = props => {
<Form.Item label="选择门店" extra="仅限POP商家设置"> <Form.Item label="选择门店" extra="仅限POP商家设置">
{getFieldDecorator('store', rulesHandler('store', []))( {getFieldDecorator('store', rulesHandler('store', []))(
supplierList.length ? ( supplierList.length ? (
<Checkbox.Group style={{ width: '100%' }}> <Checkbox.Group disabled={!!id} style={{ width: '100%' }}>
<Checkbox value="1">门店1</Checkbox> <Checkbox value="1">门店1</Checkbox>
<Checkbox value="2">门店2</Checkbox> <Checkbox value="2">门店2</Checkbox>
</Checkbox.Group> </Checkbox.Group>
...@@ -188,7 +221,7 @@ const AddUser = props => { ...@@ -188,7 +221,7 @@ const AddUser = props => {
)} )}
</Form.Item> </Form.Item>
<Form.Item label="用户角色"> <Form.Item label="用户角色">
{getFieldDecorator('organization', rulesHandler('organization'))( {getFieldDecorator('roleId', rulesHandler('roleId'))(
<Checkbox.Group style={{ width: '100%' }}>{userRoleCheckbox()}</Checkbox.Group>, <Checkbox.Group style={{ width: '100%' }}>{userRoleCheckbox()}</Checkbox.Group>,
)} )}
</Form.Item> </Form.Item>
...@@ -202,6 +235,7 @@ const AddUser = props => { ...@@ -202,6 +235,7 @@ const AddUser = props => {
</Button> </Button>
</Form.Item> </Form.Item>
</Form> </Form>
</Spin>
</div> </div>
<RolePermissionsModal ref={rolePermissionsModalRef} /> <RolePermissionsModal ref={rolePermissionsModalRef} />
</PageHeaderWrapper> </PageHeaderWrapper>
......
import React, { forwardRef, useImperativeHandle, useState, useRef, useEffect } from 'react'; import React, { forwardRef, useImperativeHandle, useState, useRef, useEffect } from 'react';
import { Modal, Input } from 'antd'; import { Modal, Input, notification } from 'antd';
import { Form } from '@ant-design/compatible'; import { Form } from '@ant-design/compatible';
import { resetPassword } from '../../../service'; import { resetPassword } from '../../../service';
...@@ -101,6 +101,7 @@ const ResetPasswordModal = (props, ref) => { ...@@ -101,6 +101,7 @@ const ResetPasswordModal = (props, ref) => {
const onCancel = () => { const onCancel = () => {
setVisible(false); setVisible(false);
setConfirmLoading(false);
formRef.current.resetFields(); formRef.current.resetFields();
}; };
...@@ -111,16 +112,24 @@ const ResetPasswordModal = (props, ref) => { ...@@ -111,16 +112,24 @@ const ResetPasswordModal = (props, ref) => {
return; return;
} }
setConfirmLoading(true); setConfirmLoading(true);
const { password } = fieldsValue;
const params = { const params = {
id: record.id, id: record.id,
...fieldsValue, password,
}; };
const res = await resetPassword(); const res = await resetPassword(params);
setConfirmLoading(false);
setTimeout(() => { if (res.code !== 2000) {
notification.warning({
message: res.detail,
});
return;
}
notification.success({
message: '重置成功',
});
setConfirmLoading(false); setConfirmLoading(false);
onCancel(); onCancel();
}, 2000);
}); });
}; };
......
...@@ -21,6 +21,7 @@ const RolePermissionsModal = (props, ref) => { ...@@ -21,6 +21,7 @@ const RolePermissionsModal = (props, ref) => {
})); }));
const modalProps = { const modalProps = {
width: 600,
title: '查看角色', title: '查看角色',
visible, visible,
footer: null, footer: null,
...@@ -31,6 +32,9 @@ const RolePermissionsModal = (props, ref) => { ...@@ -31,6 +32,9 @@ const RolePermissionsModal = (props, ref) => {
id: roleInfo.id, id: roleInfo.id,
submittable: false, submittable: false,
readyonly: true, readyonly: true,
wrapperCol: {
span: 18,
},
}; };
console.log(roleProps); console.log(roleProps);
......
...@@ -40,12 +40,11 @@ export const getColumns = props => { ...@@ -40,12 +40,11 @@ export const getColumns = props => {
title: '状态', title: '状态',
dataIndex: 'status', dataIndex: 'status',
width: 150, width: 150,
initialValue: 'all', initialValue: '3',
valueEnum: { valueEnum: {
all: { text: '全部', status: '' }, all: { text: '全部', status: '' },
close: { text: '使用中', status: 0 }, close: { text: '使用中', status: 2 },
running: { text: '已禁用', status: 1 }, running: { text: '已禁用', status: 3 },
online: { text: '已删除', status: 2 },
}, },
render: value => value.name, render: value => value.name,
}, },
......
...@@ -27,19 +27,17 @@ const Account = props => { ...@@ -27,19 +27,17 @@ const Account = props => {
const resetPasswordModal = useRef(); const resetPasswordModal = useRef();
// 新增编辑 // 新增编辑
const toUserInfo = (record = {}) => { const toUserInfo = ({ id } = {}) => {
const { id } = record; const query = id ? { id } : {};
history.push({ history.push({
pathname: '/systemManage/account/userInfo', pathname: '/systemManage/account/userInfo',
query: { query,
id: 1,
},
}); });
}; };
// 角色权限 modal // 角色权限 modal
const openRolePermissionsModal = record => { const openRolePermissionsModal = record => {
rolePermissionsModalRef.current.open(); rolePermissionsModalRef.current.open(record);
}; };
// 修改状态 modal // 修改状态 modal
......
import React, { forwardRef, useImperativeHandle, useState, useEffect } from 'react'; import React, { forwardRef, useImperativeHandle, useState, useEffect } from 'react';
import { Input, Checkbox, Button, Tree, notification } from 'antd'; import { Input, Checkbox, Button, Tree, notification, Spin } from 'antd';
import { Form } from '@ant-design/compatible'; import { Form } from '@ant-design/compatible';
import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { getUserPermissions } from '@/services/user'; import { getUserPermissions } from '@/services/user';
...@@ -22,7 +22,15 @@ const { TreeNode } = Tree; ...@@ -22,7 +22,15 @@ const { TreeNode } = Tree;
* @param {boolean} props.readyonly 是否全部为只读(查看操作) * @param {boolean} props.readyonly 是否全部为只读(查看操作)
*/ */
const RoleInfo = props => { const RoleInfo = props => {
const { id, submittable = true, readyonly = false, defaultExpandAll = true } = props; const {
id,
submittable = true,
readyonly = false,
defaultExpandAll = true,
height,
labelCol = { span: 4 },
wrapperCol = { span: 12 },
} = props;
const { getFieldDecorator, getFieldValue, validateFields, setFieldsValue } = props.form; const { getFieldDecorator, getFieldValue, validateFields, setFieldsValue } = props.form;
// 可选的权限数据 // 可选的权限数据
...@@ -30,11 +38,12 @@ const RoleInfo = props => { ...@@ -30,11 +38,12 @@ const RoleInfo = props => {
// 当前选中的权限-仅提交时使用 // 当前选中的权限-仅提交时使用
const [selectedPermissions, setSelectedPermissions] = useState([]); const [selectedPermissions, setSelectedPermissions] = useState([]);
const [detailInfo, setDetailInfo] = useState({}); const [detailInfo, setDetailInfo] = useState({});
const [loading, setLoading] = useState(false);
// 表单布局 // 表单布局
const formLayout = { const formLayout = {
labelCol: { span: 4 }, labelCol,
wrapperCol: { span: 12 }, wrapperCol,
}; };
const btnLayout = { const btnLayout = {
wrapperCol: { offset: 4, span: 12 }, wrapperCol: { offset: 4, span: 12 },
...@@ -109,9 +118,7 @@ const RoleInfo = props => { ...@@ -109,9 +118,7 @@ const RoleInfo = props => {
}; };
// 初始化权限数据 // 初始化权限数据
const initPermissions = async () => { const initPermissions = (res, roleId) => {
const roleId = id || null;
const res = await getUserPermissions(roleId);
let resource = []; let resource = [];
let selected = []; let selected = [];
if (roleId) { if (roleId) {
...@@ -130,9 +137,7 @@ const RoleInfo = props => { ...@@ -130,9 +137,7 @@ const RoleInfo = props => {
}; };
// 初始化当前角色数据 // 初始化当前角色数据
const initRoleData = async () => { const initRoleData = res => {
const res = await getRoleDetail({ id });
if (res.code !== 2000) { if (res.code !== 2000) {
notification.warning({ message: res.detail }); notification.warning({ message: res.detail });
return; return;
...@@ -149,11 +154,20 @@ const RoleInfo = props => { ...@@ -149,11 +154,20 @@ const RoleInfo = props => {
}); });
}; };
useEffect(() => { const initData = async () => {
initPermissions(); const roleId = id || null;
setLoading(true);
const permissionsRes = await getUserPermissions(roleId);
if (id) { if (id) {
initRoleData(); const roleDetailRes = await getRoleDetail({ id });
initRoleData(roleDetailRes);
} }
setLoading(false);
initPermissions(permissionsRes, roleId);
};
useEffect(() => {
initData();
}, []); }, []);
const renderTreeNodes = data => const renderTreeNodes = data =>
...@@ -170,6 +184,7 @@ const RoleInfo = props => { ...@@ -170,6 +184,7 @@ const RoleInfo = props => {
return ( return (
<div className={style['info-box']}> <div className={style['info-box']}>
<Spin spinning={loading}>
<Form className={style['info-box--form']} {...formLayout}> <Form className={style['info-box--form']} {...formLayout}>
<Form.Item label="角色名称"> <Form.Item label="角色名称">
{readyonly {readyonly
...@@ -187,7 +202,8 @@ const RoleInfo = props => { ...@@ -187,7 +202,8 @@ const RoleInfo = props => {
</Form.Item> </Form.Item>
<Form.Item label="权限"> <Form.Item label="权限">
{getFieldDecorator('selected', rulesHandler('selected'))( {getFieldDecorator('selected', rulesHandler('selected'))(
permissionsData.length ? ( <div className={style.tree} style={{ height }}>
{permissionsData.length ? (
<Tree <Tree
checkable checkable
selectable={false} selectable={false}
...@@ -198,8 +214,9 @@ const RoleInfo = props => { ...@@ -198,8 +214,9 @@ const RoleInfo = props => {
{renderTreeNodes(permissionsData)} {renderTreeNodes(permissionsData)}
</Tree> </Tree>
) : ( ) : (
<></> ''
), )}
</div>,
)} )}
</Form.Item> </Form.Item>
...@@ -216,6 +233,7 @@ const RoleInfo = props => { ...@@ -216,6 +233,7 @@ const RoleInfo = props => {
'' ''
)} )}
</Form> </Form>
</Spin>
</div> </div>
); );
}; };
......
...@@ -9,3 +9,10 @@ ...@@ -9,3 +9,10 @@
margin-left: 20px; margin-left: 20px;
} }
} }
.tree {
min-height: 500px;
padding: 20px 30px;
overflow: auto;
border: 1px solid #efefef;
}
...@@ -32,7 +32,6 @@ export const getColumns = props => { ...@@ -32,7 +32,6 @@ export const getColumns = props => {
title: '创建人', title: '创建人',
dataIndex: 'creator', dataIndex: 'creator',
hideInSearch: true, hideInSearch: true,
render: value => <a>{value}</a>,
}, },
{ {
title: '创建日期', title: '创建日期',
......
...@@ -70,12 +70,13 @@ export function userDelete({ id }) { ...@@ -70,12 +70,13 @@ export function userDelete({ id }) {
/** /**
* @name 重置/修改密码 * @name 重置/修改密码
* @param {Object} params * @param {Object} params
* @param {string} params.newPassword 新密码
* @param {string} params.password 确认密码 * @param {string} params.password 确认密码
* @see http://yapi.quantgroups.com/project/509/interface/api/41800 * @see http://yapi.quantgroups.com/project/509/interface/api/43128
*/ */
export function resetPassword(params) { export function resetPassword(params) {
return request.post('/v2/user/password/reset', params); return request.post('/v2/user/password/resetpassword', {
data: params,
});
} }
/** /**
......
export const APP_CODE = 'APP013'; export const APP_CODE = 'APP013';
export const TENANT_ID = 560761; export const TENANT_ID = 560761;
// 小程序权限标识符
export const APPLETS_PERMISSION_IDENTIFIER = 'applets';
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