diff --git a/src/App.vue b/src/App.vue index 78fbb31..6828f57 100644 --- a/src/App.vue +++ b/src/App.vue @@ -17,7 +17,7 @@ } // 微信静默授权 - await snsapiBaseAuthorize() + // await snsapiBaseAuthorize() // await initJweixinSDK() }) onShow((options) => { diff --git a/src/api/tea.ts b/src/api/tea.ts index 308c43d..b4b2da3 100644 --- a/src/api/tea.ts +++ b/src/api/tea.ts @@ -8,6 +8,7 @@ export interface ITeaSpecialistDetailsParams { id: number longitude: number latitude: number + user_id: number } export function getTeaSpecialistDetails(data: ITeaSpecialistDetailsParams) { @@ -24,7 +25,6 @@ export function getTeaSpecialistDetails(data: ITeaSpecialistDetailsParams) { */ export interface ICollectTeaSpecialistParams { id: number - user_id: number status: number } diff --git a/src/api/types/jwexin.ts b/src/api/types/jwexin.ts index 18a11d7..3418023 100644 --- a/src/api/types/jwexin.ts +++ b/src/api/types/jwexin.ts @@ -11,3 +11,13 @@ export interface IJweiXin { timestamp: number url: string } + +/** + * JSSDK 分享参数 + */ +export interface IJweiXinShareParams { + title: '' | string + desc: '' | string + link: '' | string + imgUrl: '' | string +} \ No newline at end of file diff --git a/src/api/types/tea.ts b/src/api/types/tea.ts index 79274d6..4610a77 100644 --- a/src/api/types/tea.ts +++ b/src/api/types/tea.ts @@ -11,6 +11,7 @@ export interface ITeaSpecialistDetailsResult { export interface ITeaSpecialistDetailsFields { name: string star: number + image: string reservation_num: number distance: number speed: number @@ -25,4 +26,5 @@ export interface ITeaSpecialistDetailsFields { teamasterLevel: Array price: number fare_price: number + collect: number } \ No newline at end of file diff --git a/src/hooks/useWeiXin.ts b/src/hooks/useWeiXin.ts index 0dfe503..087363d 100644 --- a/src/hooks/useWeiXin.ts +++ b/src/hooks/useWeiXin.ts @@ -1,11 +1,13 @@ import {wxSnsapiBaseLogin} from '@/api/login' import { useUserStore } from '@/store' import type { IUserInfoVo } from '@/api/types/login' +import { jump, NAVIGATE_TO } from '@/utils/tools' +import { toast } from '@/utils/toast' /** * 微信静默授权 */ -const getUrlCode = (): { [key: string]: string | undefined } => { +export const getUrlCode = (): { [key: string]: string | undefined } => { // 截取url中的code方法 const url = location.search // this.winUrl = url; @@ -25,34 +27,23 @@ const getUrlCode = (): { [key: string]: string | undefined } => { */ export async function snsapiBaseAuthorize() { // TODO 测试代码 - // wxSnsapiBaseLogin({code: '051wM51w3488N53ThD3w3obLDm2wM51r'}).then((res: IUserInfoVo) => { - // console.log("登录成功 ~ snsapiBaseAuthorize ~ res:", res) - // // 映射 IUserLogin 到 IUserInfoVo - // useUserStore().setUserInfo(res) - // }).catch(err => { - // // 失败就重新授权 - // uni.setStorageSync('wechatCode', 0) - // console.log('请求失败', err) - // }) - // const res = { - // account: "u39317465", - // avatar: "https://cz.stnav.com/uploads/user/avatar/c2b3c5f94e3f20c8a989bd302519b4c7.jpeg", - // channel:2, - // is_new_user: 1, - // id: 4, - // sn:"39317465", - // token: "013f5128f0208f2f9d9285af5070ae7b", - // nickname: '微信用户', - // mobile: '15005837859' - // } - // useUserStore().setUserInfo(res) - // console.log(useUserStore().userInfo) + // wxSnsapiBaseLogin({code: '001Vgi0w3dwIP538nE1w32v6j83Vgi0X'}).then((res: IUserInfoVo) => { + // console.log("登录成功 ~ snsapiBaseAuthorize ~ res:", res) + // // 映射 IUserLogin 到 IUserInfoVo + // useUserStore().setUserInfo(res) + // }).catch(err => { + // // 失败就重新授权 + // uni.setStorageSync('wechatCode', 0) + // console.log('请求失败', err) + // }) + // return let local = window.location.href // 获取页面url let appid = import.meta.env.VITE_WX_SERVICE_ACCOUNT_APPID // 公众号的APPID - console.log("🚀 ~ snsapiBaseAuthorize ~ appid:", appid) let code = getUrlCode().code // 截取code + console.log("🚀 ~ snsapiBaseAuthorize ~ code:", code) + // 获取之前的code let oldCode = uni.getStorageSync('wechatCode') @@ -63,7 +54,7 @@ export async function snsapiBaseAuthorize() { // 设置旧的code为0,避免死循环 uni.setStorageSync('wechatCode',0) window.location.href = - `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect` + `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect` } else { // 保存最新code uni.setStorageSync('wechatCode',code) @@ -72,6 +63,13 @@ export async function snsapiBaseAuthorize() { const res: IUserInfoVo = await wxSnsapiBaseLogin({code}) console.log("登录成功 ~ snsapiBaseAuthorize ~ res:", res) useUserStore().setUserInfo(res) + if (!res.mobile) { + // 如果没有绑定手机号的话需要去绑定手机号 + toast.info('请先绑定手机号') + jump('/pages/login/mobile', NAVIGATE_TO, 500) + } else { + uni.$emit('loginSuccess') + } } catch (err) { uni.setStorageSync('wechatCode', 0) console.log('请求失败', err) diff --git a/src/http/alova.ts b/src/http/alova.ts index 268be32..2dc5fb3 100644 --- a/src/http/alova.ts +++ b/src/http/alova.ts @@ -7,6 +7,7 @@ import VueHook from 'alova/vue' import { toast } from '@/utils/toast' import { ContentTypeEnum, ResultEnum, ShowMessage } from './tools/enum' import { useUserStore } from '@/store' +import { jump, SWITCH_TAB, NAVIGATE_TO } from '@/utils/tools' // 配置动态Tag export const API_DOMAINS = { @@ -67,14 +68,20 @@ const alovaInstance = createAlova({ // method.config.headers.token = token; const userStore = useUserStore() - const { token } = userStore.userInfo as unknown as IUserInfo + const { token, mobile } = userStore.userInfo as unknown as IUserInfo + if (!token) { toast.info('请先登录') - setTimeout(() => { - uni.switchTab({ url: '/pages/my/my' }) - }, 500) + jump('/pages/my/my', SWITCH_TAB, 500) throw new Error('[请求错误]:未登录') } + + if (!mobile) { + toast.info('请先绑定手机号') + jump('/pages/login/mobile', NAVIGATE_TO, 500) + throw new Error('[请求错误]:未绑定手机号') + } + method.config.headers.token = token; } @@ -124,6 +131,12 @@ const alovaInstance = createAlova({ // throw new Error(`登录超时[${code}]:${msg}`) // } + if (code === ResultEnum.Success) { + if (config.meta?.toast !== false && msg) { + toast.info(msg) + } + } + if (code !== ResultEnum.Success) { if (config.meta?.toast !== false) { toast.warning(msg) diff --git a/src/pages/index/detail.vue b/src/pages/index/detail.vue index fe87f32..58dd84b 100644 --- a/src/pages/index/detail.vue +++ b/src/pages/index/detail.vue @@ -72,8 +72,12 @@