From bd0cce7aab3aa55bbd58419388a36b0e3f7d0731 Mon Sep 17 00:00:00 2001 From: dzq Date: Wed, 4 Jun 2025 09:19:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=94=A8=E6=88=B7=E7=BB=91=E5=AE=9A):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=8E=E6=B1=87=E9=82=A6=E4=BA=91=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ab98接口模块新增BindQyUserCommand类型和bindQyUserApi方法 - 扩展QyLoginDTO接口添加qyUserId和ab98User字段 - 新增ab98UserDTO类型定义用户详细信息 - 在wxStore中添加qyUserId和ab98User状态及相关操作方法 - 在ProductList页面添加绑定弹窗逻辑,当检测到未绑定用户时自动弹出绑定表单 --- src/common/apis/ab98/index.ts | 10 +++++ src/common/apis/ab98/type.ts | 6 +++ src/common/apis/shop/type.ts | 37 ++++++++++++++-- src/pages/product/ProductList.vue | 74 ++++++++++++++++++++++++++++--- src/pinia/stores/wx.ts | 28 ++++++++++-- 5 files changed, 142 insertions(+), 13 deletions(-) diff --git a/src/common/apis/ab98/index.ts b/src/common/apis/ab98/index.ts index ecfbb60..e7a91d6 100644 --- a/src/common/apis/ab98/index.ts +++ b/src/common/apis/ab98/index.ts @@ -1,5 +1,6 @@ import { request } from '@/http/axios' import { + BindQyUserCommand, GetTokenParams, LoginData, LogoutResponse, @@ -8,6 +9,7 @@ import { VerifySmsParams, WechatQrCodeParams } from './type' +import { ab98UserDTO } from '../shop/type' /** 获取临时令牌 */ export function getTokenApi(appName: string) { @@ -61,4 +63,12 @@ export function tokenLogin(token: string, userid: string, openid: string) { method: 'get', params: { token, userid, openid } }) +} + +export function bindQyUserApi(data: BindQyUserCommand) { + return request>({ + url: '/wx/login/bindQyUser', + method: 'post', + data + }) } \ No newline at end of file diff --git a/src/common/apis/ab98/type.ts b/src/common/apis/ab98/type.ts index 2f1e78a..c27e65b 100644 --- a/src/common/apis/ab98/type.ts +++ b/src/common/apis/ab98/type.ts @@ -58,4 +58,10 @@ export type VerifySmsParams = { vcode: string userid: string openid: string +} + +export interface BindQyUserCommand { + qyUserId: number; + name: string; + idNum: string; } \ No newline at end of file diff --git a/src/common/apis/shop/type.ts b/src/common/apis/shop/type.ts index c0cd808..4343aac 100644 --- a/src/common/apis/shop/type.ts +++ b/src/common/apis/shop/type.ts @@ -110,10 +110,39 @@ export interface GetBalanceResponse { } export interface QyLoginDTO { - userid: string - openid: string - isCabinetAdmin: number - name: string + userid: string; + openid: string; + isCabinetAdmin: number; + qyUserId: number; + name: string; + ab98User: ab98UserDTO; +} + +export interface ab98UserDTO { + /** 主键ID */ + ab98UserId?: number; + /** openid */ + openid?: string; + /** 汇邦云用户唯一ID */ + userid?: string; + /** 真实姓名 */ + name?: string; + /** 手机号码 */ + tel?: string; + /** 身份证号码 */ + idnum?: string; + /** 性别(男 女) */ + sex?: string; + /** 人脸照片地址 */ + faceImg?: string; + /** 身份证正面地址 */ + idcardFront?: string; + /** 身份证背面地址 */ + idcardBack?: string; + /** 身份证登记地址 */ + address?: string; + /** 是否已注册(0未注册 1已注册) */ + registered?: boolean; } export interface OpenCabinetApiData { diff --git a/src/pages/product/ProductList.vue b/src/pages/product/ProductList.vue index fd45cb5..76255ab 100644 --- a/src/pages/product/ProductList.vue +++ b/src/pages/product/ProductList.vue @@ -9,15 +9,19 @@ import { computed, onBeforeUnmount, onMounted, ref } from "vue" import Cart from "./components/cart.vue" import Detail from "./components/detail.vue" import { useRoute } from 'vue-router' +import { useWxStore } from "@/pinia/stores/wx" +import { bindQyUserApi } from "@/common/apis/ab98" const router = useRouter() const route = useRoute() // 状态管理 -const productStore = useProductStore() -const cartStore = useCartStore() -const { cartItems, totalPrice, totalQuantity } = storeToRefs(cartStore) // 新增购物车状态 +const productStore = useProductStore(); +const cartStore = useCartStore(); +const wxStore = useWxStore(); +const { cartItems, totalPrice, totalQuantity } = storeToRefs(cartStore); // 新增购物车状态 // 从 store 解构分类标签和商品数据 -const { labels, categories } = storeToRefs(productStore) +const { labels, categories } = storeToRefs(productStore); +const { openid, corpidLogin, ab98User, qyUserId } = storeToRefs(wxStore); // 当前选中的分类索引 const activeCategory = ref(0) @@ -40,7 +44,11 @@ const currentProduct = computed(() => // 购物车弹窗控制 const showCartPopup = ref(false) -const searchQuery = ref('') +const searchQuery = ref(''); + +const name = ref(''); +const idNum = ref(''); +const showAb98BindPopup = ref(false); // 点击分类导航 function handleCategoryClick(index: number) { @@ -131,7 +139,38 @@ watch(() => route.path, (newPath) => { if (newPath === '/') { productStore.getGoods() } -}) +}); + +let showAb98BindPopupOnce = false; +watch(openid, async () => { + if (openid.value && corpidLogin.value && !ab98User.value + && !showAb98BindPopup.value && !showAb98BindPopupOnce) { + // 显示绑定弹窗 + showAb98BindPopup.value = true; + showAb98BindPopupOnce = true; + } +}, { immediate: true }); + +async function handleAb98Bind() { + try { + const ab98UserData = await bindQyUserApi({ + qyUserId: qyUserId.value, + name: name.value, + idNum: idNum.value + }); + + if (ab98UserData?.code === 0) { + wxStore.setAb98User(ab98UserData.data); + showAb98BindPopup.value = false; + name.value = ''; + idNum.value = ''; + } else { + console.error('绑定失败:', ab98UserData?.msg); + } + } catch (error) { + console.error('绑定失败:', error); + } +}