setting.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { useEffect, useState } from 'react'
  2. import { useParams } from 'react-router-dom';
  3. import wxLogin from './wxLogin'
  4. import { Spin, Button } from 'antd';
  5. import { UserInfo } from './type';
  6. import http from '@src/http/index';
  7. import { getBindPQUserInfo, bindPQUser } from "@src/http/api";
  8. const CONFIG = {
  9. test: {
  10. appid: 'wx853a8d12eea0e682',
  11. url: 'https://piaoquantv.yishihui.com'
  12. },
  13. prod: {
  14. appid: 'wx73a6cb4d85be594f',
  15. url: 'https://www.piaoquantv.com'
  16. }
  17. }
  18. const Setting = () => {
  19. const { code } = useParams<{ code?: string }>();
  20. const [isLoading, setIsLoading] = useState(false);
  21. const [pqUserInfo, setPqUserInfo] = useState<UserInfo>();
  22. useEffect(() => {
  23. // 设置pq登录信息
  24. const pq_userInfo = localStorage.getItem('pq_userInfo');
  25. if (pq_userInfo) {
  26. setPqUserInfo(JSON.parse(pq_userInfo))
  27. } else {
  28. http.get(getBindPQUserInfo).then(res => {
  29. const { code, data } = res;
  30. if (code === 0 && data) {
  31. setPqUserInfo(data as UserInfo)
  32. localStorage.setItem('pq_userInfo', JSON.stringify(data as UserInfo))
  33. } else {
  34. renderQrcode()
  35. }
  36. })
  37. }
  38. }, [])
  39. useEffect(() => {
  40. // 获取用户信息
  41. if (code) {
  42. getPiaoQuanUserInfo(code)
  43. } else {
  44. renderQrcode()
  45. }
  46. }, [])
  47. const getPiaoQuanUserInfo = async (code: string) => {
  48. setIsLoading(true)
  49. http.post(bindPQUser, {
  50. code,
  51. appType: 8,
  52. appId: 'wx853a8d12eea0e682'
  53. }, {
  54. headers: {
  55. 'Content-Type': 'application/x-www-form-urlencoded',
  56. },
  57. }).then(res => {
  58. const { code, data } = res;
  59. if (code === 0 && data) {
  60. localStorage.setItem('pq_userInfo', JSON.stringify(data as UserInfo))
  61. setPqUserInfo(data as UserInfo)
  62. setIsLoading(false)
  63. }
  64. })
  65. }
  66. const renderQrcode = () => {
  67. const env = window.location.host === ('content.piaoquantv.com') ? 'prod' : 'test'
  68. wxLogin({
  69. id: 'code',
  70. appid: CONFIG[env].appid,
  71. scope: 'snsapi_login',
  72. redirect_uri: encodeURIComponent(CONFIG[env].url + '?jumpTo=contentCooper'),
  73. })
  74. }
  75. const postVideo = () => {
  76. window.location.href = '/publishContent/videos'
  77. }
  78. return (
  79. <div className='w-full h-full'>
  80. <div className='px-6 py-1 flex flex-row justify-between items-center border-b border-gray-300'>
  81. <div className='text-2xl font-bold'>视频上传归属用户</div>
  82. </div>
  83. {
  84. pqUserInfo || code ? ( isLoading ? <Spin spinning={isLoading} className='mt-10! ml-10!' tip='账号关联中...'></Spin> : (
  85. <div className="w-[450px] m-auto mt-[50px] text-center">
  86. <div className='text-xl text-black-800 font-bold'>已完成视频归属用户的绑定!</div>
  87. <div className='text-black-600 mt-8'>
  88. 视频归属用户的微信昵称:{pqUserInfo?.nickName}
  89. </div>
  90. <div className='text-black-600 mt-4'>
  91. 视频归属用户的票圈UID:{pqUserInfo?.uid}
  92. </div>
  93. <div className='text-black-600 mt-10'>
  94. <Button type="primary" onClick={postVideo}>去发视频</Button>
  95. </div>
  96. </div>
  97. )
  98. ) : (
  99. <div className='px-4 py-2 max-h-[calc(100vh-200px)] h-[calc(100vh-200px)] overflow-y-auto'>
  100. <div id='code' className='m-[50px]'></div>
  101. <div className='text-gray-500 w-[450px] m-auto'>
  102. 1、手动上传的视频需要绑定一名微信用户作为视频的所有者,请使用所有者的微信账号扫描上方二维码完成绑定。
  103. </div>
  104. <div className='text-gray-500 w-[450px] m-auto mt-2'>
  105. 2、完成一次绑定后,后续无需重复绑定。若需要更换视频所有者对应的微信账号,可解绑后重新绑定(后续支持)。
  106. </div>
  107. </div>
  108. )
  109. }
  110. </div>
  111. )
  112. }
  113. export default Setting