提现错误弹窗

This commit is contained in:
2025-09-29 22:43:17 +08:00
parent 9b6e3e15d0
commit 276e7dfee0
5 changed files with 121 additions and 127 deletions

View File

@@ -31,7 +31,7 @@ export const API_CONFIG = {
LEAVE: '/game/leave' LEAVE: '/game/leave'
}, },
PROFESSIONS: '/professions/tree', PROFESSIONS: '/professions/tree',
CITIS: '/admin/wch_cities/page' CITIS: '/cities/tree'
}; };
// 请求拦截器配置 // 请求拦截器配置

View File

@@ -105,7 +105,7 @@ class HttpService {
} }
// 处理响应 // 处理响应
private handleResponse<T>(response: any): Promise<ApiResponse<T>> { private handleResponse<T>(response: any, showToast: boolean): Promise<ApiResponse<T>> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { statusCode, data } = response const { statusCode, data } = response
@@ -121,8 +121,12 @@ class HttpService {
// 业务状态码检查 // 业务状态码检查
if (data && typeof data === 'object') { if (data && typeof data === 'object') {
if (data.success === false || (data.code && data.code !== 0 && data.code !== 200)) { if (data.success === false || (data.code && data.code !== 0 && data.code !== 200)) {
if (showToast) {
this.handleBusinessError(data) this.handleBusinessError(data)
reject(new Error(data.message || '请求失败')) reject(new Error(data.message || '请求失败'))
} else {
reject(response.data)
}
return return
} }
} }
@@ -191,7 +195,8 @@ class HttpService {
data, data,
params, params,
showLoading = false, showLoading = false,
loadingText = '请求中...' loadingText = '请求中...',
showToast = true,
} = config } = config
let fullUrl = this.buildUrl(url, method === 'GET' ? params : undefined) let fullUrl = this.buildUrl(url, method === 'GET' ? params : undefined)
@@ -238,11 +243,12 @@ class HttpService {
method: method, method: method,
data: method !== 'GET' ? data : undefined, data: method !== 'GET' ? data : undefined,
header: reqHeader, header: reqHeader,
timeout: this.timeout timeout: this.timeout,
showToast,
} }
const response = await Taro.request(requestConfig) const response = await Taro.request(requestConfig)
return this.handleResponse<T>(response) return this.handleResponse<T>(response, showToast)
} catch (error) { } catch (error) {
this.log('error', '请求失败', error) this.log('error', '请求失败', error)

View File

@@ -43,10 +43,8 @@ const SetTransactionPassword: React.FC = () => {
}); });
return; return;
} }
if (handleType === "set") {
const { sms_code } = formData;
try { try {
await httpService.post("/wallet/set_payment_password", { password: new_password, sms_code }); await httpService.post("/wallet/set_payment_password", { password: new_password });
Taro.showToast({ Taro.showToast({
title: "设置交易密码成功", title: "设置交易密码成功",
icon: "success", icon: "success",
@@ -59,23 +57,6 @@ const SetTransactionPassword: React.FC = () => {
}); });
return; return;
} }
} else if (handleType === "reset") {
// const { old_password } = formData;
try {
await httpService.post("/wallet/reset_payment_password", { phone, new_password, sms_code });
Taro.showToast({
title: "修改交易密码成功",
icon: "success",
});
Taro.navigateBack();
} catch (error) {
Taro.showToast({
title: "修改交易密码失败",
icon: "none",
});
return;
}
}
}; };
return ( return (

View File

@@ -267,7 +267,7 @@ const WalletPage: React.FC = () => {
// 处理提现 // 处理提现
const handle_withdraw = () => { const handle_withdraw = () => {
if (password_status) { if (!password_status) {
navigateToSetTransactionPassword("set"); navigateToSetTransactionPassword("set");
return; return;
} }

View File

@@ -27,19 +27,11 @@ const Withdrawal: React.FC = () => {
const [password, setPassword] = useState<string[]>(new Array(6).fill("")); const [password, setPassword] = useState<string[]>(new Array(6).fill(""));
const toastConfig = { const [mapErrorCodes, setMapErrorCodes] = useState({});
aa: {
title: "已超单日限额",
content: "您今日提现已超过支付通道2000元单日限额建议您明日再发起提现资金仍安全存放在钱包余额中。"
},
bb: {
title: "已超单日限额",
content: "今日提现通道额度已用完,暂时无法提现;您的余额安全存放在钱包中,我们会在 次日0点恢复 提现服务;如有紧急情况,请联系客服。"
}
}
useDidShow(() => { useDidShow(() => {
load_wallet_data(); load_wallet_data();
getWithdrawErrorCodes();
}); });
useEffect(() => { useEffect(() => {
@@ -112,40 +104,38 @@ const Withdrawal: React.FC = () => {
}); });
} }
}; };
const getWithdrawErrorCodes = async () => {
try {
const response = await httpService.post("/wallet/error_codes");
if (response.code === 0) {
const { withdraw_errors: { WEIXIN_ERRORS } } = response.data;
const mapErrorCodes = {};
for (const key in WEIXIN_ERRORS) {
const { code } = WEIXIN_ERRORS[key];
mapErrorCodes[code] = WEIXIN_ERRORS[key];
}
setMapErrorCodes(mapErrorCodes);
}
} catch (error: any) {
console.error("获取提现错误码失败:", error);
}
}
const handleWithdraw = async () => { const handleWithdraw = async () => {
// TODO 校验提现状态
// if (true) {
// Taro.showToast({
// title: "您今日已累计提现 10次达到每日次数上限",
// icon: "none",
// });
// }
// const { aa, bb } = toastConfig;
// Taro.showModal({
// title: aa.title,
// content: aa.content,
// showCancel: false,
// confirmColor: "#000",
// });
// Taro.showModal({
// title: bb.title,
// content: bb.content,
// showCancel: false,
// confirmColor: "#000",
// });
set_show_withdraw_popup(true); set_show_withdraw_popup(true);
}; };
const submit_withdraw = async () => { const submit_withdraw = async (payment_password: string) => {
try {
// 先调用后端接口获取提现参数 // 先调用后端接口获取提现参数
const response = await httpService.post("/wallet/withdraw", { const response = await httpService.post("/wallet/withdraw", {
amount: parseFloat(inputValue), amount: parseFloat(inputValue),
transfer_remark: "用户申请提现", transfer_remark: "用户申请提现",
}); payment_password,
}, { showToast: false });
const { data } = response;
// 根据后端返回的数据结构解析参数 // 根据后端返回的数据结构解析参数
const { mch_id, app_id, package_info, open_id } = response.data; const { mch_id, app_id, package_info, open_id } = data;
console.log("/wallet/withdraw:", response.data); console.log("/wallet/withdraw:", data);
set_show_withdraw_popup(false); set_show_withdraw_popup(false);
// 调用微信商户转账接口 // 调用微信商户转账接口
@@ -172,15 +162,9 @@ const Withdrawal: React.FC = () => {
console.log("微信转账失败:", res); console.log("微信转账失败:", res);
}, },
}); });
} } catch (error: any) {
const handlePasswordInput = (e: any) => { const { code, message } = error;
const value = e.detail.value; if (message === "支付密码错误") {
const [one = "", two = "", three = "", four = "", five = "", six = ""] = value.split("");
setPassword([one, two, three, four, five, six]);
if (value.length === 6) {
const timer = setTimeout(() => {
// TODO 校验密码
if (false) {
set_show_withdraw_popup(false); set_show_withdraw_popup(false);
Taro.showModal({ Taro.showModal({
content: "支付密码错误,请重试", content: "支付密码错误,请重试",
@@ -196,12 +180,35 @@ const Withdrawal: React.FC = () => {
url: "/user_pages/validPhone/index" url: "/user_pages/validPhone/index"
}); });
} }
}).finally(() => {
clearTimeout(timer);
}); });
return;
} else if (mapErrorCodes[code]) {
const { message, description } = mapErrorCodes[code];
Taro.showModal({
title: description,
content: message,
showCancel: false,
confirmText: "确认",
confirmColor: "#fff",
});
return;
} else { } else {
submit_withdraw(); Taro.showToast({
title: message,
icon: "none",
duration: 2000,
});
} }
}
}
const handlePasswordInput = (e: any) => {
const value = e.detail.value;
const [one = "", two = "", three = "", four = "", five = "", six = ""] = value.split("");
setPassword([one, two, three, four, five, six]);
if (value.length === 6) {
const timer = setTimeout(() => {
submit_withdraw(value);
clearTimeout(timer);
}, 100); }, 100);
} }
} }