|
|
@@ -1,10 +1,10 @@
|
|
|
import { ref } from 'vue'
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
-import { scanDevices, getDiscoveredDevices, triggerMatch } from '@/api/camera-scan'
|
|
|
+import { scanDevices, getDiscoveredDevices, triggerMatch, bindDevice } from '@/api/camera-scan'
|
|
|
import type { LssNodeDTO, DiscoveredCameraDTO } from '@/types'
|
|
|
|
|
|
-export function useScanDevices() {
|
|
|
+export function useScanDevices(options?: { onRefresh?: () => void }) {
|
|
|
const { t } = useI18n({ useScope: 'global' })
|
|
|
|
|
|
const scanDrawerVisible = ref(false)
|
|
|
@@ -17,20 +17,21 @@ export function useScanDevices() {
|
|
|
async function handleScanDevices(row: LssNodeDTO) {
|
|
|
scanLssId.value = row.lssId
|
|
|
scanMatched.value = false
|
|
|
- scanDrawerVisible.value = true
|
|
|
- scanLoading.value = true
|
|
|
-
|
|
|
try {
|
|
|
if (row.scanned) {
|
|
|
- // 已扫描过,直接加载发现设备列表
|
|
|
+ // 已扫描过,直接打开抽屉加载列表
|
|
|
+ scanDrawerVisible.value = true
|
|
|
+ scanLoading.value = true
|
|
|
await loadDiscoveredDevices()
|
|
|
} else {
|
|
|
- // 未扫描,触发扫描
|
|
|
+ // 未扫描,先触发扫描
|
|
|
+ scanLoading.value = true
|
|
|
const res = await scanDevices(row.lssId)
|
|
|
if (res.success) {
|
|
|
const status = res?.data?.status || ''
|
|
|
switch (status) {
|
|
|
case 'COMPLETED':
|
|
|
+ scanDrawerVisible.value = true
|
|
|
await loadDiscoveredDevices()
|
|
|
break
|
|
|
case 'SCANNING':
|
|
|
@@ -52,6 +53,8 @@ export function useScanDevices() {
|
|
|
ElMessage.error(t('操作失败'))
|
|
|
} finally {
|
|
|
scanLoading.value = false
|
|
|
+ // 每次扫描操作后刷新 LSS 列表,更新 scanned 状态
|
|
|
+ options?.onRefresh?.()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -98,8 +101,24 @@ export function useScanDevices() {
|
|
|
}
|
|
|
|
|
|
async function handleBindDevice(row: DiscoveredCameraDTO) {
|
|
|
- console.log('bind device', row)
|
|
|
- ElMessage.info('绑定功能开发中')
|
|
|
+ try {
|
|
|
+ await ElMessageBox.confirm(t('确定要绑定该设备吗?') + `<br/>IP: ${row.ip}:${row.port}`, t('绑定设备'), {
|
|
|
+ type: 'info',
|
|
|
+ dangerouslyUseHTMLString: true
|
|
|
+ })
|
|
|
+ const res = await bindDevice({ discoveredId: row.id, cameraId: row.cameraId })
|
|
|
+ if (res.success) {
|
|
|
+ ElMessage.success(t('绑定成功'))
|
|
|
+ await loadDiscoveredDevices()
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.errMessage || t('绑定失败'))
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ if (error !== 'cancel') {
|
|
|
+ console.error('绑定失败', error)
|
|
|
+ ElMessage.error(t('绑定失败'))
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return {
|