|
|
@@ -1,40 +1,24 @@
|
|
|
-import React, { useEffect, useRef, useState } from 'react'
|
|
|
+import React, { useRef, useState } from 'react'
|
|
|
import './device.scss'
|
|
|
import UpdateBtn from './update-btn/update-btn.jsx'
|
|
|
import ConnectItem from './connect-item/connect-item.jsx'
|
|
|
-import HintView from '../public/hint-view/hint-view.jsx'
|
|
|
-import Alert from '../public/alert-view/alert-view.jsx'
|
|
|
-import ComfirmView from '../public/comfirm-view/comfirm-view.jsx'
|
|
|
+
|
|
|
import { DeviceClass } from './device.js'
|
|
|
-import hintView from '../public/hint-view/hint-view.js'
|
|
|
-import alertView from '../public/alert-view/alert-view.js'
|
|
|
-import comfirmView from '../public/comfirm-view/comfirm-view.js'
|
|
|
-import { createHandleClose } from '../home.js'
|
|
|
+
|
|
|
+import { alertView, hintView, comfirmView } from '../home.jsx'
|
|
|
|
|
|
function Device({ show }) {
|
|
|
const [deviceList, setDeviceList] = useState([])
|
|
|
- const [showHintView, setShowHintView] = useState(false)
|
|
|
- const [showAlert, setShowAlert] = useState(false)
|
|
|
- const [showComfirmView, setShowComfirmView] = useState(false)
|
|
|
const deviceClass = useRef(null)
|
|
|
|
|
|
if (!show) {
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
- // 初始化 deviceClass,确保在渲染时就有值
|
|
|
if (!deviceClass.current) {
|
|
|
deviceClass.current = new DeviceClass(setDeviceList)
|
|
|
}
|
|
|
|
|
|
- // 设置 API 对象的回调函数并初始化 deviceClass
|
|
|
- useEffect(() => {
|
|
|
- hintView.setShowCallback(setShowHintView)
|
|
|
- alertView.setShowCallback(setShowAlert)
|
|
|
- comfirmView.setShowCallback(setShowComfirmView)
|
|
|
-
|
|
|
- }, [])
|
|
|
-
|
|
|
return (
|
|
|
<>
|
|
|
<div className="device-container">
|
|
|
@@ -72,22 +56,6 @@ function Device({ show }) {
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
- {showHintView && <HintView show={showHintView} onClose={createHandleClose(setShowHintView)} title={hintView._title} content={hintView._content} />}
|
|
|
- {showAlert && <Alert show={showAlert} onClose={createHandleClose(setShowAlert)} title={alertView._title} content={alertView._content} />}
|
|
|
- {showComfirmView && <ComfirmView show={showComfirmView} onClose={() => {
|
|
|
- comfirmView.hide()
|
|
|
- if (comfirmView._onCancel) {
|
|
|
- comfirmView._onCancel()
|
|
|
- }
|
|
|
- }} onConfirm={() => {
|
|
|
- console.log('ComfirmView onConfirm clicked, _onConfirm:', comfirmView._onConfirm)
|
|
|
- if (comfirmView._onConfirm) {
|
|
|
- comfirmView._onConfirm()
|
|
|
- } else {
|
|
|
- console.warn('comfirmView._onConfirm is null')
|
|
|
- }
|
|
|
- }} title={comfirmView._title} content={comfirmView._content} />}
|
|
|
</>
|
|
|
)
|
|
|
}
|