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