feat(微信登录): 扩展微信登录返回用户信息

修改mpCodeToOpenId接口返回类型为WxUserDTO,包含完整的微信用户信息
更新相关页面调用逻辑,将openId改为wxUser
新增WxUserDTO类型定义,包含微信用户相关字段
This commit is contained in:
dzq 2025-11-06 11:05:21 +08:00
parent 35871b9b48
commit 8e031231c1
4 changed files with 32 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import { http } from "@/http/http"; import { http } from "@/http/http";
import type { CurrentUserResponseData } from './types'; import type { CurrentUserResponseData, WxUserDTO } from './types';
/** 获取当前登录用户详情 */ /** 获取当前登录用户详情 */
export async function getCurrentUserApi() { export async function getCurrentUserApi() {
@ -7,5 +7,5 @@ export async function getCurrentUserApi() {
} }
export async function mpCodeToOpenId(code: string) { export async function mpCodeToOpenId(code: string) {
return await http.get<string>("wx/mpCodeToOpenId", { code }); return await http.get<WxUserDTO>("wx/mpCodeToOpenId", { code });
} }

View File

@ -1,3 +1,29 @@
export type CurrentUserResponseData = { export type CurrentUserResponseData = {
data: { username: string, roles: string[] } data: { username: string, roles: string[] }
} }
/** 微信用户DTO */
export interface WxUserDTO {
/** 主键ID */
wxUserId?: number;
/** openid */
openid?: string;
/** 汇邦云用户ID */
ab98UserId?: number;
/** 企业用户ID */
qyUserId?: number;
/** 昵称 */
nickName?: string;
/** 手机号码 */
tel?: string;
/** 余额(分) */
wxBalance?: number;
/** 余额(元) */
wxBalanceYuan?: number;
/** 创建时间 */
createTime?: string;
/** 更新时间 */
updateTime?: string;
/** 备注 */
remark?: string;
}

View File

@ -31,8 +31,8 @@ onMounted(async () => {
uni.login({ uni.login({
provider: 'weixin', //使 provider: 'weixin', //使
success: function (loginRes) { success: function (loginRes) {
mpCodeToOpenId(loginRes.code).then((openId) => { mpCodeToOpenId(loginRes.code).then((wxUser) => {
console.log('openId:', openId) console.log('wxUser:', wxUser)
}).catch((e) => { }).catch((e) => {
console.error('mpCodeToOpenId error:', e) console.error('mpCodeToOpenId error:', e)
}) })

View File

@ -73,8 +73,8 @@ const login = () => {
uni.login({ uni.login({
provider: 'weixin', //使 provider: 'weixin', //使
success: function (loginRes) { success: function (loginRes) {
mpCodeToOpenId(loginRes.code).then((openId) => { mpCodeToOpenId(loginRes.code).then((wxUser) => {
console.log('openId:', openId) console.log('openId:', wxUser)
loading.value = false loading.value = false
}).catch((e) => { }).catch((e) => {
loading.value = false loading.value = false