|
|
|
@ -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 已登录
|
|
|
|
|
/>已过期
|
|
|
|
|
<p>
|
|
|
|
|
<Button type='link' onClick={info.onRefresh}>
|
|
|
|
|
<Button type='link' onClick={handelGernaterQR}>
|
|
|
|
|
<ReloadOutlined /> {info.locale?.refresh}
|
|
|
|
|
</Button>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
case 'loading':
|
|
|
|
|
return (
|
|
|
|
|
<Space direction='vertical'>
|
|
|
|
|
<Spin />
|
|
|
|
|
<p>Loading...</p>
|
|
|
|
|
</Space>
|
|
|
|
|
)
|
|
|
|
|
case 'scanned':
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
@ -88,7 +83,7 @@ function Profile() {
|
|
|
|
|
style={{
|
|
|
|
|
color: 'green',
|
|
|
|
|
}}
|
|
|
|
|
/>{' '}
|
|
|
|
|
/>{' ' + loginUser.whatsAppNo}已登录
|
|
|
|
|
{info.locale?.scanned}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
@ -200,7 +195,7 @@ function Profile() {
|
|
|
|
|
<Typography.Title level={2}>在系统上使用 WhatsApp</Typography.Title>
|
|
|
|
|
<Typography.Paragraph>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>点击生成二维码➡️</li>
|
|
|
|
|
<li>点击刷新二维码➡️</li>
|
|
|
|
|
<li>在手机上打开 WhatsApp</li>
|
|
|
|
|
<li>点击“已关联的设备”,再点击“关联新设备”</li>
|
|
|
|
|
<li>将手机对准屏幕扫描二维码➡️</li>
|
|
|
|
@ -210,12 +205,10 @@ function Profile() {
|
|
|
|
|
</Col>
|
|
|
|
|
<Col span={6}>
|
|
|
|
|
<Flex gap='middle' vertical justify={'center'} align={'center'}>
|
|
|
|
|
<QRCode size={264} value={qrCode} errorLevel='L' />
|
|
|
|
|
<Conditional
|
|
|
|
|
condition={isPermitted(PERM_USE_WHATSAPP)}
|
|
|
|
|
whenTrue={<Button type='primary' onClick={handelGernaterQR}>生成</Button>}
|
|
|
|
|
whenTrue={<QRCode size={264} value={qrCode} errorLevel='L' status={qrStatus} statusRender={customStatusRender} />}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
</Flex>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|