fix: Popup message when copying fails
This commit is contained in:
parent
2e7e563d75
commit
7c9bf359fd
@ -219,3 +219,14 @@ export function getChannelModels(type) {
|
|||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function copy(text, name = '') {
|
||||||
|
try {
|
||||||
|
navigator.clipboard.writeText(text);
|
||||||
|
} catch (error) {
|
||||||
|
text = `复制${name}失败,请手动复制:<br /><br />${text}`;
|
||||||
|
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text} />, getSnackbarOptions('COPY'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showSuccess(`复制${name}成功!`);
|
||||||
|
}
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from 'react';
|
||||||
import { useSearchParams } from "react-router-dom";
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
// material-ui
|
// material-ui
|
||||||
import { Button, Stack, Typography, Alert } from "@mui/material";
|
import { Button, Stack, Typography, Alert } from '@mui/material';
|
||||||
|
|
||||||
// assets
|
// assets
|
||||||
import { showError, showInfo } from "utils/common";
|
import { showError, copy } from 'utils/common';
|
||||||
import { API } from "utils/api";
|
import { API } from 'utils/api';
|
||||||
|
|
||||||
// ===========================|| FIREBASE - REGISTER ||=========================== //
|
// ===========================|| FIREBASE - REGISTER ||=========================== //
|
||||||
|
|
||||||
const ResetPasswordForm = () => {
|
const ResetPasswordForm = () => {
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const [inputs, setInputs] = useState({
|
const [inputs, setInputs] = useState({
|
||||||
email: "",
|
email: '',
|
||||||
token: "",
|
token: ''
|
||||||
});
|
});
|
||||||
const [newPassword, setNewPassword] = useState("");
|
const [newPassword, setNewPassword] = useState('');
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
const res = await API.post(`/api/user/reset`, inputs);
|
const res = await API.post(`/api/user/reset`, inputs);
|
||||||
@ -24,31 +24,25 @@ const ResetPasswordForm = () => {
|
|||||||
if (success) {
|
if (success) {
|
||||||
let password = res.data.data;
|
let password = res.data.data;
|
||||||
setNewPassword(password);
|
setNewPassword(password);
|
||||||
navigator.clipboard.writeText(password);
|
copy(password, '新密码');
|
||||||
showInfo(`新密码已复制到剪贴板:${password}`);
|
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let email = searchParams.get("email");
|
let email = searchParams.get('email');
|
||||||
let token = searchParams.get("token");
|
let token = searchParams.get('token');
|
||||||
setInputs({
|
setInputs({
|
||||||
token,
|
token,
|
||||||
email,
|
email
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack spacing={3} padding={'24px'} justifyContent={'center'} alignItems={'center'}>
|
||||||
spacing={3}
|
|
||||||
padding={"24px"}
|
|
||||||
justifyContent={"center"}
|
|
||||||
alignItems={"center"}
|
|
||||||
>
|
|
||||||
{!inputs.email || !inputs.token ? (
|
{!inputs.email || !inputs.token ? (
|
||||||
<Typography variant="h3" sx={{ textDecoration: "none" }}>
|
<Typography variant="h3" sx={{ textDecoration: 'none' }}>
|
||||||
无效的链接
|
无效的链接
|
||||||
</Typography>
|
</Typography>
|
||||||
) : newPassword ? (
|
) : newPassword ? (
|
||||||
@ -57,14 +51,7 @@ const ResetPasswordForm = () => {
|
|||||||
请登录后及时修改密码
|
请登录后及时修改密码
|
||||||
</Alert>
|
</Alert>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button fullWidth onClick={submit} size="large" type="submit" variant="contained" color="primary">
|
||||||
fullWidth
|
|
||||||
onClick={submit}
|
|
||||||
size="large"
|
|
||||||
type="submit"
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
>
|
|
||||||
点击重置密码
|
点击重置密码
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from 'prop-types';
|
||||||
import { Tooltip, Stack, Container } from "@mui/material";
|
import { Tooltip, Stack, Container } from '@mui/material';
|
||||||
import Label from "ui-component/Label";
|
import Label from 'ui-component/Label';
|
||||||
import { styled } from "@mui/material/styles";
|
import { styled } from '@mui/material/styles';
|
||||||
import { showSuccess } from "utils/common";
|
import { showSuccess, copy } from 'utils/common';
|
||||||
|
|
||||||
const TooltipContainer = styled(Container)({
|
const TooltipContainer = styled(Container)({
|
||||||
maxHeight: "250px",
|
maxHeight: '250px',
|
||||||
overflow: "auto",
|
overflow: 'auto',
|
||||||
"&::-webkit-scrollbar": {
|
'&::-webkit-scrollbar': {
|
||||||
width: "0px", // Set the width to 0 to hide the scrollbar
|
width: '0px' // Set the width to 0 to hide the scrollbar
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const NameLabel = ({ name, models }) => {
|
const NameLabel = ({ name, models }) => {
|
||||||
let modelMap = [];
|
let modelMap = [];
|
||||||
modelMap = models.split(",");
|
modelMap = models.split(',');
|
||||||
modelMap.sort();
|
modelMap.sort();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -28,8 +28,7 @@ const NameLabel = ({ name, models }) => {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
key={index}
|
key={index}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(item);
|
copy(item, '模型名称');
|
||||||
showSuccess("复制模型名称成功!");
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{item}
|
{item}
|
||||||
@ -48,7 +47,7 @@ const NameLabel = ({ name, models }) => {
|
|||||||
|
|
||||||
NameLabel.propTypes = {
|
NameLabel.propTypes = {
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
models: PropTypes.string,
|
models: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default NameLabel;
|
export default NameLabel;
|
||||||
|
@ -21,7 +21,7 @@ import { IconBrandWechat, IconBrandGithub, IconMail } from '@tabler/icons-react'
|
|||||||
import Label from 'ui-component/Label';
|
import Label from 'ui-component/Label';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
import { showError, showSuccess } from 'utils/common';
|
import { showError, showSuccess } from 'utils/common';
|
||||||
import { onGitHubOAuthClicked, onLarkOAuthClicked } from 'utils/common';
|
import { onGitHubOAuthClicked, onLarkOAuthClicked, copy } from 'utils/common';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import WechatModal from 'views/Authentication/AuthForms/WechatModal';
|
import WechatModal from 'views/Authentication/AuthForms/WechatModal';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
@ -90,8 +90,7 @@ export default function Profile() {
|
|||||||
const { success, message, data } = res.data;
|
const { success, message, data } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
setInputs((inputs) => ({ ...inputs, access_token: data }));
|
setInputs((inputs) => ({ ...inputs, access_token: data }));
|
||||||
navigator.clipboard.writeText(data);
|
copy(data, '访问令牌');
|
||||||
showSuccess(`令牌已重置并已复制到剪贴板`);
|
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
|
|
||||||
import Label from 'ui-component/Label';
|
import Label from 'ui-component/Label';
|
||||||
import TableSwitch from 'ui-component/Switch';
|
import TableSwitch from 'ui-component/Switch';
|
||||||
import { timestamp2string, renderQuota, showSuccess } from 'utils/common';
|
import { timestamp2string, renderQuota, copy } from 'utils/common';
|
||||||
|
|
||||||
import { IconDotsVertical, IconEdit, IconTrash } from '@tabler/icons-react';
|
import { IconDotsVertical, IconEdit, IconTrash } from '@tabler/icons-react';
|
||||||
|
|
||||||
@ -83,8 +83,7 @@ export default function RedemptionTableRow({ item, manageRedemption, handleOpenM
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(item.key);
|
copy(item.key, '兑换码');
|
||||||
showSuccess('已复制到剪贴板!');
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
复制
|
复制
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
import TableSwitch from 'ui-component/Switch';
|
import TableSwitch from 'ui-component/Switch';
|
||||||
import { renderQuota, showSuccess, timestamp2string } from 'utils/common';
|
import { renderQuota, timestamp2string, copy } from 'utils/common';
|
||||||
|
|
||||||
import { IconDotsVertical, IconEdit, IconTrash, IconCaretDownFilled } from '@tabler/icons-react';
|
import { IconDotsVertical, IconEdit, IconTrash, IconCaretDownFilled } from '@tabler/icons-react';
|
||||||
|
|
||||||
@ -141,8 +141,7 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
|
|||||||
if (type === 'link') {
|
if (type === 'link') {
|
||||||
window.open(text);
|
window.open(text);
|
||||||
} else {
|
} else {
|
||||||
navigator.clipboard.writeText(text);
|
copy(text);
|
||||||
showSuccess('已复制到剪贴板!');
|
|
||||||
}
|
}
|
||||||
handleCloseMenu();
|
handleCloseMenu();
|
||||||
};
|
};
|
||||||
@ -192,7 +191,7 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
|
|||||||
id={`switch-${item.id}`}
|
id={`switch-${item.id}`}
|
||||||
checked={statusSwitch === 1}
|
checked={statusSwitch === 1}
|
||||||
onChange={handleStatus}
|
onChange={handleStatus}
|
||||||
// disabled={statusSwitch !== 1 && statusSwitch !== 2}
|
// disabled={statusSwitch !== 1 && statusSwitch !== 2}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
@ -211,8 +210,7 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
|
|||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(`sk-${item.key}`);
|
copy(`sk-${item.key}`);
|
||||||
showSuccess('已复制到剪贴板!');
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
复制
|
复制
|
||||||
@ -222,7 +220,9 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
|
|||||||
</Button>
|
</Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
<ButtonGroup size="small" aria-label="split button">
|
<ButtonGroup size="small" aria-label="split button">
|
||||||
<Button color="primary" onClick={(e) => handleCopy(COPY_OPTIONS[0], 'link')}>聊天</Button>
|
<Button color="primary" onClick={(e) => handleCopy(COPY_OPTIONS[0], 'link')}>
|
||||||
|
聊天
|
||||||
|
</Button>
|
||||||
<Button size="small" onClick={(e) => handleOpenMenu(e, 'link')}>
|
<Button size="small" onClick={(e) => handleOpenMenu(e, 'link')}>
|
||||||
<IconCaretDownFilled size={'16px'} />
|
<IconCaretDownFilled size={'16px'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -4,7 +4,7 @@ import SubCard from 'ui-component/cards/SubCard';
|
|||||||
import inviteImage from 'assets/images/invite/cwok_casual_19.webp';
|
import inviteImage from 'assets/images/invite/cwok_casual_19.webp';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
import { showError, showSuccess } from 'utils/common';
|
import { showError, copy } from 'utils/common';
|
||||||
|
|
||||||
const InviteCard = () => {
|
const InviteCard = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -12,8 +12,7 @@ const InviteCard = () => {
|
|||||||
|
|
||||||
const handleInviteUrl = async () => {
|
const handleInviteUrl = async () => {
|
||||||
if (inviteUl) {
|
if (inviteUl) {
|
||||||
navigator.clipboard.writeText(inviteUl);
|
copy(inviteUl, '邀请链接');
|
||||||
showSuccess(`邀请链接已复制到剪切板`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const res = await API.get('/api/user/aff');
|
const res = await API.get('/api/user/aff');
|
||||||
@ -21,8 +20,7 @@ const InviteCard = () => {
|
|||||||
if (success) {
|
if (success) {
|
||||||
let link = `${window.location.origin}/register?aff=${data}`;
|
let link = `${window.location.origin}/register?aff=${data}`;
|
||||||
setInviteUrl(link);
|
setInviteUrl(link);
|
||||||
navigator.clipboard.writeText(link);
|
copy(link, '邀请链接');
|
||||||
showSuccess(`邀请链接已复制到剪切板`);
|
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user