index.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { Avatar, Button, Card, Col, message, Row } from 'antd';
  2. import { useEffect, useState } from 'react';
  3. import Service from '@/pages/account/Center/service';
  4. import styles from './index.less';
  5. export const service = new Service();
  6. const Bind = () => {
  7. const [bindUser, setBindUser] = useState<any>();
  8. const [user, setUser] = useState<any>();
  9. const [code, setCode] = useState<string>('');
  10. const iconMap = new Map();
  11. iconMap.set('dingtalk', require('/public/images/notice/dingtalk.png'));
  12. iconMap.set('wechat-webapp', require('/public/images/notice/wechat.png'));
  13. const bGroundMap = new Map();
  14. bGroundMap.set('dingtalk', require('/public/images/notice/dingtalk-background.png'));
  15. bGroundMap.set('wechat-webapp', require('/public/images/notice/wechat-background.png'));
  16. const bindUserInfo = (params: string) => {
  17. service.bindUserInfo(params).then((res) => {
  18. if (res.status === 200) {
  19. setBindUser(res.result);
  20. }
  21. });
  22. };
  23. const getDetail = () => {
  24. service.getUserDetail().subscribe((res) => {
  25. setUser(res.result);
  26. });
  27. };
  28. useEffect(() => {
  29. const params = window.location.href.split('?')[1].split('&')[1].split('=')[1];
  30. // const params = 'b584032923c78d69e6148cf0e9312723'
  31. setCode(params);
  32. bindUserInfo(params);
  33. getDetail();
  34. }, []);
  35. return (
  36. <>
  37. <Card>
  38. <div style={{ margin: '0 auto', width: 800 }}>
  39. <Row>
  40. <Col span={12} className={styles.col}>
  41. <Card title="个人信息">
  42. <div className={styles.item}>
  43. <div style={{ height: 100 }}>
  44. <Avatar size={90} src={user?.avatar} />
  45. </div>
  46. <p>登录账号:{user?.username}</p>
  47. <p>姓名:{user?.name}</p>
  48. </div>
  49. </Card>
  50. </Col>
  51. <Col span={12} className={styles.col}>
  52. <Card title="三方账号信息">
  53. <div className={styles.item}>
  54. <div style={{ height: 100 }}>
  55. <img style={{ height: 80 }} src={iconMap.get(bindUser?.type)} />
  56. </div>
  57. <p>组织:{bindUser?.providerName}</p>
  58. <p>名字:{bindUser?.result.others.name}</p>
  59. </div>
  60. </Card>
  61. </Col>
  62. </Row>
  63. <Row>
  64. <Col span={24} style={{ textAlign: 'center', marginTop: 20 }}>
  65. <Button
  66. type="primary"
  67. onClick={() => {
  68. // window.close()
  69. service.bind(code).then((res) => {
  70. if (res.status === 200) {
  71. message.success('绑定成功');
  72. localStorage.setItem('onBind', 'true');
  73. setTimeout(() => window.close(), 300);
  74. } else {
  75. message.error('绑定失败');
  76. }
  77. });
  78. }}
  79. >
  80. 立即绑定
  81. </Button>
  82. </Col>
  83. </Row>
  84. </div>
  85. </Card>
  86. </>
  87. );
  88. };
  89. export default Bind;