This commit is contained in:
Mrx
2026-02-28 11:21:11 +08:00
parent 2fad9bd3dd
commit ca575800ba

View File

@@ -80,54 +80,38 @@ onBeforeMount(async () => {
await store.fetchAgentStatus();
}
});
import { applyForAgent, registerByInviteCode } from "@/api/agent";
import useApiFetch from '@/composables/useApiFetch'
const submitApplication = async (formData) => {
const { region, mobile, wechat_id, code, referrer } = formData;
// 根据是否已登录选择不同的API
const isLoggedIn = !!localStorage.getItem("token");
const apiCall = isLoggedIn ? applyForAgent : registerByInviteCode;
const apiUrl = isLoggedIn ? 'agent/apply' : 'agent/register/invite';
// 使用滑块验证码保护申请接口
runWithCaptcha(
(captchaVerifyParam) => {
let postData = {
region,
mobile,
wechat_id,
code,
referrer,
captchaVerifyParam,
};
return apiCall(postData);
},
async ({ data, error }) => {
if (data.value && !error.value) {
if (data.value.code === 200) {
showApplyPopup.value = false;
showToast({ message: "注册成功,您已成为代理!" });
// 更新token和状态
if (data.value.data.accessToken) {
localStorage.setItem("token", data.value.data.accessToken);
localStorage.setItem(
"refreshAfter",
data.value.data.refreshAfter
);
localStorage.setItem(
"accessExpire",
data.value.data.accessExpire
);
// 重新获取代理状态
await store.fetchAgentStatus();
await userStore.fetchUserInfo();
// 跳转到代理主页
router.replace("/agent");
}
} else {
console.log("申请失败", data.value);
showToast({ message: data.value.msg || "申请失败" });
(captchaVerifyParam) =>
useApiFetch(apiUrl)
.post({ region, mobile, wechat_id, code, referrer, captchaVerifyParam })
.json(),
(res) => {
if (res.code === 200) {
showApplyPopup.value = false;
showToast({ message: "注册成功,您已成为代理!" });
// 更新token和状态
if (res.data.accessToken) {
localStorage.setItem("token", res.data.accessToken);
localStorage.setItem("refreshAfter", res.data.refreshAfter);
localStorage.setItem("accessExpire", res.data.accessExpire);
// 重新获取代理状态
store.fetchAgentStatus();
userStore.fetchUserInfo();
// 跳转到代理主页
router.replace("/agent");
}
} else {
showToast({ message: res.msg || "申请失败" });
}
}
);