diff --git a/web/berry/src/utils/common.js b/web/berry/src/utils/common.js
index 626727d4..d74d032e 100644
--- a/web/berry/src/utils/common.js
+++ b/web/berry/src/utils/common.js
@@ -219,3 +219,14 @@ export function getChannelModels(type) {
}
return [];
}
+
+export function copy(text, name = '') {
+ try {
+ navigator.clipboard.writeText(text);
+ } catch (error) {
+ text = `复制${name}失败,请手动复制:
${text}`;
+ enqueueSnackbar(, getSnackbarOptions('COPY'));
+ return;
+ }
+ showSuccess(`复制${name}成功!`);
+}
diff --git a/web/berry/src/views/Authentication/AuthForms/ResetPasswordForm.js b/web/berry/src/views/Authentication/AuthForms/ResetPasswordForm.js
index eaa8dc95..a9f0f9e3 100644
--- a/web/berry/src/views/Authentication/AuthForms/ResetPasswordForm.js
+++ b/web/berry/src/views/Authentication/AuthForms/ResetPasswordForm.js
@@ -1,22 +1,22 @@
-import { useState, useEffect } from "react";
-import { useSearchParams } from "react-router-dom";
+import { useState, useEffect } from 'react';
+import { useSearchParams } from 'react-router-dom';
// material-ui
-import { Button, Stack, Typography, Alert } from "@mui/material";
+import { Button, Stack, Typography, Alert } from '@mui/material';
// assets
-import { showError, showInfo } from "utils/common";
-import { API } from "utils/api";
+import { showError, copy } from 'utils/common';
+import { API } from 'utils/api';
// ===========================|| FIREBASE - REGISTER ||=========================== //
const ResetPasswordForm = () => {
const [searchParams] = useSearchParams();
const [inputs, setInputs] = useState({
- email: "",
- token: "",
+ email: '',
+ token: ''
});
- const [newPassword, setNewPassword] = useState("");
+ const [newPassword, setNewPassword] = useState('');
const submit = async () => {
const res = await API.post(`/api/user/reset`, inputs);
@@ -24,31 +24,25 @@ const ResetPasswordForm = () => {
if (success) {
let password = res.data.data;
setNewPassword(password);
- navigator.clipboard.writeText(password);
- showInfo(`新密码已复制到剪贴板:${password}`);
+ copy(password, '新密码');
} else {
showError(message);
}
};
useEffect(() => {
- let email = searchParams.get("email");
- let token = searchParams.get("token");
+ let email = searchParams.get('email');
+ let token = searchParams.get('token');
setInputs({
token,
- email,
+ email
});
}, []);
return (
-
+
{!inputs.email || !inputs.token ? (
-
+
无效的链接
) : newPassword ? (
@@ -57,14 +51,7 @@ const ResetPasswordForm = () => {
请登录后及时修改密码
) : (
-