feat(shop): 添加邀请注册功能并优化注册流程

- 新增邀请注册弹窗组件,用于生成邀请链接和二维码
- 在注册页面添加邀请信息显示,引导用户通过邀请链接注册
- 实现注册成功后自动建立推荐关系的功能
- 优化注册表单,支持通过邀请链接直接进入注册页面
This commit is contained in:
2025-09-05 15:01:21 +08:00
parent c6e6bb02d3
commit cf74d2670c
3 changed files with 209 additions and 4 deletions

View File

@@ -35,6 +35,14 @@
>
</div>
<template v-if="loginType === 'account'">
<!-- 邀请信息显示 -->
<div v-if="inviterId" style="margin-bottom: 16px; padding: 12px; background: #f6ffed; border: 1px solid #b7eb8f; border-radius: 4px;">
<div style="color: #52c41a; font-size: 14px;">
<check-circle-outlined style="margin-right: 4px;" />
您正在通过邀请链接注册注册成功后将自动建立推荐关系
</div>
</div>
<a-form-item name="phone">
<a-input
allow-clear
@@ -227,12 +235,12 @@
</template>
<script lang="ts" setup>
import {ref, reactive, unref, watch} from 'vue';
import {ref, reactive, unref, watch, onMounted} from 'vue';
import {useI18n} from 'vue-i18n';
import {useRouter} from 'vue-router';
import {getTenantId} from '@/utils/domain';
import {Form, message} from 'ant-design-vue';
import { AimOutlined } from '@ant-design/icons-vue';
import { AimOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons-vue';
import { storeToRefs } from 'pinia';
import {goHomeRoute, cleanPageTabs} from '@/utils/page-tab-util';
import {loginBySms, getCaptcha} from '@/api/passport/login';
@@ -248,6 +256,7 @@ import {push} from "@/utils/common";
import {useThemeStore} from "@/store/modules/theme";
import {CmsWebsite} from "@/api/cms/cmsWebsite/model";
import {createCmsWebSite} from "@/api/layout";
import { bindUserReferee } from '@/api/user/referee';
const useForm = Form.useForm;
const {currentRoute} = useRouter();
@@ -382,6 +391,8 @@ const countdownTime = ref(0);
let countdownTimer: number | null = null;
// 是否显示地图选择弹窗
const showMap = ref(false);
// 邀请人ID
const inviterId = ref<number>();
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
@@ -548,8 +559,28 @@ const submit = () => {
.validate()
.then(() => {
loading.value = true;
// 普通注册流程
createCmsWebSite(form)
.then((msg) => {
.then(async (msg) => {
// 如果有邀请人,注册成功后建立推荐关系
if (inviterId.value) {
try {
const userId = localStorage.getItem('UserId');
if (userId) {
await bindUserReferee({
dealerId: inviterId.value,
userId: Number(userId),
level: 1
});
message.success('注册成功,已建立推荐关系');
}
} catch (e) {
console.error('建立推荐关系失败:', e);
// 不影响注册流程,只是推荐关系建立失败
}
}
setTimeout(() => {
// 登录成功
message.success(msg);
@@ -593,6 +624,15 @@ const changeCaptcha = () => {
// 首次加载
changeCaptcha();
// 检查URL参数中的邀请人ID
onMounted(() => {
const urlParams = new URLSearchParams(window.location.search);
const inviterParam = urlParams.get('inviter');
if (inviterParam) {
inviterId.value = Number(inviterParam);
}
});
watch(
currentRoute,
() => {