forked from 77media/video-flow
积分不足提醒
This commit is contained in:
parent
e6f849e0af
commit
99f3002ff6
@ -7,6 +7,7 @@ const HTTP_ERROR_MESSAGES: Record<number, string> = {
|
|||||||
0: "Please try again if the network is abnormal. If it happens again, please contact us.",
|
0: "Please try again if the network is abnormal. If it happens again, please contact us.",
|
||||||
400: "Request parameter error, please check your input.",
|
400: "Request parameter error, please check your input.",
|
||||||
401: "Login expired, please log in again.",
|
401: "Login expired, please log in again.",
|
||||||
|
402: "Insufficient points, please recharge.",
|
||||||
403: "Insufficient permissions to access this resource.",
|
403: "Insufficient permissions to access this resource.",
|
||||||
404: "Requested resource does not exist.",
|
404: "Requested resource does not exist.",
|
||||||
408: "Request timeout, please try again.",
|
408: "Request timeout, please try again.",
|
||||||
@ -31,12 +32,6 @@ const ERROR_HANDLERS: Record<number, () => void> = {
|
|||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
// 跳转到登录页面
|
// 跳转到登录页面
|
||||||
window.location.href = '/login';
|
window.location.href = '/login';
|
||||||
},
|
|
||||||
4001: () => {
|
|
||||||
// 显示积分不足通知
|
|
||||||
import('../utils/notifications').then(({ showInsufficientPointsNotification }) => {
|
|
||||||
showInsufficientPointsNotification();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -10,11 +10,24 @@ import { errorHandle } from './errorHandle';
|
|||||||
const handleRequestError = (error: any, defaultMessage: string = '请求失败') => {
|
const handleRequestError = (error: any, defaultMessage: string = '请求失败') => {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
const { status, data } = error.response;
|
const { status, data } = error.response;
|
||||||
const errorMessage = data?.message || defaultMessage;
|
const errorMessage = data?.message || data?.detail?.message || defaultMessage;
|
||||||
|
|
||||||
|
// 处理 402 状态码的特殊情况
|
||||||
|
if (status === 402 && data?.detail) {
|
||||||
|
import('./errorHandle').then(({ errorHandle }) => {
|
||||||
|
errorHandle(status, errorMessage);
|
||||||
|
// 调用积分不足通知,传入详细信息
|
||||||
|
import('../utils/notifications').then(({ showInsufficientPointsNotification }) => {
|
||||||
|
showInsufficientPointsNotification(data.detail);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
errorHandle(status, errorMessage);
|
errorHandle(status, errorMessage);
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
// 请求已发出但没有收到响应
|
// 请求已发出但没有收到响应
|
||||||
errorHandle(0 );
|
errorHandle(0);
|
||||||
} else {
|
} else {
|
||||||
// 请求配置出错
|
// 请求配置出错
|
||||||
errorHandle(0, error.message || defaultMessage);
|
errorHandle(0, error.message || defaultMessage);
|
||||||
|
|||||||
@ -58,7 +58,11 @@ const btnStyle = {
|
|||||||
* 显示积分不足通知
|
* 显示积分不足通知
|
||||||
* @description 在右上角显示一个带有充值链接的积分不足提醒
|
* @description 在右上角显示一个带有充值链接的积分不足提醒
|
||||||
*/
|
*/
|
||||||
export const showInsufficientPointsNotification = () => {
|
export const showInsufficientPointsNotification = (detail?: {
|
||||||
|
current_balance?: number;
|
||||||
|
required_tokens?: number;
|
||||||
|
message?: string;
|
||||||
|
}) => {
|
||||||
notification.warning({
|
notification.warning({
|
||||||
message: null,
|
message: null,
|
||||||
description: (
|
description: (
|
||||||
@ -66,7 +70,17 @@ export const showInsufficientPointsNotification = () => {
|
|||||||
<h3 style={messageStyle}>
|
<h3 style={messageStyle}>
|
||||||
Insufficient credits reminder
|
Insufficient credits reminder
|
||||||
</h3>
|
</h3>
|
||||||
<p style={descriptionStyle}>Your credits are insufficient, please upgrade to continue.</p>
|
<p style={descriptionStyle}>
|
||||||
|
{detail?.message || 'Your credits are insufficient, please upgrade to continue.'}
|
||||||
|
{detail?.current_balance !== undefined && detail?.required_tokens !== undefined && (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
<span style={{ color: 'rgba(255, 255, 255, 0.85)' }}>
|
||||||
|
Current balance: {detail.current_balance} / Required: {detail.required_tokens}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => window.location.href = '/pricing'}
|
onClick={() => window.location.href = '/pricing'}
|
||||||
style={btnStyle}
|
style={btnStyle}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user