feat(用户): 添加动态码生成功能
- 新增 DynamicCodeResponse 类型定义 - 添加 generateDynamicCode API 方法 - 在首页登录流程中调用动态码生成接口
This commit is contained in:
parent
8e031231c1
commit
a0df240aaf
|
|
@ -1,5 +1,5 @@
|
|||
import { http } from "@/http/http";
|
||||
import type { CurrentUserResponseData, WxUserDTO } from './types';
|
||||
import type { CurrentUserResponseData, WxUserDTO, DynamicCodeResponse } from './types';
|
||||
|
||||
/** 获取当前登录用户详情 */
|
||||
export async function getCurrentUserApi() {
|
||||
|
|
@ -9,3 +9,8 @@ export async function getCurrentUserApi() {
|
|||
export async function mpCodeToOpenId(code: string) {
|
||||
return await http.get<WxUserDTO>("wx/mpCodeToOpenId", { code });
|
||||
}
|
||||
|
||||
/** 根据openid获取动态码 */
|
||||
export async function generateDynamicCode(openid: string) {
|
||||
return await http.get<DynamicCodeResponse>("wx/generateDynamicCode", { openid });
|
||||
}
|
||||
|
|
@ -27,3 +27,11 @@ export interface WxUserDTO {
|
|||
/** 备注 */
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/** 动态码响应数据 */
|
||||
export interface DynamicCodeResponse {
|
||||
/** 动态码 */
|
||||
dynamicCode: string;
|
||||
/** 有效时间(分钟) */
|
||||
validityMinutes: string;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import { useCartStore } from '@/pinia/stores/cart'
|
|||
import { getShopListApi } from '@/api/shop'
|
||||
import type { ShopEntity } from '@/api/shop/types'
|
||||
import ProductContainer from './components/product-container.vue';
|
||||
import { mpCodeToOpenId } from '@/api/users'
|
||||
import { generateDynamicCode, mpCodeToOpenId } from '@/api/users'
|
||||
import { toHttpsUrl } from '@/utils'
|
||||
|
||||
definePage({
|
||||
|
|
@ -32,7 +32,13 @@ onMounted(async () => {
|
|||
provider: 'weixin', //使用微信登录
|
||||
success: function (loginRes) {
|
||||
mpCodeToOpenId(loginRes.code).then((wxUser) => {
|
||||
console.log('wxUser:', wxUser)
|
||||
console.log('wxUser:', wxUser);
|
||||
wxStore.setOpenid(wxUser.data.openid);
|
||||
generateDynamicCode(wxUser.data.openid).then((dynamicCode) => {
|
||||
console.log('dynamicCode:', dynamicCode);
|
||||
}).catch((e) => {
|
||||
console.error('generateDynamicCode error:', e)
|
||||
})
|
||||
}).catch((e) => {
|
||||
console.error('mpCodeToOpenId error:', e)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue