From d06eee3c1c4bc666a083ddaa63cc1bd451c0f259 Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Tue, 24 Dec 2024 14:51:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20WA=20=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F=EF=BC=9B?= =?UTF-8?q?WA=20=E5=8F=AF=E4=BB=A5=E4=BF=9D=E5=AD=98=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20WA=20=E6=B6=88=E6=81=AF=E6=A0=BC=E5=BC=8F=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/AuthStore.js | 5 +++-- src/views/accounts/Profile.jsx | 35 +++++++++++++------------------- wai-server/core/baileys/index.js | 6 +++--- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/stores/AuthStore.js b/src/stores/AuthStore.js index 62394e7..094b887 100644 --- a/src/stores/AuthStore.js +++ b/src/stores/AuthStore.js @@ -176,11 +176,11 @@ const useAuthStore = create(devtools((set, get) => ({ ) }, - setWhatsAppBusiness: async (userId, whatsAppBusiness) => { + setWhatsAppProfile: async (userId, whatsAppBusiness, whatsAppNo) => { const { loginUser, saveUserSession } = get() const postWABAUrl = `${API_HOST}/v2/set_whatsapp_info` - const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness}; + const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness, whatsapp_wa: whatsAppNo}; return fetchJSON(postWABAUrl, params) .then(json => { @@ -188,6 +188,7 @@ const useAuthStore = create(devtools((set, get) => ({ set(() => ({ loginUser: { ...loginUser, + whatsAppNo: whatsAppNo, whatsAppBusiness: whatsAppBusiness, } })) diff --git a/src/views/accounts/Profile.jsx b/src/views/accounts/Profile.jsx index e33d750..bb59c0a 100644 --- a/src/views/accounts/Profile.jsx +++ b/src/views/accounts/Profile.jsx @@ -10,11 +10,12 @@ function Profile() { const { notification } = App.useApp() const [wabaForm] = Form.useForm() - const [loginUser, setWhatsAppBusiness, isPermitted] = useAuthStore((state) => [ - state.loginUser, state.setWhatsAppBusiness, state.isPermitted + const [loginUser, setWhatsAppProfile, isPermitted] = useAuthStore((state) => [ + state.loginUser, state.setWhatsAppProfile, state.isPermitted ]) - const [qrCode, setQRCode] = useState('') + const [qrCode, setQRCode] = useState('expired') + const [qrStatus, setQRStatus] = useState('expired') useEffect(() => { // 测试错误捕获: @@ -23,11 +24,12 @@ function Profile() { }, []) const handelUpdateWABA = useCallback(() => { - setWhatsAppBusiness(loginUser.userId, wabaForm.getFieldsValue().whatsAppBusiness) + const formValues = wabaForm.getFieldsValue() + setWhatsAppProfile(loginUser.userId, formValues.whatsAppBusiness, formValues.whatsAppNo) .then(() => { notification.info({ message: 'Notification', - description: '商业号身份设置成功', + description: 'WhatsApp 配置成功', placement: 'top', }) }) @@ -48,8 +50,8 @@ function Profile() { 'http://localhost:3031/api/v1/whatsapp/channels/qrcode', { phone }) .then(r => { - console.info(r) setQRCode(r.result.qr) + setQRStatus('active') }) .catch(ex => { console.error(ex) @@ -57,6 +59,7 @@ function Profile() { }, []) const customStatusRender = (info) => { + console.info(info) switch (info.status) { case 'expired': return ( @@ -65,22 +68,14 @@ function Profile() { style={{ color: '#52c41a', }} - />{' '} - 8618754124786 已登录 + />已过期

-

) - case 'loading': - return ( - - -

Loading...

-
- ) case 'scanned': return (
@@ -88,7 +83,7 @@ function Profile() { style={{ color: 'green', }} - />{' '} + />{' ' + loginUser.whatsAppNo}已登录 {info.locale?.scanned}
) @@ -200,7 +195,7 @@ function Profile() { 在系统上使用 WhatsApp