AdbHeader.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import React, { useState } from "react";
  2. import type { FormProps } from 'antd';
  3. import { Modal, Select, Button, Form, Input,Image } from "antd";
  4. import QRCode from "react-qr-code";
  5. import { updateConnectType, AppState } from "../../states/global";
  6. import { useDispatch, useSelector } from "react-redux";
  7. import disConnectImg from "../../asstes/icon/uploader_disconnect.png";
  8. import connectImg from "../../asstes/icon/uploader_connect.png";
  9. import WifiImg from "../../asstes/icon/wifi.png";
  10. import adb1 from "../../asstes/img/adb1.png";
  11. import adb2 from "../../asstes/img/adb2.png";
  12. import adb3 from "../../asstes/img/adb3.png";
  13. import adb4 from "../../asstes/img/adb4.jpg";
  14. import "../../asstes/css/updateLog.css"
  15. type FieldType = {
  16. name?: string;
  17. password?: string;
  18. remember?: string;
  19. };
  20. const adbHeaderStyle: React.CSSProperties = {
  21. backgroundColor: "#f1f2f5",
  22. padding: '10px 0',
  23. textAlign: "left"
  24. }
  25. const imgStyle: React.CSSProperties = {
  26. width: '20px',
  27. height: '20px',
  28. margin: '0 5px',
  29. cursor: 'pointer'
  30. }
  31. const wifiStyle: React.CSSProperties = {
  32. width: '20px',
  33. height: '20px',
  34. margin: '0 15px 0 5px',
  35. float: 'right',
  36. cursor: 'pointer'
  37. }
  38. const Pstyle: React.CSSProperties = {
  39. position: 'absolute',
  40. bottom: "-250px",
  41. left: "50%",
  42. transform: "translate(-50%, 0)"
  43. }
  44. const AdbHeader: React.FC = () => {
  45. const dispatch = useDispatch();
  46. const currentBackend = useSelector(
  47. (state: AppState) => state.currentBackend,
  48. );
  49. const [wifiModalVisible, setWifiModalVisible] = useState(false);
  50. const [codeValue, setCodeValue] = useState("");
  51. const [adbVisible, setAdbVisible] = useState(false);
  52. const switchConnectType = (e: any) => {
  53. console.log(e)
  54. dispatch(updateConnectType(e));
  55. }
  56. const getQRCode = (val: any) => {
  57. setCodeValue(val)
  58. }
  59. const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
  60. console.log('Success:', values);
  61. if (values.name && values.password) {
  62. getQRCode(values.name + values.password)
  63. }
  64. };
  65. const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (errorInfo) => {
  66. console.log('Failed:', errorInfo);
  67. setCodeValue("")
  68. };
  69. return (
  70. <div style={adbHeaderStyle} className="adb-header">
  71. <span>设备</span>
  72. <Select defaultValue="1" style={{ width: 100, margin: '0 5px' }} onChange={switchConnectType}>
  73. <Select.Option value="1">有线连接</Select.Option>
  74. <Select.Option value="2">无线连接</Select.Option>
  75. </Select>
  76. {!currentBackend && <img style={imgStyle} onClick={()=>setAdbVisible(true)} src={disConnectImg} alt="" />}
  77. {currentBackend && <img style={imgStyle} src={connectImg} alt="" />}
  78. <img onClick={() => setWifiModalVisible(true)} style={wifiStyle} src={WifiImg} alt="WiFi" />
  79. <Modal visible={wifiModalVisible} footer={null} width={800} title="扫描二维码,连接网络" onCancel={() => setWifiModalVisible(false)}>
  80. <Form
  81. name="basic"
  82. labelCol={{ span: 6 }}
  83. wrapperCol={{ span: 14 }}
  84. style={{ width: '100%' }}
  85. initialValues={{ remember: true }}
  86. onFinish={onFinish}
  87. onFinishFailed={onFinishFailed}
  88. autoComplete="off">
  89. <Form.Item<FieldType>
  90. label="WiFi 名"
  91. name="name"
  92. rules={[{ required: true, message: 'Please input your WiFi name!' }]}>
  93. <Input />
  94. </Form.Item>
  95. <Form.Item<FieldType>
  96. label="密码"
  97. name="password"
  98. rules={[{ required: true, message: 'Please input your password!' }]}>
  99. <Input />
  100. </Form.Item>
  101. <div style={{ textAlign: 'center', position: 'relative' }}>
  102. <Button type="primary" htmlType="submit">
  103. 生成二维码
  104. </Button>
  105. </div>
  106. </Form>
  107. <div style={{ textAlign: 'center', position: 'relative', marginTop: '40px' }}>
  108. {codeValue && <QRCodeGenerator url={codeValue} />}
  109. <p style={Pstyle}>打开CocoPi上的扫码联网样例,扫描屏幕二维码,连接上网</p>
  110. </div>
  111. </Modal>
  112. <Modal visible={adbVisible} footer={null} width={800} title="无法连接问题处理" onCancel={() => setAdbVisible(false)}>
  113. <div className="update-log-step">
  114. <h2>windows</h2>
  115. <p>一、 下载驱动精灵帮助文档</p>
  116. <div style={{ margin: "10px 0" }}>
  117. <a download href="./static/docx/如何通过驱动精灵更新Android手机驱动.docx">
  118. <Button type="primary">下载</Button>
  119. </a>
  120. <a href="//file.drivergenius.com/DGSetup_Home_KZ.exe" style={{ marginLeft: 15 }}>
  121. <Button type="primary">下载安装包</Button>
  122. </a>
  123. </div>
  124. <p>二、adb 驱动升级步骤</p>
  125. <a download href="//cocorobo.cn/downloads/usb_driver_r13-windows.zip">
  126. <Button type="primary">点击下载</Button>
  127. </a>
  128. <ul className="update-log-adb-step">
  129. <li>
  130. <p>将文件下载至电脑并解压</p>
  131. </li>
  132. <li>
  133. <p>计算机 -- 右击 -- 管理 -- 设备管理器</p>
  134. <Image src={adb1} alt="" />
  135. </li>
  136. <li>
  137. <p>双击带黄色感叹号的ADB Interface</p>
  138. <Image src={adb2} alt="" />
  139. </li>
  140. <li>
  141. <p>点击更新驱动程序</p>
  142. </li>
  143. <li>
  144. <p>点击 “浏览计算机以查找驱动程序软件”</p>
  145. <Image src={adb3} alt="" />
  146. </li>
  147. <li>
  148. <p>
  149. 点击“从计算机的设备驱动程序列表中选择”
  150. </p>
  151. <Image src={adb4} alt="" />
  152. </li>
  153. <li>
  154. <p>然后一直点击下一步,直至安装成功</p>
  155. </li>
  156. </ul>
  157. </div>
  158. </Modal>
  159. </div>
  160. )
  161. }
  162. interface QRCodeGeneratorProps {
  163. url: string;
  164. }
  165. const QRCodeGenerator: React.FC<QRCodeGeneratorProps> = ({ url }) => {
  166. return (
  167. <div style={{ position: 'absolute', left: '50%', transform: 'translate(-50%, 0)' }}>
  168. <QRCode value={url} size={200} fgColor="#000000" />
  169. </div>
  170. );
  171. };
  172. export default AdbHeader;