New file |
| | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { |
| | | ProForm, |
| | | ProFormDigit, |
| | | ProFormText, |
| | | } from '@ant-design/pro-components'; |
| | | import { Form, Modal } from 'antd'; |
| | | |
| | | const Pwd = (props) => { |
| | | const [form] = Form.useForm(); |
| | | const { } = props; |
| | | |
| | | delete props.values.password |
| | | |
| | | useEffect(() => { |
| | | form.resetFields(); |
| | | form.setFieldsValue({ |
| | | ...props.values |
| | | }) |
| | | }, [form, props]) |
| | | |
| | | const handleCancel = () => { |
| | | props.onCancel(); |
| | | }; |
| | | |
| | | const handleOk = () => { |
| | | form.submit(); |
| | | } |
| | | |
| | | const handleFinish = async (values) => { |
| | | props.onSubmit({ ...values }); |
| | | } |
| | | |
| | | return ( |
| | | <> |
| | | <Modal |
| | | title="Reset Password" |
| | | width={400} |
| | | forceRender |
| | | destroyOnClose |
| | | open={props.open} |
| | | onCancel={handleCancel} |
| | | onOk={handleOk} |
| | | > |
| | | <ProForm |
| | | form={form} |
| | | submitter={false} |
| | | onFinish={handleFinish} |
| | | layout="horizontal" |
| | | grid={true} |
| | | > |
| | | <ProFormDigit |
| | | name="id" |
| | | disabled |
| | | hidden={true} |
| | | /> |
| | | <ProFormText |
| | | name="password" |
| | | label="新密码" |
| | | colProps={{ md: 24, xl: 24 }} |
| | | placeholder="请输入" |
| | | rules={[ |
| | | { required: true, message: "密码不能为空!" }, |
| | | { min: 4, message: "密码不能小于4位! " }, |
| | | { max: 16, message: "密码不能大于16位! " }, |
| | | ]} |
| | | /> |
| | | </ProForm> |
| | | </Modal> |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default Pwd; |
| | |
| | | import { PlusOutlined, ExportOutlined, DownOutlined } from '@ant-design/icons'; |
| | | import Http from '@/utils/http'; |
| | | import Edit from './components/edit' |
| | | import Pwd from './components/pwd' |
| | | import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch' |
| | | import { transformTreeData, getTreeAllKeys } from '@/utils/tree-util' |
| | | import { statusMap } from '@/utils/enum-util' |
| | |
| | | } |
| | | }; |
| | | |
| | | const handlePwd = async (val) => { |
| | | const hide = message.loading('正在重置'); |
| | | try { |
| | | const resp = await Http.doPost('api/user/reset/pwd', val); |
| | | if (resp.code === 200) { |
| | | message.success('重置成功'); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('重置失败请重试!'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | |
| | | const Main = () => { |
| | | const formTableRef = useRef(); |
| | |
| | | const [boxHeight, setBoxHeight] = useState(); |
| | | const [deptTreeData, setDeptTreeData] = useState([]); |
| | | const [deptExpandedKeys, setDeptExpandedKeys] = useState([]); |
| | | const [pwdModalVisible, setPwdModalVisible] = useState(false); |
| | | |
| | | useEffect(() => { |
| | | const handleResize = () => setBoxHeight(window.innerHeight - 368); |
| | |
| | | { |
| | | title: '操作', |
| | | dataIndex: 'option', |
| | | width: 100, |
| | | width: 150, |
| | | valueType: 'option', |
| | | render: (_, record) => [ |
| | | <Button |
| | |
| | | }} |
| | | > |
| | | 编辑 |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | | key="pwd" |
| | | onClick={() => { |
| | | setPwdModalVisible(true); |
| | | setCurrentRow(record); |
| | | }} |
| | | > |
| | | 重置密码 |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | |
| | | formRef={formTableRef} |
| | | columns={columns} |
| | | cardBordered |
| | | scroll={{y: boxHeight }} |
| | | scroll={{ y: boxHeight }} |
| | | dateFormatter="string" |
| | | pagination={{ pageSize: 20 }} |
| | | search={false} |
| | |
| | | } |
| | | } |
| | | /> |
| | | |
| | | <Pwd |
| | | open={pwdModalVisible} |
| | | values={currentRow || {}} |
| | | onCancel={ |
| | | () => { |
| | | setPwdModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | } |
| | | } |
| | | onSubmit={async (values) => { |
| | | let ok = false; |
| | | if (values.id) { |
| | | ok = await handlePwd({ ...values }) |
| | | } |
| | | if (ok) { |
| | | setPwdModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | if (actionRef.current) { |
| | | actionRef.current.reload(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /> |
| | | </Row> |
| | | </PageContainer> |
| | | ); |
| | |
| | | ExcelUtil.build(ExcelUtil.create(userService.list(), User.class), response); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:update')") |
| | | @OperationLog("重置密码") |
| | | @PostMapping("/user/reset/pwd") |
| | | public R resetPwd(@RequestBody User user) { |
| | | if (!Cools.isEmpty(user.getPassword())) { |
| | | user.setPassword(userService.encodePassword(user.getPassword())); |
| | | } |
| | | user.setUpdateBy(getLoginUserId()); |
| | | user.setUpdateTime(new Date()); |
| | | if (!userService.updateById(user)) { |
| | | return R.error("重置失败"); |
| | | } |
| | | return R.ok("重置成功"); |
| | | } |
| | | |
| | | } |