|
|
@ -1,6 +1,6 @@
|
|
|
|
import useAuthStore from '@/stores/AuthStore'
|
|
|
|
import useAuthStore from '@/stores/AuthStore'
|
|
|
|
import { Flex, Result, Spin, Typography } from 'antd'
|
|
|
|
import { Flex, Input, Button, Typography } from 'antd'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import { useEffect, useState, useRef } from 'react'
|
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
|
|
|
|
|
|
|
|
const { Title } = Typography
|
|
|
|
const { Title } = Typography
|
|
|
@ -8,7 +8,6 @@ const { Title } = Typography
|
|
|
|
// 钉钉扫码开发文档:https://open.dingtalk.com/document/orgapp/tutorial-obtaining-user-personal-information#title-qpi-0qv-anm
|
|
|
|
// 钉钉扫码开发文档:https://open.dingtalk.com/document/orgapp/tutorial-obtaining-user-personal-information#title-qpi-0qv-anm
|
|
|
|
|
|
|
|
|
|
|
|
function QRCode() {
|
|
|
|
function QRCode() {
|
|
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
|
|
|
|
const [result, setResult] = useState('')
|
|
|
|
const [result, setResult] = useState('')
|
|
|
@ -16,16 +15,19 @@ function QRCode() {
|
|
|
|
// const loginStatus = useAuthStore((state) => state.loginStatus)
|
|
|
|
// const loginStatus = useAuthStore((state) => state.loginStatus)
|
|
|
|
// const setLoginStatus = useAuthStore((state) => state.setLoginStatus)
|
|
|
|
// const setLoginStatus = useAuthStore((state) => state.setLoginStatus)
|
|
|
|
// const loginUser = useAuthStore((state) => state.loginUser)
|
|
|
|
// const loginUser = useAuthStore((state) => state.loginUser)
|
|
|
|
// const login = useAuthStore((state) => state.login)
|
|
|
|
const login = useAuthStore((state) => state.login)
|
|
|
|
|
|
|
|
const codeRef = useRef()
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
// if (loginUser.userId > 0) {
|
|
|
|
// if (loginUser.userId > 0) {
|
|
|
|
// navigate('/')
|
|
|
|
// navigate('/')
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}, [])
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
import('https://g.alicdn.com/dingding/h5-dingtalk-login/0.21.0/ddlogin.js').then(() => {
|
|
|
|
import(
|
|
|
|
|
|
|
|
'https://g.alicdn.com/dingding/h5-dingtalk-login/0.21.0/ddlogin.js'
|
|
|
|
|
|
|
|
).then(() => {
|
|
|
|
window.DTFrameLogin(
|
|
|
|
window.DTFrameLogin(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
id: 'qrCodeContainer',
|
|
|
|
id: 'qrCodeContainer',
|
|
|
@ -33,7 +35,9 @@ function QRCode() {
|
|
|
|
height: 300,
|
|
|
|
height: 300,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
redirect_uri: encodeURIComponent('https://sales.mycht.cn/p/dingding/callback'),
|
|
|
|
redirect_uri: encodeURIComponent(
|
|
|
|
|
|
|
|
'https://sales.mycht.cn/p/dingding/callback',
|
|
|
|
|
|
|
|
),
|
|
|
|
client_id: 'dingwgdx6emlxr3fcrg8',
|
|
|
|
client_id: 'dingwgdx6emlxr3fcrg8',
|
|
|
|
scope: 'openid',
|
|
|
|
scope: 'openid',
|
|
|
|
response_type: 'code',
|
|
|
|
response_type: 'code',
|
|
|
@ -42,7 +46,6 @@ function QRCode() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
(loginResult) => {
|
|
|
|
(loginResult) => {
|
|
|
|
const { authCode } = loginResult
|
|
|
|
const { authCode } = loginResult
|
|
|
|
// login(authCode)
|
|
|
|
|
|
|
|
setResult(authCode)
|
|
|
|
setResult(authCode)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
(errorMsg) => {
|
|
|
|
(errorMsg) => {
|
|
|
@ -56,10 +59,24 @@ function QRCode() {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Flex justify='center' align='center' gap='middle' vertical>
|
|
|
|
<Flex justify='center' align='center' gap='middle' vertical>
|
|
|
|
<Title level={4}>使用钉钉扫码</Title>
|
|
|
|
<Title level={4}>使用钉钉扫码</Title>
|
|
|
|
<div id='qrCodeContainer' style={{ border: '12px solid rgba(5, 5, 5, 0.06)', borderRadius: '8px' }}></div>
|
|
|
|
<div
|
|
|
|
|
|
|
|
id='qrCodeContainer'
|
|
|
|
|
|
|
|
style={{
|
|
|
|
|
|
|
|
border: '12px solid rgba(5, 5, 5, 0.06)',
|
|
|
|
|
|
|
|
borderRadius: '8px',
|
|
|
|
|
|
|
|
}}></div>
|
|
|
|
<span>钉钉 authCode: {result}</span>
|
|
|
|
<span>钉钉 authCode: {result}</span>
|
|
|
|
|
|
|
|
<Input placeholder='placeholder' ref={codeRef} />
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
|
|
danger
|
|
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
|
|
console.info(codeRef.current.nativeElement.value)
|
|
|
|
|
|
|
|
login(codeRef.current.nativeElement.value)
|
|
|
|
|
|
|
|
}}>
|
|
|
|
|
|
|
|
登录
|
|
|
|
|
|
|
|
</Button>
|
|
|
|
</Flex>
|
|
|
|
</Flex>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default QRCode
|
|
|
|
export default QRCode
|
|
|
|