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

📦 增加注册关注加入志愿者分享用户ID

快乐的梦鱼 1 месяц назад
Родитель
Сommit
d3ddf30414

+ 1 - 0
src/api/auth/UserApi.ts

@@ -91,6 +91,7 @@ export class UserApi extends AppServerRequestModule<DataModel> {
     iv: string,
     raw_data: string,
     signature: string,
+    recommend_user_id?: number,
   }) {
     return (await this.post('/village/volunteer/third', '登录', {
       appid: AppCofig.appId,

+ 10 - 4
src/api/inhert/VillageApi.ts

@@ -253,8 +253,11 @@ export class VillageApi extends AppServerRequestModule<DataModel> {
     });
     return transformArrayDataModel<VillageListItem>(VillageListItem, transformSomeToArray(res.data), `村落`, true);
   }
-  async claimVallage(data: VillageClaimInfo) {
-    return this.post('/village/village/addVillageClaim', '认领村落', data.toServerSide());
+  async claimVallage(data: VillageClaimInfo, recommendUserId?: number) {
+    return this.post('/village/village/addVillageClaim', '认领村落', {
+      ...data.toServerSide(),
+      recommend_user_id: recommendUserId || 0,
+    });
   }
   async getVallageList(level?: number, status?: number, region?: string) {
     const res = await this.get('/village/village/getList', '村落列表', {
@@ -287,8 +290,11 @@ export class VillageApi extends AppServerRequestModule<DataModel> {
       village_id: villageId,
     });
   }
-  async shareAddVolunteer(data: VolunteerInfo) {
-    const res = await this.post('/village/volunteer/shareAdd', '分享添加志愿者', data.toServerSide(), undefined, LoginResult);
+  async shareAddVolunteer(data: VolunteerInfo, recommendUserId?: number) {
+    const res = await this.post('/village/volunteer/shareAdd', '分享添加志愿者', {
+      ...data.toServerSide(),
+      recommend_user_id: recommendUserId || 0,
+    }, undefined, LoginResult);
     return res.data as LoginResult;
   }
   async bindVolunteer(data: {

+ 2 - 1
src/api/light/FollowVillageApi.ts

@@ -42,9 +42,10 @@ export class FollowVillageApi extends AppServerRequestModule<DataModel> {
     super();
   }
 
-  async followVillage(villageId: number) {
+  async followVillage(villageId: number, recommendUserId?: number) {
     const res = await this.post<null>('/village/village/follow', '关注村社', {
       village_id: villageId,
+      recommend_user_id: recommendUserId || 0,
     });
     return res.requireData();
   }

+ 22 - 0
src/pages/home/composeabe/ShareLink.ts

@@ -0,0 +1,22 @@
+import { onMounted, ref, watch } from "vue";
+
+export function useShareLink() {
+
+  const recommendUserId = ref(0);
+
+  onMounted(() => {
+    recommendUserId.value = uni.getStorageSync('recommendUserId') || 0;
+  })
+  watch(recommendUserId, (newVal) => {
+    uni.setStorageSync('recommendUserId', newVal);
+  })
+
+  function setRecommendUserId(userId: number) {
+    recommendUserId.value = userId;
+  }
+
+  return {
+    recommendUserId,
+    setRecommendUserId,
+  };
+}

+ 6 - 3
src/pages/home/light/submit-volunteer.vue

@@ -90,6 +90,8 @@ import { onMounted, ref } from 'vue';
 import { useAppInit } from '@/common/composeabe/AppInit';
 import { useAuthStore } from '@/store/auth';
 import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
+import { useVillageStore } from '@/store/village';
+import { useShareLink } from '../composeabe/ShareLink';
 import { UserApi } from '@/api/auth/UserApi';
 import { waitTimeOut } from '@imengyu/imengyu-utils';
 import { fillClaimFromVolunteer, getClaimVillageForm } from './form/claim';
@@ -109,7 +111,6 @@ import CommonTopBanner from '@/common/components/CommonTopBanner.vue';
 import PrimaryButton from '@/common/components/PrimaryButton.vue';
 import ProvideVar from '@/components/theme/ProvideVar.vue';
 import BoxMid from '@/common/components/box/BoxMid.vue';
-import { useVillageStore } from '@/store/village';
 
 /**
  * 点亮村社页面
@@ -118,6 +119,8 @@ import { useVillageStore } from '@/store/village';
 const authStore = useAuthStore();
 const villageStore = useVillageStore();
 const { init } = useAppInit();
+const { recommendUserId } = useShareLink();
+
 
 const { querys } = useLoadQuerys({ 
   villageId: 0,  
@@ -177,7 +180,7 @@ async function loginWechat() {
       uni.login({ provider: 'weixin' }),
       uni.getUserProfile({ desc: '用于完善会员资料' }),
     ]);
-    await authStore.loginWechart(res[0].code, res[1]);
+    await authStore.loginWechart(res[0].code, res[1], recommendUserId.value);
     toast({
       type: 'success',  
       content: '登录成功',
@@ -239,7 +242,7 @@ async function addSubmit() {
   try {
     addFormLoading.value = true;
     addFormModel.value.villageId = querys.value.villageId;
-    await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo);
+    await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo, recommendUserId.value);
     await suscribePassMessage();
     toast({ content: '提交成功' });
     finishedMode.value = 'claim';

+ 4 - 2
src/pages/home/village/composeabe/Follow.ts

@@ -1,13 +1,15 @@
-import FollowVillageApi from "@/api/light/FollowVillageApi";
 import { useRequireLogin } from "@/common/composeabe/RequireLogin";
+import { useShareLink } from "../../composeabe/ShareLink";
 import { useVillageStore } from "@/store/village";
 import { computed } from "vue";
 import { toast, confirm } from "@/components/dialog/CommonRoot";
 import LightVillageApi from "@/api/light/LightVillageApi";
+import FollowVillageApi from "@/api/light/FollowVillageApi";
 
 export function useFollow() {
 
   const { requireLogin } = useRequireLogin();
+  const { recommendUserId } = useShareLink();
   const villageStore = useVillageStore();
   const isFollowed = computed(() => {
     return villageStore.myFollowVillages.some(p => p.id === villageStore.currentVillage?.id);
@@ -18,7 +20,7 @@ export function useFollow() {
       return;
     requireLogin(async () => {
       try {
-        await FollowVillageApi.followVillage(villageStore.currentVillage!.id);
+        await FollowVillageApi.followVillage(villageStore.currentVillage!.id, recommendUserId.value);
         const info = await LightVillageApi.getVillageDetails(villageStore.currentVillage!.id);
         villageStore.myFollowVillages.push(info);
         toast('关注成功');

+ 4 - 5
src/pages/home/village/dialogs/ClamVolunteerDialog.vue

@@ -39,7 +39,9 @@
 import { ref } from 'vue';
 import { toast } from '@/components/dialog/CommonRoot';
 import { showError } from '@/common/composeabe/ErrorDisplay';
+import { getClaimVillageForm } from '../../light/form/claim';
 import { useVillageStore } from '@/store/village';
+import { useShareLink } from '../../composeabe/ShareLink';
 import VillageApi, { VillageClaimInfo } from '@/api/inhert/VillageApi';
 import CommonDialog from '@/common/components/CommonDialog.vue';
 import FrameButton from '@/common/components/FrameButton.vue';
@@ -51,11 +53,7 @@ import Height from '@/components/layout/space/Height.vue';
 import Result from '@/components/feedback/Result.vue';
 import ProvideVar from '@/components/theme/ProvideVar.vue';
 import BoxMid from '@/common/components/box/BoxMid.vue';
-import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
 import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
-import type { FieldProps } from '@/components/form/Field.vue';
-import type { RuleItem } from 'async-validator';
-import { getClaimVillageForm } from '../../light/form/claim';
 
 const show = ref(false);
 const props = defineProps<{
@@ -63,6 +61,7 @@ const props = defineProps<{
 }>();
 const emit = defineEmits(['finish']);
 
+const { recommendUserId } = useShareLink();
 const villageStore = useVillageStore();
 const step = ref('form');
 
@@ -84,7 +83,7 @@ async function addSubmit() {
   try {
     addFormLoading.value = true;
     addFormModel.value.villageId = props.villageId;
-    await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo);
+    await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo, recommendUserId.value);
     toast({ content: '提交成功' });
     step.value = 'finished';
     villageStore.loadMyJoinedVillages();

+ 6 - 3
src/pages/home/village/dialogs/JoinDialog.vue

@@ -61,6 +61,7 @@ import { ref } from 'vue';
 import { toast } from '@/components/dialog/CommonRoot';
 import { showError } from '@/common/composeabe/ErrorDisplay';
 import { useVillageStore } from '@/store/village';
+import { useShareLink } from '../../composeabe/ShareLink';
 import VillageApi, { VillageClaimInfo } from '@/api/inhert/VillageApi';
 import CommonDialog from '@/common/components/CommonDialog.vue';
 import FrameButton from '@/common/components/FrameButton.vue';
@@ -71,12 +72,12 @@ import FlexCol from '@/components/layout/FlexCol.vue';
 import FlexRow from '@/components/layout/FlexRow.vue';
 import Height from '@/components/layout/space/Height.vue';
 import Touchable from '@/components/feedback/Touchable.vue';
-import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
-import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
 import Result from '@/components/feedback/Result.vue';
 import Width from '@/components/layout/space/Width.vue';
 import ProvideVar from '@/components/theme/ProvideVar.vue';
 import BoxMid from '@/common/components/box/BoxMid.vue';
+import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
+import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
 
 const show = ref(false);
 const props = defineProps<{
@@ -85,6 +86,8 @@ const props = defineProps<{
 const emit = defineEmits(['finish']);
 
 const villageStore = useVillageStore();
+const { recommendUserId } = useShareLink();
+
 const step = ref('chooseIdentity');
 
 const identityChoices = ref([
@@ -207,7 +210,7 @@ async function addSubmit() {
   try {
     addFormLoading.value = true;
     addFormModel.value.villageId = props.villageId;
-    await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo);
+    await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo, recommendUserId.value);
     toast({ content: '提交成功' });
     step.value = 'finished';
     villageStore.loadMyJoinedVillages();

+ 4 - 1
src/pages/home/village/dialogs/ShareQRDialog.vue

@@ -20,6 +20,7 @@
 import { ref } from 'vue';
 import { useSimpleDataLoader } from '@/components/composeabe/loader/SimpleDataLoader';
 import { envVersion } from '@/common/config/AppCofig';
+import { useAuthStore } from '@/store/auth';
 import CommonDialog from '@/common/components/CommonDialog.vue';
 import Image from '@/components/basic/Image.vue';
 import FlexCol from '@/components/layout/FlexCol.vue';
@@ -27,13 +28,15 @@ import Text from '@/components/basic/Text.vue';
 import SimplePageContentLoader from '@/components/loader/SimplePageContentLoader.vue';
 import LightVillageApi from '@/api/light/LightVillageApi';
 
+const authStore = useAuthStore();
+
 const show = ref(false);
 const props = defineProps<{
   villageId: number,
 }>();
 
 const loader = useSimpleDataLoader(async () => {
-  const scense = `invg:${props.villageId}`;
+  const scense = `invg:${props.villageId}:${authStore.userId || 0}`;
   return await LightVillageApi.getInviteQrcode({
     scene: scense,
     width: 430,

+ 3 - 1
src/pages/user/login.vue

@@ -75,6 +75,7 @@
 <script setup lang="ts">
 import { useTheme } from '@/components/theme/ThemeDefine';
 import { useAuthStore } from '@/store/auth';
+import { useShareLink } from '../home/composeabe/ShareLink';
 import { useAppInit } from '@/common/composeabe/AppInit';
 import { waitTimeOut } from '@imengyu/imengyu-utils';
 import { onMounted, ref } from 'vue';
@@ -110,6 +111,7 @@ const type = ref('wechat');
 const authStore = useAuthStore();
 const themeContext = useTheme();
 const { init } = useAppInit();
+const { recommendUserId } = useShareLink();
 
 const loginFormModel = ref({
   mobile: '',
@@ -154,7 +156,7 @@ async function loginWechat() {
     ])
 
     //登录微信
-    await authStore.loginWechart(res[0].code, res[1]);
+    await authStore.loginWechart(res[0].code, res[1], recommendUserId.value);
     toast({  type: 'success',content: '登录成功' });
     await loginAfter();
   } catch(e) {

+ 2 - 1
src/store/auth.ts

@@ -44,7 +44,7 @@ export const useAuthStore = defineStore('auth', {
     /**
      * 微信登录
      */
-    async loginWechart(code: string, res: UniApp.GetUserProfileRes) {
+    async loginWechart(code: string, res: UniApp.GetUserProfileRes, recommendUserId: number) {
       const loginResult = await UserApi.loginThird({
         code,
         encrypted_data: res.encryptedData,
@@ -52,6 +52,7 @@ export const useAuthStore = defineStore('auth', {
         platform: 'wechat',
         raw_data: JSON.parse(res.rawData),
         signature: res.signature,
+        recommend_user_id: recommendUserId || 0,
       })
       await this.loginResultHandle(
         loginResult, 

+ 0 - 7
src/store/village.ts

@@ -13,8 +13,6 @@ export const useVillageStore = defineStore('village', () => {
   const currentLonlat = ref<{ longitude: number, latitude: number } | null>(null);
   const myFollowVillages = ref<VillageListItem[]>([]);
   const myJoinedVillages = ref<VillageListItem[]>([]);
-  const shareFromVillageUserId = ref(0);
-
   async function setCurrentVillage(village: VillageListItem) {
     currentVillage.value = await LightVillageApi.getVillageDetails(village.id);
     console.log('切换当前激活村社', currentVillage.value);
@@ -46,22 +44,17 @@ export const useVillageStore = defineStore('village', () => {
     const res = await FollowVillageApi.getClaimedVallageList();
     myJoinedVillages.value = res;
   }
-  function setShareFromVillageUserId(userId: number) {
-    shareFromVillageUserId.value = userId;
-  }
 
   return { 
     currentVillage,
     currentLonlat,
     myFollowVillages,
     myJoinedVillages,
-    shareFromVillageUserId,
     loadCurrentVillage,
     reloadVillageInfo,
     setCurrentVillage,
     setCurrentLonlat,
     loadMyFollowVillages,
     loadMyJoinedVillages,
-    setShareFromVillageUserId,
   }
 })