新增注册来源功能

This commit is contained in:
wangxiaowei
2026-01-18 00:48:27 +08:00
parent b7e2d5d4c9
commit 1e09782256
9 changed files with 71 additions and 12 deletions

View File

@ -2,9 +2,10 @@
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { navigateToInterceptor } from '@/router/interceptor'
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
import { useUserStore } from '@/store'
import { strToParams } from '@/utils/tools'
onLaunch((options) => {
// console.log("🚀 ~ onLaunch options:", options)
// if (options?.path === 'bundle/order/tea-room/order-detail') {
// uni.setStorageSync('transferOrder', {
// orderId: options?.query?.orderId || '',
@ -33,6 +34,18 @@
shareSource: options?.query?.shareSource || ''
})
}
// 这里是设置用户场景类型的逻辑: 0 普通扫码进入 1 电梯扫码进入 2 充电宝扫码进入
if (options?.query?.scene) {
const scene = decodeURIComponent(options.query.scene)
const params = strToParams(scene)
if (params && params?.registerSource) {
const userStore = useUserStore()
userStore.setUserRegisterSource(Number(params.registerSource))
console.log("🚀 ~ onShow registerSource =", userStore.userRegisterSource)
}
}
console.log('App Show', options)
})
onHide(() => {

View File

@ -23,4 +23,8 @@ export function getHomeCouponPopup() {
*/
export function claimIndexCoupon() {
return http.Post('/api/UserCoupon/shouyeCoupon', {})
}
export function getWxacode() {
return http.Post('/api/wxCode/getWxacode', {})
}

View File

@ -91,10 +91,10 @@ export function getWxCode() {
/**
* 微信登录
* @param params 微信登录参数包含code
* @param params 微信登录参数包含code, reg_source(注册来源,可选)
* @returns Promise 包含登录结果
*/
export function wxLogin(data: { code: string }) {
export function wxLogin(data: { code: string, source?: number }) {
return http.Post<IUserLogin>('/api/login/mnpLogin',
data,
{

View File

@ -64,7 +64,6 @@
<!-- 团购券 -->
<view v-if="couponType == 2">
checkedId--{{checkedId}}
<view class="mx-30rpx">
<view class="mx30rpx">
<text class="text-[#303133] font-bold text-30rpx leading-42rpx">可用团购券</text>

View File

@ -40,11 +40,21 @@
<view>-{{ bill.groupCoupon || 0 }}</view>
</view>
<view class="flex justify-between items-center text-24rpx text-[#909399] leading-34rpx mt-16rpx">
<view>会员</view>
<view>会员折</view>
<view>-{{ bill.discount }}</view>
</view>
</view>
<!-- <view class="flex justify-between items-center text-30rpx text-[#303133] leading-42rpx">
<view>茶叶费</view>
<view>{{ bill.service.total }}</view>
</view>
<view class="flex justify-between items-center text-30rpx text-[#303133] leading-42rpx">
<view>茶具费</view>
<view>{{ bill.service.total }}</view>
</view> -->
<view class="my-30rpx">
<wd-gap height="2rpx" bgColor='#F6F7F9'></wd-gap>
</view>

View File

@ -142,7 +142,7 @@
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
import useMescroll from "@/uni_modules/mescroll-uni/hooks/useMescroll.js"
import { LOCATION_DENY_TIME_KEY, handleEnsureLocationAuthHooks, LOCATION_DEFAULT_CITY, handleGetLocationCity, LOCATION_CITY_KEY, handleForceGetLocation } from '@/hooks/useLocation'
import { getHomeBannerList, getHomeCouponPopup, claimIndexCoupon } from '@/api/home'
import { getHomeBannerList, getHomeCouponPopup, claimIndexCoupon, getWxacode } from '@/api/home'
import { getHomeTeaStoreList } from '@/api/tea-room'
import { useUserStore } from '@/store'
import { useToast } from 'wot-design-uni'
@ -213,7 +213,11 @@
}
})
onLoad(async() => {
onLoad(async(args) => {
// 获取小程序码注册来源
// getWxacode().then( res => {})
// 初始化页面数据
Index.handleInit()

View File

@ -62,6 +62,7 @@
const OSS = inject('OSS')
const env = import.meta.env.VITE_NODE_ENV
const userStore = useUserStore()
// 服务协议条款
const agree = ref<boolean>(false)
@ -89,7 +90,7 @@
mask: true
})
try {
const userStore = useUserStore()
console.log("🚀 ~ Login userRegisterSource=", userStore.userRegisterSource)
const res = await userStore.wxLogin()
console.log("🚀 ~ res:", res)
console.log("🚀 ~ token:", uni.getStorageSync('token'))
@ -122,6 +123,7 @@
* 一键授权绑定手机号码
*/
handleBindMobile: async (e: any) => {
console.log("🚀 ~ e:", e)
uni.showLoading({ title: '绑定中...', mask: true })
try {
await getMobileByMnp(e.code)

View File

@ -26,9 +26,13 @@ const userInfoState: IUserInfoVo = {
mobile: '',
username: '',
}
export const useUserStore = defineStore(
'user',
() => {
// 用户扫码登录场景类型
const userRegisterSource = ref<number>(0) // 0 普通扫码登录/注册 1 电梯扫码登录/注册 2 访客充电宝扫码登录/注册
// 默认未登录
const isLoggedIn = ref<boolean>(false)
// 定义用户信息
@ -114,7 +118,10 @@ export const useUserStore = defineStore(
const data = await getWxCode()
console.log('微信登录code', data)
const res = await _wxLogin(data)
// 添加注册来源
const loginData = { ...data, source: userRegisterSource.value }
const res = await _wxLogin(loginData)
uni.setStorageSync('token', res.token)
const user = await getUserInfo()
@ -127,6 +134,11 @@ export const useUserStore = defineStore(
return res && user
}
// 设置用户扫码登录场景类型
const setUserRegisterSource = (source: number) => {
userRegisterSource.value = source
}
return {
userInfo,
login,
@ -137,7 +149,9 @@ export const useUserStore = defineStore(
setUserInfo,
removeUserInfo,
isLoggedIn,
mobileLogin
mobileLogin,
setUserRegisterSource,
userRegisterSource
}
},
{

View File

@ -175,4 +175,17 @@ export function previewImage(current: string, urls: string[]) {
current,
urls
})
}
}
/**
* uri字符串转对象
* @param uri
* @returns
*/
export function strToParams(uri: string) :any {
let newparams = {}
for (let item of uri.split('&')) {
newparams[item.split('=')[0]] = item.split('=')[1]
}
return newparams
}