first commit

This commit is contained in:
2025-12-16 12:33:02 +08:00
commit 547f543e6c
643 changed files with 87387 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
<template>
<div class="min-h-screen bg-[#DBE0FF]">
<img src="@/assets/images/invitation_agent_apply.png" alt="邀请代理申请" />
<!-- 统一状态处理容器 -->
<div class="flex flex-col items-center justify-centerx">
<!-- 已是代理状态 -->
<div v-if="isAgent" class="text-center">
<span class="text-xs text-gray-500">您已是代理欢迎回来</span>
<div class="bg-green-100 p-1 rounded-3xl shadow-xl mt-1" @click="goToHome">
<div
class="text-xl font-bold px-8 py-2 bg-gradient-to-t from-green-500 to-green-300 text-white rounded-3xl shadow-lg cursor-pointer">
进入应用首页
</div>
</div>
</div>
<!-- 未成为代理状态包含邀请状态 -->
<div v-else class="text-center">
<span class="text-xs text-gray-500">{{
isSelf ? "立即申请成为代理人" : "邀您注册代理人"
}}</span>
<div class="bg-gray-100 p-1 rounded-3xl shadow-xl mt-1" @click="agentApply">
<div
class="text-xl font-bold px-8 py-2 bg-gradient-to-t from-blue-500 to-blue-300 text-white rounded-3xl shadow-lg cursor-pointer">
立即成为代理方
</div>
</div>
</div>
</div>
</div>
<AgentApplicationForm v-model:show="showApplyPopup" @submit="submitApplication" @close="showApplyPopup = false" />
</template>
<script setup>
import { aesDecrypt } from "@/utils/crypto";
const showApplyPopup = ref(false);
const route = useRoute();
const router = useRouter();
import { storeToRefs } from "pinia";
import { ref } from "vue";
const store = useAgentStore();
const userStore = useUserStore();
const { userName } = storeToRefs(userStore);
const { isAgent } = storeToRefs(store);
const ancestor = ref("");
const isSelf = ref(false);
const agentApply = () => {
showApplyPopup.value = true;
};
// 跳转到首页
const goToHome = () => {
router.replace("/promote");
};
onBeforeMount(async () => {
// 如果是通过邀请链接访问旧的linkIdentifier格式提取信息
if (route.params.linkIdentifier && route.name !== "invitationAgentApplySelf") {
try {
const linkIdentifier = route.params.linkIdentifier;
const decryptDataStr = aesDecrypt(
decodeURIComponent(linkIdentifier),
"8e3e7a2f60edb49221e953b9c029ed10"
);
const decryptData = JSON.parse(decryptDataStr);
// 旧格式可能包含agentID和mobile但新系统使用邀请码
// 这里可以保留兼容,但主要功能是通过邀请码
} catch (error) {
console.error("解析链接标识符失败", error);
}
} else {
isSelf.value = true;
}
// 检查是否已登录并获取代理状态
const token = localStorage.getItem("token");
if (token) {
await store.fetchAgentStatus();
}
});
import { applyForAgent, registerByInviteCode } from "@/api/agent";
const submitApplication = async (formData) => {
const { region, mobile, wechat_id, code, referrer } = formData;
// 根据是否已登录选择不同的API
const isLoggedIn = !!localStorage.getItem("token");
const apiCall = isLoggedIn ? applyForAgent : registerByInviteCode;
let postData = {
region,
mobile,
wechat_id,
code,
referrer,
};
const { data, error } = await apiCall(postData);
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);
}
}
};
</script>
<style lang="scss" scoped></style>