对接接口

This commit is contained in:
wangxiaowei
2025-10-14 18:08:12 +08:00
parent 0ff0df7d5b
commit 76da09be91
12 changed files with 180 additions and 79 deletions

2
env/.env vendored
View File

@ -8,7 +8,7 @@ VITE_WX_APPID = 'wxa2abb91f64032a2b'
VITE_APP_PUBLIC_BASE = '/h5'
# 登录页面
VITE_LOGIN_URL = '/pages/login/login'
VITE_LOGIN_URL = '/pages/login/mobile'
# 第一个请求地址
VITE_SERVER_BASEURL = 'https://cz.stnav.com'

View File

@ -17,7 +17,7 @@
}
// 微信静默授权
// snsapiBaseAuthorize()
snsapiBaseAuthorize()
initJweixinSDK()
})
onShow((options) => {

27
src/api/home.ts Normal file
View File

@ -0,0 +1,27 @@
import { http } from '@/http/alova'
import type { IIndexResult } from '@/api/types/home'
/**
* 获取首页数据
*/
export interface IIndexData {
id: number
}
export function getDecorate(data: IIndexData) {
return http.Get('/api/index/decorate', {params: data})
}
/**
* 获取茶艺师等级
*/
export function getTeaSpecialistLevels() {
return http.Post('/api/Teamaster/teamasterLevel')
}
/**
* 获取茶艺师列表
*/
export function getTeaSpecialist() {
return http.Post('/api/Teamaster/teamasterLevel')
}

View File

@ -11,7 +11,9 @@ export interface IWxSnsapiBaseLoginForm {
}
export function wxSnsapiBaseLogin(data: IWxSnsapiBaseLoginForm) {
return http.Post<IUserInfoVo>('/api/login/oaLogin', data)
return http.Post<IUserInfoVo>('/api/login/oaLogin', data, {
meta: { ignoreAuth: true }, // 忽略认证
})
}
/**
@ -24,7 +26,19 @@ export interface IPhoneLoginForm {
}
export function phoneLogin(data: IPhoneLoginForm) {
return http.Post<IUserLogin>('/api/login/oaLogin', {params: data})
return http.Post<IUserLogin>('/api/login/oaLogin', data)
}
/**
* 获取验证码
*/
export interface ISMSLogin {
mobile: number,
scene: string
}
export function smsCode(data: ISMSLogin) {
return http.Post('/api/sms/sendCode',data)
}
/**

6
src/api/types/home.ts Normal file
View File

@ -0,0 +1,6 @@
/**
* 首页初始化返回数据
*/
export interface IIndexResult {
data: String
}

View File

@ -25,49 +25,57 @@ const getUrlCode = (): { [key: string]: string | undefined } => {
*/
export function snsapiBaseAuthorize() {
// TODO 测试代码
const res = {
account: "u39317465",
avatar: "https://cz.stnav.com/uploads/user/avatar/c2b3c5f94e3f20c8a989bd302519b4c7.jpeg",
channel:2,
is_new_user: 1,
id: 1,
sn:"39317465",
token: "14a11310d926121e352afec2ef1d2f7f",
nickname: '微信用户',
mobile: '15005837859'
}
useUserStore().setUserInfo(res)
console.log(useUserStore().userInfo)
return
// wxSnsapiBaseLogin({code: '0316MW1w32OBM53meU2w3GPdbe16MW1p'}).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: "c6416f9ebed9f06d3807d01e9c9a9693",
// nickname: '微信用户',
// mobile: '15005837859'
// }
// useUserStore().setUserInfo(res)
// // console.log(useUserStore().userInfo)
// 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
// 获取之前的code
let oldCode = uni.getStorageSync('wechatCode')
// 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
// // 获取之前的code
// let oldCode = uni.getStorageSync('wechatCode')
if (code == null || code === '' || code == 'undefined' || code == oldCode) {
// 如果没有code就去请求获取code
console.log('当前没有code进入授权页面')
let uri = encodeURIComponent(local)
// 设置旧的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_userinfo&state=123#wechat_redirect`
} else {
// 保存最新code
uni.setStorageSync('wechatCode',code)
// 使用code换取用户信息
wxSnsapiBaseLogin({code}).then((res: IUserInfoVo) => {
console.log("登录成功 ~ snsapiBaseAuthorize ~ res:", res)
// 映射 IUserLogin 到 IUserInfoVo
useUserStore().setUserInfo(res)
console.log('登录成功 ~ ' + useUserStore().userInfo)
}).catch(err => {
// 失败就重新授权
uni.setStorageSync('wechatCode', 0)
console.log('请求失败', err)
})
}
// if (code == null || code === '' || code == 'undefined' || code == oldCode) {
// // 如果没有code就去请求获取code
// console.log('当前没有code进入授权页面')
// let uri = encodeURIComponent(local)
// // 设置旧的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_userinfo&state=123#wechat_redirect`
// } else {
// // 保存最新code
// uni.setStorageSync('wechatCode',code)
// // 使用code换取用户信息
// wxSnsapiBaseLogin({code}).then((res: IUserInfoVo) => {
// console.log("登录成功 ~ snsapiBaseAuthorize ~ res:", res)
// // 映射 IUserLogin 到 IUserInfoVo
// useUserStore().setUserInfo(res)
// }).catch(err => {
// // 失败就重新授权
// uni.setStorageSync('wechatCode', 0)
// console.log('请求失败', err)
// })
// }
}

View File

@ -56,15 +56,26 @@ const alovaInstance = createAlova({
}
const { config } = method
console.log("🚀 ~ config.meta?.ignoreAuth:", config)
const ignoreAuth = !config.meta?.ignoreAuth
console.log('ignoreAuth===>', ignoreAuth)
// 处理认证信息 自行处理认证问题
if (ignoreAuth) {
const token = 'getToken()'
// const token = 'getToken()'
// if (!token) {
// throw new Error('[请求错误]:未登录')
// }
// method.config.headers.token = token;
const userStore = useUserStore()
const { token } = userStore.userInfo as unknown as IUserInfo
console.log("🚀 ~ userStore.userInfo:", userStore.userInfo)
console.log("🚀 ~ token:", token)
if (!token) {
throw new Error('[请求错误]:未登录')
}
// method.config.headers.token = token;
method.config.headers.token = token;
}
// 处理动态域名
@ -102,12 +113,22 @@ const alovaInstance = createAlova({
// }
// 处理业务逻辑错误
const { code, message, data } = rawData as IResponse
const { code, msg, data } = rawData as IResponse
// if (code === ResultEnum.Unauthorized) {
// if (config.meta?.toast !== false) {
// toast.info(msg)
// setTimeout(() => {
// uni.navigateTo({ url: '/pages/login/mobile' })
// })
// }
// throw new Error(`登录超时[${code}]${msg}`)
// }
if (code !== ResultEnum.Success) {
if (config.meta?.toast !== false) {
toast.warning(message)
toast.warning(msg)
}
throw new Error(`请求错误[${code}]${message}`)
throw new Error(`请求错误[${code}]${msg}`)
}
// 处理成功响应,返回业务数据
return data

View File

@ -1,7 +1,7 @@
export enum ResultEnum {
Success = 1, // 成功
Error = 0, // 错误
Unauthorized = 401, // 未授权
Unauthorized = -1, // 未授权
Forbidden = 403, // 禁止访问原为forbidden
NotFound = 404, // 未找到原为notFound
MethodNotAllowed = 405, // 方法不允许原为methodNotAllowed

View File

@ -11,7 +11,7 @@ export type CustomRequestOptions = UniApp.RequestOptions & {
export interface IResponse<T = any> {
code: number | string
data: T
message: string
msg: string
status: string | number
}

View File

@ -74,11 +74,11 @@
<!-- 茶艺师等级筛选 -->
<view class="flex items-center text-#303133 overflow-x-auto whitespace-nowrap ml-30rpx my-30rpx tea-level-scrollbar">
<view
class="h-64rpx rounded-12rpx px-24rpx py-12rpx flex items-center justify-center font-400 text-28rpx mr-20rpx"
:class="selectedLevel.includes(item.value) ? 'bg-[#4C9F44] text-[#fff]' : 'bg-[#FFF] text-[#606266]'"
v-for="(item, index) in TeaSpecialistLevels" :key="index"
@click="Index.handleToggleTeaSpecialistLevel(item.value)">
{{ item.label }}
class="h-64rpx rounded-12rpx px-24rpx py-12rpx flex items-center justify-center font-400 text-28rpx mr-20rpx"
:class="selectedLevel.includes(item.id) ? 'bg-[#4C9F44] text-[#fff]' : 'bg-[#FFF] text-[#606266]'"
@click="Index.handleToggleTeaSpecialistLevel(item.id)">
{{ item.level_name}}
</view>
</view>
@ -146,22 +146,34 @@
<script lang="ts" setup>
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
import useMescroll from "@/uni_modules/mescroll-uni/hooks/useMescroll.js"
import {TeaSpecialistLevels} from '@/utils/teaSpecialist'
import TeaSpecialistLevel from '@/components/TeaSpecialistLevel.vue'
import { OrderSource, OrderStatus } from '@/utils/order'
import {getlocation} from '@/utils/jwexin'
import {getDecorate, getTeaSpecialistLevels} from '@/api/home'
// import {TeaSpecialistLevels} from '@/utils/teaSpecialist'
const OSS = inject('OSS')
// 茶艺师等级
const TeaSpecialistLevels = reactive<Array<{ id: number, status: number, level_name: string}>>([])
const selectedLevel = ref<Array<any>>([]) // 选择茶艺师的点击等级
// 分页
const { mescrollInit, downCallback } = useMescroll(onPageScroll, onReachBottom) // 调用mescroll的hook
onLoad(() => {
getlocation((res) => {
console.log('经纬度:' + res.latitude + ',' + res.longitude)
// getlocation((res) => {
// console.log('经纬度:' + res.latitude + ',' + res.longitude)
// })
// getDecorate({id: 1}).then((res: any) => {
// const data = JSON.parse(res.data)
// console.log('装修数据:', data)
// })
// 获取茶艺师等级
getTeaSpecialistLevels().then((res:Array<any>) => {
TeaSpecialistLevels.push(...res)
})
})

View File

@ -14,12 +14,12 @@
<view class="font-400 text-28rpx leading-44rpx text-[#6B7280] mt-12rpx"> {{ page.desc }}</view>
</view>
<view class="mt-106rpx mx-48rpx">
<wd-form ref="form" :model="model">
<wd-form ref="form" :model="form">
<view>
<view class="font-400 text-30rpx text-[#606266] leading-44rpx">手机号</view>
<view class="mt-20rpx">
<wd-input
v-model="model.mobile"
v-model="form.mobile"
type="text"
placeholder="请输入手机号码"
inputmode="numeric"
@ -34,7 +34,7 @@
<view class="mt-40rpx">
<view class="font-400 text-30rpx text-[#606266] leading-44rpx">验证码</view>
<view class="mt-20rpx">
<wd-input type="text" placeholder="请输入验证码" v-model="model.code" inputmode="numeric" no-border custom-class="!bg-[#F6F7F8] !border !border-solid !border-[#EAECF0] !rounded-16rpx" custom-input-class="!px-32rpx !h-104rpx">
<wd-input type="text" placeholder="请输入验证码" v-model="form.code" inputmode="numeric" no-border custom-class="!bg-[#F6F7F8] !border !border-solid !border-[#EAECF0] !rounded-16rpx" custom-input-class="!px-32rpx !h-104rpx">
<template #suffix>
<view class="flex items-center mr-34rpx">
<view class="flex items-center">
@ -87,10 +87,11 @@
<script lang="ts" setup>
import {mobile as testMobile} from '@/utils/test'
import {useToast} from 'wot-design-uni'
import {smsCode} from '@/api/login'
const OSS = inject('OSS')
const toast = useToast()
const disabled = ref<boolean>(true)
const disabled = ref<boolean>(false)
/** 页面 **/
let pageType = 'login' // 页面类型 login:登录 edit:修改手机号
@ -104,11 +105,11 @@
const countDown = ref<any>(null) // 倒计时组件
/** 表单相关 **/
const model = reactive<{
const form = reactive<{
mobile: string
code: string
}>({
mobile: '',
mobile: '15005837859',
code: ''
})
/** 结束 **/
@ -131,8 +132,8 @@
const mobile = {
// 验证手机号
handleInputMobile: (e: {value: string}) => {
model.mobile = e.value
disabled.value = !testMobile(model.mobile)
form.mobile = e.value
disabled.value = !testMobile(form.mobile)
},
// 发送验证码
@ -151,6 +152,18 @@
countDown.value?.start()
// 发送验证码请求
console.log("🚀 ~ 发送验证码请求:")
smsCode({ mobile: Number(form.mobile), scene: 'YZMDL' }).then(() => {
toast.show({
iconClass: 'success-circle',
msg: '验证码发送成功',
direction: 'vertical'
})
}).catch((err) => {
console.log("🚀 ~ err:", err)
startCountDown.value = false
countDown.value?.reset()
})
})
},
@ -172,7 +185,7 @@
return
}
if (!testMobile(model.mobile)) {
if (!testMobile(form.mobile)) {
toast.show({
iconClass: 'info-circle',
msg: '手机号码错误请重新输入',
@ -181,7 +194,7 @@
return
}
if (!model.code) {
if (!form.code) {
toast.show({
iconClass: 'info-circle',
msg: '验证码错误',

View File

@ -9,9 +9,9 @@ export enum TeaSpecialistLevel {
// 茶艺师对象结构
export const TeaSpecialistLevels = [
{ value: 'gold', label: TeaSpecialistLevel.Gold},
{ value: 'senior', label: TeaSpecialistLevel.Senior },
{ value: 'intermediate', label: TeaSpecialistLevel.Intermediate },
{ value: 'junior', label: TeaSpecialistLevel.Junior },
{ value: 'enthusiast', label: TeaSpecialistLevel.Enthusiast }
{ id: 1, value: 'gold', label: TeaSpecialistLevel.Gold},
{ id: 2,value: 'senior', label: TeaSpecialistLevel.Senior },
{ id: 3,value: 'intermediate', label: TeaSpecialistLevel.Intermediate },
{ id: 4,value: 'junior', label: TeaSpecialistLevel.Junior },
{ id: 5,value: 'enthusiast', label: TeaSpecialistLevel.Enthusiast }
];