|
|
@ -2,14 +2,19 @@ import { useEffect, useCallback, useState } from 'react'
|
|
|
|
import { Row, Col, Space, Input, Descriptions, Avatar, Tag, Divider, List, App, Button, Flex, Select, Spin, Form, Typography, QRCode, Tooltip } from 'antd'
|
|
|
|
import { Row, Col, Space, Input, Descriptions, Avatar, Tag, Divider, List, App, Button, Flex, Select, Spin, Form, Typography, QRCode, Tooltip } from 'antd'
|
|
|
|
import { UserOutlined, InfoCircleOutlined, ReloadOutlined, CheckCircleFilled } from '@ant-design/icons'
|
|
|
|
import { UserOutlined, InfoCircleOutlined, ReloadOutlined, CheckCircleFilled } from '@ant-design/icons'
|
|
|
|
import useAuthStore from '@/stores/AuthStore'
|
|
|
|
import useAuthStore from '@/stores/AuthStore'
|
|
|
|
|
|
|
|
import { fetchJSON } from '@/utils/request'
|
|
|
|
|
|
|
|
import { Conditional } from '@/components/Conditional'
|
|
|
|
|
|
|
|
import { PERM_USE_WHATSAPP } from '@/stores/AuthStore'
|
|
|
|
|
|
|
|
|
|
|
|
function Profile() {
|
|
|
|
function Profile() {
|
|
|
|
const { notification } = App.useApp()
|
|
|
|
const { notification } = App.useApp()
|
|
|
|
const [wabaForm] = Form.useForm()
|
|
|
|
const [wabaForm] = Form.useForm()
|
|
|
|
|
|
|
|
|
|
|
|
const [loginUser, setWhatsAppBusiness] = useAuthStore((state) => [state.loginUser, state.setWhatsAppBusiness])
|
|
|
|
const [loginUser, setWhatsAppBusiness, isPermitted] = useAuthStore((state) => [
|
|
|
|
|
|
|
|
state.loginUser, state.setWhatsAppBusiness, state.isPermitted
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
const [text, setText] = useState('')
|
|
|
|
const [qrCode, setQRCode] = useState('')
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
// 测试错误捕获:
|
|
|
|
// 测试错误捕获:
|
|
|
@ -36,6 +41,21 @@ function Profile() {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}, [])
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handelGernaterQR = useCallback(() => {
|
|
|
|
|
|
|
|
const phone = loginUser.whatsAppNo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fetchJSON(
|
|
|
|
|
|
|
|
'http://localhost:3031/api/v1/whatsapp/channels/qrcode',
|
|
|
|
|
|
|
|
{ phone })
|
|
|
|
|
|
|
|
.then(r => {
|
|
|
|
|
|
|
|
console.info(r)
|
|
|
|
|
|
|
|
setQRCode(r.result.qr)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(ex => {
|
|
|
|
|
|
|
|
console.error(ex)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
const customStatusRender = (info) => {
|
|
|
|
const customStatusRender = (info) => {
|
|
|
|
switch (info.status) {
|
|
|
|
switch (info.status) {
|
|
|
|
case 'expired':
|
|
|
|
case 'expired':
|
|
|
@ -107,7 +127,7 @@ function Profile() {
|
|
|
|
<span>商业号身份</span>
|
|
|
|
<span>商业号身份</span>
|
|
|
|
</Space>
|
|
|
|
</Space>
|
|
|
|
}>
|
|
|
|
}>
|
|
|
|
<Form layout='vertical' className='w-3/5' form={wabaForm} initialValues={{ whatsAppBusiness: loginUser.whatsAppBusiness }}>
|
|
|
|
<Form layout='vertical' className='w-3/5' form={wabaForm} initialValues={{ whatsAppBusiness: loginUser.whatsAppBusiness, whatsAppNo: loginUser.whatsAppNo }}>
|
|
|
|
<Form.Item name='whatsAppBusiness'>
|
|
|
|
<Form.Item name='whatsAppBusiness'>
|
|
|
|
<Select
|
|
|
|
<Select
|
|
|
|
options={[
|
|
|
|
options={[
|
|
|
@ -142,6 +162,11 @@ function Profile() {
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
|
|
|
label='WhatsApp'
|
|
|
|
|
|
|
|
name='whatsAppNo'>
|
|
|
|
|
|
|
|
<Input />
|
|
|
|
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item>
|
|
|
|
<Form.Item>
|
|
|
|
<Button type='primary' onClick={handelUpdateWABA}>
|
|
|
|
<Button type='primary' onClick={handelUpdateWABA}>
|
|
|
|
保存
|
|
|
|
保存
|
|
|
@ -175,6 +200,7 @@ function Profile() {
|
|
|
|
<Typography.Title level={2}>在系统上使用 WhatsApp</Typography.Title>
|
|
|
|
<Typography.Title level={2}>在系统上使用 WhatsApp</Typography.Title>
|
|
|
|
<Typography.Paragraph>
|
|
|
|
<Typography.Paragraph>
|
|
|
|
<ul>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
<li>点击生成二维码➡️</li>
|
|
|
|
<li>在手机上打开 WhatsApp</li>
|
|
|
|
<li>在手机上打开 WhatsApp</li>
|
|
|
|
<li>点击“已关联的设备”,再点击“关联新设备”</li>
|
|
|
|
<li>点击“已关联的设备”,再点击“关联新设备”</li>
|
|
|
|
<li>将手机对准屏幕扫描二维码➡️</li>
|
|
|
|
<li>将手机对准屏幕扫描二维码➡️</li>
|
|
|
@ -184,12 +210,12 @@ function Profile() {
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
<Col span={6}>
|
|
|
|
<Col span={6}>
|
|
|
|
<Flex gap='middle' vertical justify={'center'} align={'center'}>
|
|
|
|
<Flex gap='middle' vertical justify={'center'} align={'center'}>
|
|
|
|
<Input
|
|
|
|
<QRCode size={264} value={qrCode} errorLevel='L' />
|
|
|
|
placeholder=""
|
|
|
|
<Conditional
|
|
|
|
value={text}
|
|
|
|
condition={isPermitted(PERM_USE_WHATSAPP)}
|
|
|
|
onChange={(e) => setText(e.target.value)}
|
|
|
|
whenTrue={<Button type='primary' onClick={handelGernaterQR}>生成</Button>}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<QRCode size={264} value={text} errorLevel='L' />
|
|
|
|
|
|
|
|
</Flex>
|
|
|
|
</Flex>
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Row>
|
|
|
|