index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React, { useEffect, useState } from 'react';
  2. import * as dd from 'dingtalk-jsapi';
  3. import { message } from 'antd';
  4. import { LoadingOutlined, CheckOutlined } from '@ant-design/icons';
  5. import { bindDDCode } from '@/services/boom';
  6. function DDLogin(props) {
  7. const {
  8. match: {
  9. params: { dingUserId },
  10. },
  11. } = props;
  12. const [info, setInfo] = useState('');
  13. useEffect(() => {
  14. if (dd.env.platform != 'notInDingTalk') {
  15. dd.ready(function() {
  16. dd.runtime.permission.requestAuthCode({
  17. corpId: 'ding0cdce2d5dbf986d9', // 企业id
  18. onSuccess: async function(info) {
  19. setTimeout(() => {
  20. setInfo(info.code);
  21. }, 500);
  22. let res = await bindDDCode(dingUserId, info.code);
  23. console.log(res);
  24. // 通过该免登授权码可以获取用户身份
  25. },
  26. onFail: error => {
  27. setInfo(JSON.stringify(error));
  28. },
  29. });
  30. });
  31. }
  32. }, []);
  33. return (
  34. <div
  35. style={{
  36. width: '100vw',
  37. fontSize: 24,
  38. paddingTop: 50,
  39. display: 'flex',
  40. justifyContent: 'center',
  41. alignItems: 'center',
  42. flexDirection: 'column',
  43. }}
  44. >
  45. {info ? (
  46. <>
  47. <CheckOutlined style={{ fontSize: 40, color: '#52c41a' }} />
  48. <div>授权成功</div>
  49. {/* <div>{info}</div> */}
  50. </>
  51. ) : (
  52. <>
  53. <LoadingOutlined style={{ fontSize: 40, color: '#1890ff' }} />
  54. <div>授权中...</div>
  55. </>
  56. )}
  57. </div>
  58. );
  59. }
  60. export default DDLogin;