|
|
|
@ -1,21 +1,40 @@
|
|
|
|
|
import { Flex, Result, Spin } from 'antd'
|
|
|
|
|
import { useState } from 'react'
|
|
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
|
import { isNotEmpty } from '@/utils/commons'
|
|
|
|
|
import * as dd from 'dingtalk-jsapi'
|
|
|
|
|
|
|
|
|
|
// 获取微应用免登授权码
|
|
|
|
|
// https://open.dingtalk.com/document/orgapp/jsapi-request-auth-code
|
|
|
|
|
function Login() {
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
const urlSearch = new URLSearchParams(location.search)
|
|
|
|
|
const originUrl = urlSearch.get('origin_url')
|
|
|
|
|
const redirectUrl = isNotEmpty(originUrl)
|
|
|
|
|
? 'https://login.dingtalk.com/oauth2/auth?redirect_uri=https%3A%2F%2Fsales.mycht.cn%2Fp%2Fdingding%2Fcallback%3Forigin_url%3D' +
|
|
|
|
|
originUrl +
|
|
|
|
|
'&response_type=code&client_id=dingwgdx6emlxr3fcrg8&scope=openid&state=global-saels&prompt=consent'
|
|
|
|
|
: 'https://login.dingtalk.com/oauth2/auth?redirect_uri=https%3A%2F%2Fsales.mycht.cn%2Fp%2Fdingding%2Fcallback%3Forigin_url%3D&response_type=code&client_id=dingwgdx6emlxr3fcrg8&scope=openid&state=global-saels&prompt=consent'
|
|
|
|
|
|
|
|
|
|
const [errorMsg, setErrorMsg] = useState('')
|
|
|
|
|
|
|
|
|
|
if (dd.env.platform === 'notInDingTalk') {
|
|
|
|
|
if (isNotEmpty(originUrl)) {
|
|
|
|
|
window.location = 'https://login.dingtalk.com/oauth2/auth?redirect_uri=https%3A%2F%2Fsales.mycht.cn%2Fp%2Fdingding%2Fcallback%3Forigin_url%3D' + originUrl + '&response_type=code&client_id=dingwgdx6emlxr3fcrg8&scope=openid&state=global-saels&prompt=consent'
|
|
|
|
|
} else {
|
|
|
|
|
window.location = 'https://login.dingtalk.com/oauth2/auth?redirect_uri=https%3A%2F%2Fsales.mycht.cn%2Fp%2Fdingding%2Fcallback%3Forigin_url%3D&response_type=code&client_id=dingwgdx6emlxr3fcrg8&scope=openid&state=global-saels&prompt=consent'
|
|
|
|
|
}
|
|
|
|
|
window.location =redirectUrl
|
|
|
|
|
} else {
|
|
|
|
|
dd.ready(function() {
|
|
|
|
|
console.info('dd.ready()')
|
|
|
|
|
dd.requestAuthCode({
|
|
|
|
|
clientId: 'dingwgdx6emlxr3fcrg8', // sales.mycht.cn
|
|
|
|
|
// clientId: 'dingl3jyntkazyg4coxf', // hub.mycht.cn
|
|
|
|
|
corpId: 'ding48bce8fd3957c96b',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
const { code } = res
|
|
|
|
|
navigate('/p/dingding/callback?state=global-saels&authCode=' + code, {
|
|
|
|
|
replace: true,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
fail: (error) => {
|
|
|
|
|
setErrorMsg(JSON.stringify(error))
|
|
|
|
|
},
|
|
|
|
|
complete: () => {},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -24,10 +43,8 @@ function Login() {
|
|
|
|
|
<Result
|
|
|
|
|
status='success'
|
|
|
|
|
title='欢迎使用'
|
|
|
|
|
subTitle='正在跳转到钉钉登录页面'
|
|
|
|
|
extra={[
|
|
|
|
|
<Spin key='dingding-login' size='small' />
|
|
|
|
|
]}
|
|
|
|
|
subTitle={'正在获取钉钉登授权' + errorMsg}
|
|
|
|
|
extra={[<Spin key='dingding-login' size='small' />]}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
)
|
|
|
|
|