Commit ccd098e1 authored by 邓超's avatar 邓超

fix: 主管图标及交互修改,编辑跟修改密码合并改为双击修改

parent e6eba6d4
Pipeline #65367 waiting for manual action with stages
/* eslint-disable import/no-unresolved */
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, notification, message } from 'antd';
import voca from 'voca';
import { editUser } from '@/services/userManage/api';
import classNames from 'classnames';
import { editUser, updateUserPassword } from '@/services/userManage/api';
import sha1 from 'sha1';
import styles from './AddUserModal.less';
const EditUserModal = props => {
const { visible, currentUser, currentSelectOrg, onCancel, onSelect, submitSearchUser } = props;
......@@ -13,15 +16,29 @@ const EditUserModal = props => {
const isEmail = new RegExp(
/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\.[a-z]{2,}$/,
); // 邮箱
const [passwordForm] = Form.useForm(); // 修改密码
const [newPasswordLevel, setNewPasswordLevel] = useState('');
const [passwordConfirmLevel, setPasswordConfirmLevel] = useState('');
useEffect(() => {
console.log(currentUser);
editUserForm.setFieldsValue({
loginName: voca.stripTags(currentUser.loginName),
userName: voca.stripTags(currentUser.userName),
phone: voca.stripTags(currentUser.phone) || '',
email: currentUser.email || '',
});
if (visible) {
console.log(currentUser);
editUserForm.setFieldsValue({
loginName: voca.stripTags(currentUser.loginName),
userName: voca.stripTags(currentUser.userName),
phone: voca.stripTags(currentUser.phone) || '',
email: currentUser.email || '',
});
console.log(currentUser.password);
passwordForm.setFieldsValue({
oldPassword: currentUser.password,
newPassword: '',
passwordConfirm: '',
});
} else {
setNewPasswordLevel('');
setPasswordConfirmLevel('');
}
}, [visible]);
// 提交-编辑用户
......@@ -30,35 +47,68 @@ const EditUserModal = props => {
const userName = voca.stripTags(editUserForm.getFieldValue('userName'));
const phone = voca.stripTags(editUserForm.getFieldValue('phone')) || '';
const email = editUserForm.getFieldValue('email') || '';
const oldPassword = passwordForm.getFieldValue('oldPassword');
const newPassword = passwordForm.getFieldValue('newPassword');
const passwordConfirm = passwordForm.getFieldValue('passwordConfirm');
// 正则验证
if (loginName === '') {
notification.error({
message: '提交失败',
description: '登录名称不能为空!',
});
} else if (!noChinese.test(loginName)) {
return;
}
if (!noChinese.test(loginName)) {
notification.error({
message: '提交失败',
description: '登录名不支持中文!',
});
} else if (userName === '') {
return;
}
if (userName === '') {
notification.error({
message: '提交失败',
description: '用户姓名不能为空!',
});
} else if (phone !== '' && !isPhone.test(phone)) {
return;
}
if (phone !== '' && !isPhone.test(phone)) {
notification.error({
message: '提交失败',
description: '请输入11位手机号!',
});
} else if (email !== '' && !isEmail.test(email)) {
return;
}
if (email !== '' && !isEmail.test(email)) {
notification.error({
message: '提交失败',
description: '邮箱格式不正确!',
});
return;
}
if (newPassword === '' || passwordConfirm === '') {
notification.error({
message: '提交失败',
description: '带*号为必填项,不能为空',
});
return;
}
if ((newPassword && newPassword.length < 6) || (passwordConfirm && passwordConfirm < 6)) {
notification.error({
message: '提交失败',
description: '密码至少为6位!',
});
return;
}
if (newPassword !== passwordConfirm) {
notification.error({
message: '提交失败',
description: '确认密码不一致!',
});
return;
}
// 所有验证通过才可以提交,phone/email为空时不验证
else if (
if (
loginName &&
noChinese.test(loginName) &&
userName &&
......@@ -71,11 +121,12 @@ const EditUserModal = props => {
onCancel();
// 重新获取用户表
// eslint-disable-next-line no-unused-expressions
currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
// currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
notification.success({
message: '提交成功',
duration: 2,
});
submitChangePassword();
} else {
notification.error({
message: '提交失败',
......@@ -103,6 +154,86 @@ const EditUserModal = props => {
的信息
</span>
);
// 提交-修改密码
const submitChangePassword = () => {
const oldPassword = passwordForm.getFieldValue('oldPassword');
const newPassword = passwordForm.getFieldValue('newPassword');
const passwordConfirm = passwordForm.getFieldValue('passwordConfirm');
if (
newPassword &&
newPassword.length >= 6 &&
passwordConfirm &&
newPassword.length >= 6 &&
newPassword === passwordConfirm
) {
updateUserPassword({
UserId: +currentUser.userID,
OldPassWord: oldPassword,
NewPassWord: sha1(newPassword).toUpperCase(),
})
.then(res => {
if (res.code === 0) {
onCancel();
// eslint-disable-next-line no-unused-expressions
currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
// notification.success({
// message: '提交成功',
// duration: 2,
// });
} else {
notification.error({
message: '提交失败',
description: res.message,
});
}
passwordForm.setFieldsValue({
oldPassword: currentUser.password,
newPassword: '',
passwordConfirm: '',
});
})
.catch(err => {
message.error(err);
});
}
};
const changeValue = changedFields => {
if (changedFields[0].name[0] === 'newPassword') {
setNewPasswordLevel(checkStrong(changedFields[0].value));
}
if (changedFields[0].name[0] === 'passwordConfirm') {
setPasswordConfirmLevel(checkStrong(changedFields[0].value));
}
};
const checkStrong = sValue => {
let modes = 0;
// 正则表达式验证符合要求的
if (sValue.length < 1) return modes;
if (/\d/.test(sValue)) modes++; // 数字
if (/[a-z]/.test(sValue)) modes++; // 小写
if (/[A-Z]/.test(sValue)) modes++; // 大写
if (/[_\W]/.test(sValue)) modes++; // 特殊字符
console.log(modes, 'modes');
// 逻辑处理
// eslint-disable-next-line default-case
switch (modes) {
case 1:
return '弱';
case 2:
if (sValue.length > 8) {
return '中';
}
return '弱';
case 3:
if (sValue.length > 8) {
return '强';
}
return '中';
case 4:
return '强';
}
};
return (
<Modal
title={title}
......@@ -182,6 +313,83 @@ const EditUserModal = props => {
<Input placeholder="请输入电子邮箱" autoComplete="off" />
</Form.Item>
</Form>
<div className={styles.modalContent}>
<Form form={passwordForm} labelCol={{ span: 4 }} onFieldsChange={changeValue}>
<Form.Item name="oldPassword" label="原始密码">
<Input disabled />
</Form.Item>
<div className={styles.formBox}>
<Form.Item
name="newPassword"
label="新密码"
rules={[
{
pattern: /^[a-zA-Z0-9_]{6,16}$/,
message: '长度6-16位,支持字母与数字,允许下划线',
},
{ required: true },
]}
>
<Input.Password
placeholder="请输入新密码"
autoComplete="off"
maxLength="16"
onCopy={e => {
e.preventDefault();
}}
onPaste={e => {
// 禁止粘贴
e.preventDefault();
}}
/>
</Form.Item>
<div
className={classNames(styles.tipsText, {
[styles.tipsRed]: newPasswordLevel === '弱',
[styles.tipsOrange]: newPasswordLevel === '中',
[styles.tipsGreen]: newPasswordLevel === '强',
})}
>
{newPasswordLevel}
</div>
</div>
<div className={styles.formBox}>
<Form.Item
name="passwordConfirm"
label="确认密码"
rules={[
{
pattern: /^[a-zA-Z0-9_]{6,16}$/,
message: '长度6-16位,支持字母与数字,允许下划线',
},
{ required: true },
]}
>
<Input.Password
placeholder="再次确认新密码"
autoComplete="off"
maxLength="16"
onCopy={e => {
e.preventDefault();
}}
onPaste={e => {
// 禁止粘贴
e.preventDefault();
}}
/>
</Form.Item>
<div
className={classNames(styles.tipsText, {
[styles.tipsRed]: passwordConfirmLevel === '弱',
[styles.tipsOrange]: passwordConfirmLevel === '中',
[styles.tipsGreen]: passwordConfirmLevel === '强',
})}
>
{passwordConfirmLevel}
</div>
</div>
</Form>
</div>
</Modal>
);
};
......
......@@ -285,14 +285,14 @@ const UserManage = () => {
}}
>
<UserOutlined
style={{ fontSize: '20px', color: record.isManager ? '#FAAD14' : '#1890FF' }}
style={{ fontSize: '16px', color: record.isManager ? '#FAAD14' : '#1890FF' }}
/>
</Popconfirm>
</Tooltip>
<Tooltip title="关联权限">
<IdcardOutlined
onClick={() => relateRole(record)}
style={{ fontSize: '20px', color: '#1890FF' }}
style={{ fontSize: '16px', color: '#1890FF' }}
/>
</Tooltip>
<Tooltip title="更改机构">
......@@ -301,15 +301,15 @@ const UserManage = () => {
style={{ fontSize: '16px', color: '#1890FF' }}
/>
</Tooltip>
<Tooltip title="修改密码">
{/* <Tooltip title="修改密码">
<UnlockOutlined
onClick={() => changePassword(record)}
style={{ fontSize: '16px', color: '#1890FF' }}
/>
</Tooltip>
<Tooltip title="编辑用户">
</Tooltip> */}
{/* <Tooltip title="编辑用户">
<EditTwoTone onClick={() => editUser(record)} style={{ fontSize: '16px' }} />
</Tooltip>
</Tooltip> */}
{(record.state == 0 || record.state == null) && (
<>
{record.loginName == 'panda' || record.loginName == 'admin' ? (
......@@ -329,7 +329,7 @@ const UserManage = () => {
cancelText="取消"
onConfirm={() => freezeUser(record)}
>
<StopOutlined style={{ fontSize: '16px', color: '#e86060' }} />
<StopOutlined style={{ fontSize: '16px', color: '#1890ff' }} />
</Popconfirm>
</Tooltip>
)}
......@@ -343,7 +343,7 @@ const UserManage = () => {
placement="bottomRight"
title={
<p>
即将解冻用户{' '}
即将解冻用户
<span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
,是否确认解冻?
</p>
......@@ -352,7 +352,7 @@ const UserManage = () => {
cancelText="取消"
onConfirm={() => freezeUser(record)}
>
<UserOutlined style={{ fontSize: '16px', color: '#1890ff' }} />
<StopOutlined style={{ fontSize: '16px', color: '#e86060' }} />
</Popconfirm>
</Tooltip>
</>
......@@ -1690,6 +1690,11 @@ const UserManage = () => {
showQuickJumper: true,
showSizeChanger: true,
}}
onRow={record => ({
onDoubleClick: () => {
editUser(record);
},
})}
onChange={onChangeInput}
/>
)}
......
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