/* * @Author: cclu * @Date: 2022-04-28 10:47:35 * @LastEditTime: 2022-05-13 11:54:57 * @LastEditors: cclu lkrnchocolateaaron@gmail.com * @Description: 安全设置组件 * @FilePath: \cloud-platform\src\pages\account\setting\components\SecurityView.tsx */ import { ModalForm, ProFormCaptcha, ProFormText } from "@ant-design/pro-form"; import { List, message } from "antd"; import { useState, useRef } from "react"; import type { FormInstance } from "antd"; import type { CurrentUser } from "umi"; import type { CloudChangeUserModel, CloudChangePassword } from "../data"; import { getSMSIdentityCode, modifyUserPassword, modifyUserMobilePhone } from "../sevice"; type ChangeType = 'password' | 'phone' // 重置账号密码请求 const handelResetPassWord = async (item: CloudChangePassword) => { const loading = message.loading("正在提交...") const result = await modifyUserPassword(item) loading() if (result.Result_Code !== 100) { message.error(`${result.Result_Desc}` || `${result.Result_Code}:账户密码重置失败`) return false } message.success("账户密码重置成功!") return true } // 重置账号密码请求 const handleMobilePhone = async (item: CloudChangeUserModel) => { const loading = message.loading("正在提交...") const result = await modifyUserMobilePhone(item) loading() if (result.Result_Code !== 100) { message.error(`${result.Result_Desc}` || `${result.Result_Code}:账户手机号修改失败`) return false } message.success("账户手机号修改成功!") return true } /** * @description: 安全组件主体 * @param {CurrentUser} 用户信息 * @return {*} 函数组件dom */ const SecurityView: React.FC<{ currentUser?: CurrentUser }> = ({ currentUser }) => { const [modelVisible, handleModelVisible] = useState(false) // 弹出框操作状态 const [changeType, setChangeType] = useState('password') // 修改的数据类型 const formRef = useRef() return ( <>
安全设置
} > { setChangeType('password') handleModelVisible(true) }}>修改]} > { setChangeType('phone') handleModelVisible(true) }}>修改]} > { handleModelVisible(value) if (!value) { formRef.current?.resetFields(); } }} onFinish={async (value) => { const newValue = { ...value, USER_ID_Encrypted: currentUser?.ID_Encrypted } let success = null if (changeType === 'password') { if (newValue.NewPassword !== newValue.ComfirmPassword) { message.error('两次输入的密码不一致') return } delete newValue.ComfirmPassword success = await handelResetPassWord({ ...newValue, DataType: 1000 }) } else { success = await handleMobilePhone(newValue as CloudChangeUserModel) } if (success) { return true } return false }} > {changeType === 'password' ? (<> ) : (<> { await getSMSIdentityCode(phone) message.success(`手机号 ${phone} 验证码发送成功!`); }} /> )} ); } export default SecurityView;