diff --git a/src/App.vue b/src/App.vue index 19c907f..6615054 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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(() => { diff --git a/src/api/home.ts b/src/api/home.ts index 23f4f53..3ba1b0c 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -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', {}) } \ No newline at end of file diff --git a/src/api/login.ts b/src/api/login.ts index d229080..a82d272 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -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('/api/login/mnpLogin', data, { diff --git a/src/bundle/coupon/coupon.vue b/src/bundle/coupon/coupon.vue index 5a21bff..e1d929d 100644 --- a/src/bundle/coupon/coupon.vue +++ b/src/bundle/coupon/coupon.vue @@ -64,7 +64,6 @@ - checkedId--{{checkedId}} 可用团购券 diff --git a/src/bundle/tea-room/choose-room-reserve.vue b/src/bundle/tea-room/choose-room-reserve.vue index 2569852..d731e59 100644 --- a/src/bundle/tea-room/choose-room-reserve.vue +++ b/src/bundle/tea-room/choose-room-reserve.vue @@ -40,11 +40,21 @@ -¥{{ bill.groupCoupon || 0 }} - 会员八折 + 会员折扣 -¥{{ bill.discount }} + + diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 9ec1630..b2ad6ee 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -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() diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index ae0d5be..7dd5b68 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -62,6 +62,7 @@ const OSS = inject('OSS') const env = import.meta.env.VITE_NODE_ENV + const userStore = useUserStore() // 服务协议条款 const agree = ref(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) diff --git a/src/store/user.ts b/src/store/user.ts index c56b534..1469246 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -26,9 +26,13 @@ const userInfoState: IUserInfoVo = { mobile: '', username: '', } + export const useUserStore = defineStore( 'user', () => { + // 用户扫码登录场景类型 + const userRegisterSource = ref(0) // 0 普通扫码登录/注册 1 电梯扫码登录/注册 2 访客充电宝扫码登录/注册 + // 默认未登录 const isLoggedIn = ref(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 } }, { diff --git a/src/utils/tools.ts b/src/utils/tools.ts index ba16c20..f9f22c4 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -175,4 +175,17 @@ export function previewImage(current: string, urls: string[]) { current, urls }) -} \ No newline at end of file +} + +/** + * 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 +}