Просмотр исходного кода

新增邀请码和域名支持,优化游客账号创建逻辑,提升用户体验

wuyi 3 месяцев назад
Родитель
Сommit
8c0b194120
3 измененных файлов с 13 добавлено и 5 удалено
  1. 5 1
      src/components/layout/MainLayout.vue
  2. 6 2
      src/services/api.ts
  3. 2 2
      src/store/user.ts

+ 5 - 1
src/components/layout/MainLayout.vue

@@ -124,8 +124,12 @@ const createGuestAccount = async () => {
   try {
     const urlParams = new URLSearchParams(window.location.search);
     const inviteCode = urlParams.get("code");
+    const refString = urlParams.get("ref");
 
-    await userStore.createGuest(inviteCode || undefined);
+    await userStore.createGuest(
+      inviteCode || undefined,
+      refString || undefined
+    );
     console.log("游客账号创建成功", userStore.userInfo);
   } catch (error) {
     console.error("创建游客账号失败", error);

+ 6 - 2
src/services/api.ts

@@ -119,8 +119,12 @@ export const profile = async (): Promise<any> => {
   return res.data;
 };
 
-export const newGuest = async (code?: string): Promise<any> => {
-  const res = await api.get("/member/guest", { params: code ? { code } : {} });
+export const newGuest = async (code?: string, ref?: string): Promise<any> => {
+  const params: any = {};
+  if (code) params.code = code;
+  if (ref) params.ref = ref;
+
+  const res = await api.get("/member/guest", { params });
   return res.data;
 };
 

+ 2 - 2
src/store/user.ts

@@ -60,9 +60,9 @@ export const useUserStore = defineStore("user", () => {
     userManuallyLoggedOut.value = true;
   };
 
-  const createGuest = async (code?: string) => {
+  const createGuest = async (code?: string, ref?: string) => {
     try {
-      const response = await newGuest(code);
+      const response = await newGuest(code, ref);
       setToken(response.token);
       setUserInfo(response.user);
       userManuallyLoggedOut.value = false;