Browse Source

修改登陆接口

master
DU 4 months ago
parent
commit
f46c01a984
  1. 4
      src/api/login.ts
  2. 9
      src/pages/user/index.tsx
  3. 7
      src/types/login.ts

4
src/api/login.ts

@ -8,8 +8,8 @@ import { WechatLoginRequest, WechatAuthResponse } from '../types/login' @@ -8,8 +8,8 @@ import { WechatLoginRequest, WechatAuthResponse } from '../types/login'
*
* @param code
*/
export const wechatLogin = (code: string, grpSn=''): Promise<WechatAuthResponse> => {
const data: WechatLoginRequest = { code,grpSn }
export const wechatLogin = (code: string): Promise<WechatAuthResponse> => {
const data: WechatLoginRequest = { code }
return request({
url: '/WechatAuth/login-wechat',

9
src/pages/user/index.tsx

@ -73,7 +73,6 @@ const UserIndex = observer(() => { @@ -73,7 +73,6 @@ const UserIndex = observer(() => {
// 微信登录
const handleWechatLogin = async () => {
let grpSn = '212'
try {
userStore.setLoading(true)
@ -83,10 +82,12 @@ const UserIndex = observer(() => { @@ -83,10 +82,12 @@ const UserIndex = observer(() => {
throw new Error('获取微信登录凭证失败')
}
console.log('loginResult', loginResult.code)
// return
// 调用后端接口
const response = await wechatLogin(loginResult.code,grpSn)
const response = await wechatLogin(loginResult.code)
if (response.success && response.data.success) {
if (response.success && response.data) {
// 保存用户信息到store
userStore.setUserInfoFromWechat(response.data.customer)
@ -95,7 +96,7 @@ const UserIndex = observer(() => { @@ -95,7 +96,7 @@ const UserIndex = observer(() => {
icon: 'success'
})
} else {
throw new Error(response.data.message || response.message || '登录失败')
throw new Error(response.data?.message || response.message || '登录失败')
}
} catch (error: any) {
console.error('微信登录失败:', error)

7
src/types/login.ts

@ -2,10 +2,9 @@ @@ -2,10 +2,9 @@
*
*/
// 微信登录请求参数
// 微信登录请求参数 - 根据接口文档更新
export interface WechatLoginRequest {
code: string
grpSn?: string
code: string // 微信登录凭证code,通过 wx.login() 获取的临时登录凭证
}
// 客户信息
@ -31,9 +30,7 @@ export interface CustomerDto { @@ -31,9 +30,7 @@ export interface CustomerDto {
// 微信登录结果数据
export interface WechatAuthResultDto {
success: boolean
customer: CustomerDto
operationResult: any
isNewCustomer: boolean
message: string
}

Loading…
Cancel
Save