detail-camera.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. <template>
  2. <view class="container">
  3. <!-- 设备头部信息区域 -->
  4. <view class="device-header">
  5. <view class="device-info-row">
  6. <view class="device-name-container">
  7. <text class="device-name">{{ deviceInfo.name }}</text>
  8. <view class="status-tag" :class="deviceInfo.status === 1 ? 'status-online' : 'status-offline'">
  9. <view class="status-dot" :class="{'offline-dot': deviceInfo.status === 0}"></view>
  10. {{ deviceInfo.status === 1 ? '在线' : '离线' }}
  11. </view>
  12. </view>
  13. <view class="refresh-btn" :class="{'refreshing': isRefreshing}" @tap="refreshData">
  14. <image src="/static/icons/refresh_icon.png" mode="aspectFit" style="width: 22px; height: 22px;">
  15. </image>
  16. </view>
  17. </view>
  18. <view class="device-meta-row">
  19. <view class="device-meta-item">
  20. <view class="meta-icon">
  21. <image src="/static/icons/device_icon.png" mode="aspectFit"
  22. style="width: 36rpx; height: 36rpx;"></image>
  23. </view>
  24. <text class="meta-label">设备编号:</text>
  25. <text class="meta-value">{{ deviceInfo.deviceId }}</text>
  26. </view>
  27. <view class="device-meta-item">
  28. <view class="meta-icon">
  29. <image src="/static/icons/location_icon.png" mode="aspectFit"
  30. style="width: 36rpx; height: 36rpx;"></image>
  31. </view>
  32. <text class="meta-label">安装位置:</text>
  33. <text class="meta-value">{{ deviceInfo.location }}</text>
  34. </view>
  35. <view class="device-meta-item">
  36. <view class="meta-icon">
  37. <image src="/static/icons/clock_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;">
  38. </image>
  39. </view>
  40. <text class="meta-label">最近更新:</text>
  41. <text class="meta-value">{{ formatDate(deviceInfo.lastUpdate) }}</text>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 视频预览区域 -->
  46. <view class="video-section">
  47. <view class="video-container" :class="{'fullscreen-mode': isFullscreen}">
  48. <image v-if="!isPlaying" src="/static/images/video-placeholder.jpg" mode="aspectFill"
  49. class="video-placeholder"></image>
  50. <!-- 使用跨平台视频播放组件 -->
  51. <!-- #ifdef H5 -->
  52. <view v-if="isPlaying" class="h5-video-wrapper">
  53. <Jessibuca ref="jessibucaRef" :videoUrl="getH5StreamUrl" :hasAudio="true" @error="onVideoError" />
  54. </view>
  55. <!-- #endif -->
  56. <!-- #ifdef MP-WEIXIN -->
  57. <live-player v-if="isPlaying" id="videoPlayer" :src="getMiniProgramStreamUrl" mode="live"
  58. :autoplay="true" :muted="isMuted" object-fit="contain" @statechange="onStateChange"
  59. @error="onVideoError" @fullscreenchange="onFullscreenChange" class="video-player"></live-player>
  60. <!-- #endif -->
  61. <!-- 视频控制层 -->
  62. <view class="video-controls">
  63. <view class="control-row top-controls">
  64. <view class="signal-indicator">
  65. <image src="/static/icons/signal_icon.png" mode="aspectFit"
  66. style="width: 16px; height: 16px;"></image>
  67. <text class="signal-text">信号良好</text>
  68. </view>
  69. <view class="fullscreen-button" @click="toggleFullscreen">
  70. <image src="/static/icons/resize_icon.png" mode="aspectFit"
  71. style="width: 20px; height: 20px;"></image>
  72. </view>
  73. </view>
  74. <view class="control-row center-controls">
  75. <view v-if="!isPlaying" class="play-button" @click="togglePlayState">
  76. <image src="/static/icons/play_icon.png" mode="aspectFit"
  77. style="width: 32px; height: 32px;"></image>
  78. </view>
  79. <view v-else class="center-button-container" @click="togglePlayState">
  80. <view class="pause-icon">
  81. <image src="/static/icons/pause_icon.png" mode="aspectFit"
  82. style="width: 24px; height: 24px;"></image>
  83. </view>
  84. </view>
  85. </view>
  86. <view class="control-row bottom-controls">
  87. <view class="video-time">{{ currentTime }}</view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 告警信息列表 -->
  93. <view class="alerts-section">
  94. <view class="section-title">
  95. <text>告警信息</text>
  96. <view class="alert-badge" v-if="getUnhandledAlerts.length > 0">{{ getUnhandledAlerts.length }}</view>
  97. </view>
  98. <view class="alerts-list" v-if="getUnhandledAlerts.length > 0">
  99. <view v-for="(item, index) in getUnhandledAlerts.slice(0, 3)" :key="index" class="alert-item" :class="{
  100. 'alert-urgent': item.level === 3,
  101. 'alert-warning': item.level === 2,
  102. 'alert-info': item.level === 1
  103. }">
  104. <view class="alert-item-icon">
  105. <image v-if="item.level === 3" src="/static/icons/warning_icon.png" mode="aspectFit"
  106. style="width: 24px; height: 24px;"></image>
  107. <image v-else-if="item.level === 2" src="/static/icons/info_icon.png" mode="aspectFit"
  108. style="width: 24px; height: 24px;"></image>
  109. <image v-else src="/static/icons/success_icon.png" mode="aspectFit"
  110. style="width: 24px; height: 24px;"></image>
  111. </view>
  112. <view class="alert-item-info">
  113. <text class="alert-item-type">{{ item.type }}</text>
  114. <text class="alert-item-level">
  115. {{ item.level === 3 ? '紧急' : item.level === 2 ? '警告' : '提示' }}
  116. </text>
  117. </view>
  118. <view class="alert-item-time">{{ formatSmartTime(item.time) }}</view>
  119. </view>
  120. </view>
  121. <view v-else class="empty-alert">
  122. <text class="empty-text">暂无告警信息</text>
  123. </view>
  124. </view>
  125. </view>
  126. </template>
  127. <script setup>
  128. import { ref, reactive, computed, onMounted, onBeforeUnmount } from 'vue'
  129. import {
  130. getDeviceCollectorDetail,
  131. getChannels,
  132. playStart,
  133. pause
  134. } from "@/api/services/device.js"
  135. import {
  136. formatSmartTime,
  137. formatDate,
  138. getFormattedTime
  139. } from '@/utils/dateUtils'
  140. import {
  141. buildPlatformStreamUrls
  142. } from '@/utils/media-utils'
  143. import config from '@/config/config'
  144. // 导入Jessibuca组件
  145. // #ifdef H5
  146. import Jessibuca from '@/components/common/jessibuca.vue'
  147. // #endif
  148. // 响应式数据
  149. const deviceInfo = reactive({
  150. deviceId: '',
  151. name: '设备加载中...',
  152. status: '',
  153. location: '正在获取位置...',
  154. lastUpdate: '',
  155. deviceType: 'weather', // 默认类型,会根据API返回更新
  156. deviceTypeId: null,
  157. streamUrl: '',
  158. channelId: null, // 当前通道ID
  159. originalStreamUrl: 'ws://121.4.16.100:6080/rtp/34020000001110000001_34020000001320000012.live.flv',
  160. })
  161. const isPlaying = ref(false)
  162. const isMuted = ref(false)
  163. const isRecording = ref(false)
  164. const isFullscreen = ref(false)
  165. const isVoiceActive = ref(false)
  166. const isGridView = ref(false)
  167. const isZoomMode = ref(false)
  168. const currentTime = ref('14:30:25')
  169. // 模拟历史录像数据
  170. const recordHistory = ref([{
  171. id: 1,
  172. startTime: '今天 12:30',
  173. duration: '00:15:30',
  174. url: ''
  175. },
  176. {
  177. id: 2,
  178. startTime: '今天 10:15',
  179. duration: '00:05:22',
  180. url: ''
  181. },
  182. {
  183. id: 3,
  184. startTime: '昨天 18:45',
  185. duration: '00:30:10',
  186. url: ''
  187. },
  188. {
  189. id: 4,
  190. startTime: '昨天 14:20',
  191. duration: '00:10:05',
  192. url: ''
  193. }
  194. ])
  195. // 模拟告警数据
  196. const alertHistory = ref([])
  197. const livePlayerContext = ref(null) // 小程序视频上下文
  198. const isRefreshing = ref(false)
  199. const jessibucaRef = ref(null)
  200. // 计算属性
  201. // 获取所有未处理的告警
  202. const getUnhandledAlerts = computed(() => {
  203. return alertHistory.value.filter(alert => alert.status === 0)
  204. })
  205. // 获取H5环境使用的流地址
  206. const getH5StreamUrl = computed(() => {
  207. return deviceInfo.originalStreamUrl || config.streamServer.wsFlvServer
  208. })
  209. // 获取小程序环境使用的流地址
  210. const getMiniProgramStreamUrl = computed(() => {
  211. const {
  212. streamServer
  213. } = config
  214. if (deviceInfo.rtmpUrl) {
  215. return deviceInfo.rtmpUrl
  216. }
  217. if (deviceInfo.hlsUrl) {
  218. return deviceInfo.hlsUrl
  219. }
  220. return streamServer.rtmpServer || streamServer.hlsServer
  221. })
  222. // 方法
  223. // 刷新数据
  224. const refreshData = () => {
  225. isRefreshing.value = true
  226. fetchDeviceInfo()
  227. setTimeout(() => {
  228. isRefreshing.value = false
  229. }, 1000)
  230. }
  231. // 加载Jessibuca脚本
  232. const loadJessibucaScript = () => {
  233. // #ifdef H5
  234. const script = document.createElement('script')
  235. script.src = '/static/js/jessibuca/jessibuca.js'
  236. script.onload = () => {
  237. console.log('Jessibuca 脚本加载成功')
  238. }
  239. script.onerror = (error) => {
  240. console.error('Jessibuca 脚本加载失败:', error)
  241. }
  242. document.head.appendChild(script)
  243. // #endif
  244. // #ifndef H5
  245. // 非 H5 平台不支持 Jessibuca 视频播放
  246. console.warn('当前平台不支持 Jessibuca 视频播放,请使用 uni-app video 组件')
  247. // #endif
  248. }
  249. // 获取设备信息
  250. const fetchDeviceInfo = () => {
  251. console.log('获取设备信息:', deviceInfo.deviceId)
  252. getDeviceCollectorDetail(deviceInfo.deviceId)
  253. .then(res => {
  254. if (res.data.data && res.data.code === 200) {
  255. const detail = res.data.data
  256. deviceInfo.lastUpdate = getFormattedTime()
  257. uni.setNavigationBarTitle({
  258. title: deviceInfo.name
  259. })
  260. if (detail.alertRecordList && detail.alertRecordList.length > 0) {
  261. alertHistory.value = detail.alertRecordList.map(alert => ({
  262. id: alert.alertId,
  263. time: alert.alertTime,
  264. type: alert.alertContent,
  265. status: alert.processStatus,
  266. level: alert.alertLevel
  267. }))
  268. }
  269. }
  270. })
  271. }
  272. // 根据设备id获取通道列表
  273. const queryChannels = () => {
  274. getChannels(deviceInfo.deviceId)
  275. .then(response => {
  276. console.log('获取通道列表:', response)
  277. const res = response[1].data
  278. if (res.code === 0 && res.data.total > 0) {
  279. const channels = res.data.list
  280. deviceInfo.channelId = channels[0].deviceId
  281. playStart(deviceInfo.deviceId, deviceInfo.channelId).then(res => {
  282. if (res[1].data.code !== 0) {
  283. console.error('播放开始失败:', res.message)
  284. uni.showToast({
  285. title: '播放失败: ' + res.message,
  286. icon: 'none'
  287. })
  288. return
  289. }
  290. console.log('播放开始:', res)
  291. deviceInfo.originalStreamUrl = res[1].data.data.ws_flv || deviceInfo.originalStreamUrl
  292. }).catch(err => {
  293. console.error('播放开始失败:', err)
  294. })
  295. } else {
  296. uni.showToast({
  297. title: '获取通道列表失败: ' + res.message,
  298. icon: 'none'
  299. })
  300. return
  301. }
  302. })
  303. .catch(err => {
  304. console.error('获取通道列表错误:', err)
  305. })
  306. }
  307. // 播放/暂停切换
  308. const togglePlayState = () => {
  309. if (!isPlaying.value) {
  310. isPlaying.value = true
  311. // #ifdef MP-WEIXIN
  312. setTimeout(() => {
  313. if (livePlayerContext.value) {
  314. livePlayerContext.value.play({
  315. success: () => {
  316. console.log('小程序视频播放成功')
  317. uni.vibrateShort()
  318. },
  319. fail: (err) => {
  320. console.error('小程序视频播放失败:', err)
  321. uni.showToast({
  322. title: '视频播放失败',
  323. icon: 'none'
  324. })
  325. }
  326. })
  327. }
  328. }, 300)
  329. // #endif
  330. // #ifdef H5
  331. setTimeout(() => {
  332. playStart(deviceInfo.deviceId, deviceInfo.channelId).then(res => {
  333. if (res[1].data.code !== 0) {
  334. console.error('播放开始失败:', res.message)
  335. uni.showToast({
  336. title: '播放失败: ' + res.message,
  337. icon: 'none'
  338. })
  339. return
  340. }
  341. console.log('播放开始:', res[1])
  342. deviceInfo.originalStreamUrl = res[1].data.data.ws_flv || deviceInfo.originalStreamUrl
  343. }).catch(err => {
  344. console.error('播放开始失败:', err)
  345. })
  346. uni.vibrateShort()
  347. }, 300)
  348. // #endif
  349. } else {
  350. // #ifdef H5
  351. if (jessibucaRef.value) {
  352. jessibucaRef.value.pause()
  353. }
  354. // #endif
  355. // #ifdef MP-WEIXIN
  356. if (livePlayerContext.value) {
  357. livePlayerContext.value.pause()
  358. }
  359. // #endif
  360. isPlaying.value = false
  361. uni.showToast({
  362. title: '视频已暂停',
  363. icon: 'none',
  364. duration: 1500
  365. })
  366. }
  367. }
  368. // 静音切换
  369. const toggleMute = () => {
  370. isMuted.value = !isMuted.value
  371. // #ifdef H5
  372. if (jessibucaRef.value) {
  373. if (isMuted.value) {
  374. jessibucaRef.value.mute()
  375. } else {
  376. jessibucaRef.value.cancelMute()
  377. }
  378. }
  379. // #endif
  380. }
  381. // 全屏切换
  382. const toggleFullscreen = () => {
  383. if (!isPlaying.value) {
  384. togglePlayState()
  385. setTimeout(() => {
  386. setFullscreen(true)
  387. }, 500)
  388. } else {
  389. setFullscreen(!isFullscreen.value)
  390. }
  391. }
  392. // 设置全屏状态
  393. const setFullscreen = (fullscreen) => {
  394. isFullscreen.value = fullscreen
  395. // #ifdef H5
  396. if (isFullscreen.value) {
  397. const ua = navigator.userAgent.toLowerCase()
  398. const isMobile = /mobile|android|iphone|ipad/.test(ua)
  399. if (isMobile && jessibucaRef.value) {
  400. jessibucaRef.value.fullscreenSwich()
  401. } else {
  402. setTimeout(() => {
  403. if (jessibucaRef.value) {
  404. jessibucaRef.value.resize()
  405. }
  406. }, 300)
  407. }
  408. if (window.screen && window.screen.orientation && window.screen.orientation.lock) {
  409. window.screen.orientation.lock('landscape').catch(err => {
  410. console.error('无法锁定屏幕方向:', err)
  411. })
  412. }
  413. } else {
  414. if (jessibucaRef.value) {
  415. if (jessibucaRef.value.isFullscreen()) {
  416. jessibucaRef.value.fullscreenSwich()
  417. }
  418. setTimeout(() => {
  419. if (jessibucaRef.value) {
  420. jessibucaRef.value.resize()
  421. }
  422. }, 300)
  423. }
  424. if (window.screen && window.screen.orientation && window.screen.orientation.unlock) {
  425. window.screen.orientation.unlock()
  426. }
  427. }
  428. // #endif
  429. // #ifdef MP-WEIXIN
  430. if (livePlayerContext.value) {
  431. if (isFullscreen.value) {
  432. livePlayerContext.value.requestFullScreen({
  433. direction: 90,
  434. success: () => {
  435. console.log('进入全屏模式成功')
  436. },
  437. fail: (err) => {
  438. console.error('进入全屏模式失败:', err)
  439. }
  440. })
  441. } else {
  442. livePlayerContext.value.exitFullScreen({
  443. success: () => {
  444. console.log('退出全屏模式成功')
  445. },
  446. fail: (err) => {
  447. console.error('退出全屏模式失败:', err)
  448. }
  449. })
  450. }
  451. }
  452. // #endif
  453. }
  454. // 截图
  455. const takeScreenshot = () => {
  456. // #ifdef H5
  457. if (jessibucaRef.value && isPlaying.value) {
  458. jessibucaRef.value.screenshot()
  459. uni.showToast({
  460. title: '截图已保存',
  461. icon: 'success'
  462. })
  463. } else {
  464. uni.showToast({
  465. title: '请先播放视频',
  466. icon: 'none'
  467. })
  468. }
  469. // #endif
  470. // #ifdef MP-WEIXIN
  471. if (livePlayerContext.value && isPlaying.value) {
  472. livePlayerContext.value.snapshot({
  473. success: (res) => {
  474. console.log('截图成功:', res.tempImagePath)
  475. uni.saveImageToPhotosAlbum({
  476. filePath: res.tempImagePath,
  477. success: () => {
  478. uni.showToast({
  479. title: '截图已保存到相册',
  480. icon: 'success'
  481. })
  482. },
  483. fail: (err) => {
  484. console.error('保存截图失败:', err)
  485. uni.showToast({
  486. title: '保存截图失败',
  487. icon: 'none'
  488. })
  489. }
  490. })
  491. },
  492. fail: (err) => {
  493. console.error('截图失败:', err)
  494. uni.showToast({
  495. title: '截图失败',
  496. icon: 'none'
  497. })
  498. }
  499. })
  500. } else {
  501. uni.showToast({
  502. title: '请先播放视频',
  503. icon: 'none'
  504. })
  505. }
  506. // #endif
  507. }
  508. // 小程序播放器状态变化处理
  509. const onStateChange = (e) => {
  510. console.log('播放器状态变化:', e.detail)
  511. const state = e.detail.code
  512. switch (state) {
  513. case 2001:
  514. console.log('已连接服务器')
  515. break
  516. case 2002:
  517. console.log('开始拉流')
  518. break
  519. case 2003:
  520. console.log('网络接收到首个视频帧')
  521. break
  522. case 2004:
  523. console.log('视频播放开始')
  524. break
  525. case 2005:
  526. console.log('视频播放进度')
  527. break
  528. case 2006:
  529. console.log('视频播放结束')
  530. isPlaying.value = false
  531. break
  532. case 2007:
  533. console.log('视频播放Loading')
  534. break
  535. case 2008:
  536. console.log('解码器启动')
  537. break
  538. case 2009:
  539. console.log('视频分辨率改变')
  540. break
  541. case -2301:
  542. console.error('网络断连,且重新连接亦不能恢复,播放器已停止')
  543. isPlaying.value = false
  544. uni.showToast({
  545. title: '网络断连,请重试',
  546. icon: 'none'
  547. })
  548. break
  549. case -2302:
  550. console.error('获取加速拉流地址失败')
  551. break
  552. case 2101:
  553. console.error('当前视频帧解码失败')
  554. break
  555. case 2102:
  556. console.error('当前音频帧解码失败')
  557. break
  558. case 2103:
  559. console.warn('网络断连, 已启动自动重连')
  560. break
  561. case 2104:
  562. console.warn('网络断连, 重连中...')
  563. break
  564. case 2105:
  565. console.log('网络断连, 重连成功')
  566. break
  567. case 2106:
  568. console.error('网络断连, 重连失败')
  569. break
  570. case 2107:
  571. console.error('播放器连接超时')
  572. break
  573. case 2108:
  574. console.error('获取点播文件信息失败')
  575. break
  576. default:
  577. console.log('其他状态:', state)
  578. }
  579. }
  580. // 小程序全屏状态变化
  581. const onFullscreenChange = (e) => {
  582. isFullscreen.value = e.detail.fullScreen
  583. console.log('全屏状态变化:', isFullscreen.value)
  584. }
  585. // 初始化流地址
  586. const initStreamUrl = () => {
  587. const originalUrl = deviceInfo.originalStreamUrl
  588. const streamUrls = buildPlatformStreamUrls(originalUrl, {
  589. streamServer: config.streamServer,
  590. fallbackToHls: true
  591. })
  592. // #ifdef H5
  593. deviceInfo.streamUrl = streamUrls.h5Url
  594. // #endif
  595. // #ifdef MP-WEIXIN
  596. if (streamUrls.miniProgramUrl) {
  597. deviceInfo.streamUrl = streamUrls.miniProgramUrl
  598. } else {
  599. uni.showToast({
  600. title: '当前视频流不支持小程序播放',
  601. icon: 'none',
  602. duration: 3000
  603. })
  604. }
  605. // #endif
  606. console.log('初始化流地址:', deviceInfo.streamUrl)
  607. }
  608. // 切换九宫格视图
  609. const toggleGridView = () => {
  610. isGridView.value = !isGridView.value
  611. uni.showToast({
  612. title: isGridView.value ? '切换到多画面模式' : '切换到单画面模式',
  613. icon: 'none'
  614. })
  615. }
  616. // 语音对讲
  617. const toggleVoiceIntercom = () => {
  618. isVoiceActive.value = !isVoiceActive.value
  619. if (isVoiceActive.value) {
  620. uni.showToast({
  621. title: '语音对讲已开启',
  622. icon: 'none'
  623. })
  624. } else {
  625. uni.showToast({
  626. title: '语音对讲已关闭',
  627. icon: 'none'
  628. })
  629. }
  630. }
  631. // 云台控制
  632. const controlPTZ = (direction, isStart) => {
  633. if (isStart) {
  634. console.log(`开始控制云台: ${direction}`)
  635. uni.vibrateShort()
  636. } else {
  637. console.log(`停止控制云台: ${direction}`)
  638. }
  639. }
  640. // 云台复位
  641. const resetPTZ = () => {
  642. console.log('云台复位')
  643. uni.vibrateShort()
  644. uni.showToast({
  645. title: '云台已复位',
  646. icon: 'none'
  647. })
  648. }
  649. // 变焦控制
  650. const controlZoom = (type, isStart) => {
  651. if (isStart) {
  652. console.log(`开始控制变焦: ${type}`)
  653. uni.vibrateShort()
  654. } else {
  655. console.log(`停止控制变焦: ${type}`)
  656. }
  657. }
  658. // 切换缩放模式
  659. const toggleZoom = () => {
  660. isZoomMode.value = !isZoomMode.value
  661. uni.showToast({
  662. title: isZoomMode.value ? '进入缩放模式' : '退出缩放模式',
  663. icon: 'none'
  664. })
  665. }
  666. // 添加预设位
  667. const addPreset = () => {
  668. uni.showModal({
  669. title: '添加预设位',
  670. content: '是否保存当前位置为预设位?',
  671. success: (res) => {
  672. if (res.confirm) {
  673. uni.showToast({
  674. title: '预设位已保存',
  675. icon: 'success'
  676. })
  677. }
  678. }
  679. })
  680. }
  681. // 处理告警点击
  682. const handleAlert = (item) => {
  683. uni.navigateTo({
  684. url: `/pages/alerts/alert-detail?alertId=${item.id}&deviceId=${deviceInfo.deviceId}`
  685. })
  686. }
  687. // 跳转到历史视频页面
  688. const navigateToHistory = () => {
  689. uni.navigateTo({
  690. url: `/pages/video/history?deviceId=${deviceInfo.deviceId}`
  691. })
  692. }
  693. // 视频播放错误处理
  694. const onVideoError = (e) => {
  695. console.error('视频播放错误:', e)
  696. uni.showToast({
  697. title: '视频加载失败,请检查网络连接',
  698. icon: 'none',
  699. duration: 2000
  700. })
  701. // #ifdef H5
  702. setTimeout(() => {
  703. if (isPlaying.value && jessibucaRef.value) {
  704. console.log('尝试重新加载视频流')
  705. if (deviceInfo.originalStreamUrl !== config.streamServer.wsFlvServer) {
  706. deviceInfo.streamUrl = config.streamServer.wsFlvServer
  707. }
  708. }
  709. }, 3000)
  710. // #endif
  711. }
  712. // 更新时间
  713. const startTimeUpdate = () => {
  714. setInterval(() => {
  715. const now = new Date()
  716. const hours = String(now.getHours()).padStart(2, '0')
  717. const minutes = String(now.getMinutes()).padStart(2, '0')
  718. const seconds = String(now.getSeconds()).padStart(2, '0')
  719. currentTime.value = `${hours}:${minutes}:${seconds}`
  720. }, 1000)
  721. }
  722. // 设置全屏状态监听
  723. const setupFullscreenListener = () => {
  724. // Placeholder for fullscreen listener setup
  725. }
  726. // 设置键盘监听
  727. const setupKeyboardListener = () => {
  728. // Placeholder for keyboard listener setup
  729. }
  730. // 生命周期钩子
  731. onMounted(() => {
  732. uni.setNavigationBarTitle({
  733. title: deviceInfo.name
  734. })
  735. startTimeUpdate()
  736. // #ifdef MP-WEIXIN
  737. livePlayerContext.value = uni.createLivePlayerContext('videoPlayer')
  738. // #endif
  739. // #ifdef H5
  740. loadJessibucaScript()
  741. // #endif
  742. setupFullscreenListener()
  743. setupKeyboardListener()
  744. initStreamUrl()
  745. })
  746. onBeforeUnmount(() => {
  747. console.log("停止点播")
  748. pause(deviceInfo.deviceId, deviceInfo.channelId).then(res => {
  749. if (res[1].data.code !== 0) {
  750. console.error('暂停失败:', res.message)
  751. } else {
  752. console.log('视频已暂停')
  753. }
  754. }).catch(err => {
  755. console.error('暂停请求错误:', err)
  756. })
  757. })
  758. // uni-app 生命周期
  759. uni.$once('passDeviceData', (data) => {
  760. console.log('接收到数据', data)
  761. if (data && data.deviceId) {
  762. deviceInfo.deviceId = data.deviceId
  763. deviceInfo.location = data.fieldName
  764. deviceInfo.name = data.deviceName
  765. deviceInfo.status = data.status
  766. deviceInfo.deviceTypeId = data.deviceTypeId || ''
  767. fetchDeviceInfo()
  768. queryChannels()
  769. }
  770. })
  771. </script>
  772. <style>
  773. /* 基础样式 */
  774. .container {
  775. display: flex;
  776. flex-direction: column;
  777. min-height: 100vh;
  778. background-color: #F8FCF9;
  779. padding-bottom: 30rpx;
  780. }
  781. /* 设备头部样式 */
  782. .device-header {
  783. background-color: #FFFFFF;
  784. border-radius: 20rpx;
  785. padding: 26rpx 30rpx 30rpx;
  786. margin: 20rpx 30rpx 20rpx;
  787. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  788. }
  789. .device-info-row {
  790. display: flex;
  791. justify-content: space-between;
  792. align-items: flex-start;
  793. margin-bottom: 24rpx;
  794. }
  795. .device-name-container {
  796. display: flex;
  797. flex-direction: column;
  798. align-items: flex-start;
  799. }
  800. .device-name {
  801. font-size: 34rpx;
  802. color: #333333;
  803. font-weight: 600;
  804. margin-bottom: 10rpx;
  805. }
  806. .status-tag {
  807. padding: 4rpx 12rpx 4rpx 24rpx;
  808. border-radius: 30rpx;
  809. font-size: 22rpx;
  810. font-weight: 500;
  811. flex-shrink: 0;
  812. position: relative;
  813. overflow: hidden;
  814. }
  815. .status-online {
  816. background-color: rgba(76, 175, 80, 0.1);
  817. color: #3BB44A;
  818. }
  819. .status-offline {
  820. background-color: rgba(245, 108, 108, 0.1);
  821. color: #F56C6C;
  822. padding-left: 24rpx;
  823. }
  824. .status-dot {
  825. position: absolute;
  826. width: 6rpx;
  827. height: 6rpx;
  828. background-color: #3BB44A;
  829. border-radius: 50%;
  830. top: 50%;
  831. left: 12rpx;
  832. transform: translateY(-50%);
  833. box-shadow: 0 0 4rpx rgba(76, 175, 80, 0.8);
  834. animation: blink 1.5s infinite;
  835. display: inline-block;
  836. }
  837. .status-dot.offline-dot {
  838. background-color: #F56C6C;
  839. box-shadow: 0 0 4rpx rgba(245, 108, 108, 0.8);
  840. }
  841. @keyframes blink {
  842. 0% {
  843. opacity: 0.4;
  844. }
  845. 50% {
  846. opacity: 1;
  847. }
  848. 100% {
  849. opacity: 0.4;
  850. }
  851. }
  852. .device-meta-row {
  853. display: flex;
  854. flex-direction: column;
  855. }
  856. .device-meta-item {
  857. display: flex;
  858. align-items: center;
  859. font-size: 26rpx;
  860. margin-top: 18rpx;
  861. }
  862. .meta-icon {
  863. width: 36rpx;
  864. height: 36rpx;
  865. display: flex;
  866. align-items: center;
  867. justify-content: center;
  868. margin-right: 8rpx;
  869. }
  870. .meta-label {
  871. color: #999999;
  872. min-width: 140rpx;
  873. font-size: 26rpx;
  874. }
  875. .meta-value {
  876. color: #333333;
  877. flex: 1;
  878. font-size: 26rpx;
  879. }
  880. /* 视频预览区域 */
  881. .video-section {
  882. margin: 0 30rpx 20rpx;
  883. position: relative;
  884. z-index: 1;
  885. }
  886. .video-container {
  887. position: relative;
  888. width: 100%;
  889. height: 420rpx;
  890. background-color: #000000;
  891. border-radius: 16rpx;
  892. overflow: hidden;
  893. box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.1);
  894. transition: all 0.3s ease;
  895. }
  896. .video-container.fullscreen-mode {
  897. position: fixed;
  898. top: 0;
  899. left: 0;
  900. width: 100vw;
  901. height: 100vh;
  902. margin: 0;
  903. z-index: 9999;
  904. border-radius: 0;
  905. }
  906. .video-container.fullscreen-mode .video-controls {
  907. padding: 30rpx;
  908. }
  909. .video-container.fullscreen-mode .top-controls,
  910. .video-container.fullscreen-mode .bottom-controls {
  911. opacity: 0;
  912. transition: opacity 0.3s ease;
  913. }
  914. .video-container.fullscreen-mode:hover .top-controls,
  915. .video-container.fullscreen-mode:hover .bottom-controls {
  916. opacity: 1;
  917. }
  918. .video-player,
  919. .video-placeholder {
  920. width: 100%;
  921. height: 100%;
  922. object-fit: contain;
  923. }
  924. .video-controls {
  925. position: absolute;
  926. top: 0;
  927. left: 0;
  928. width: 100%;
  929. height: 100%;
  930. display: flex;
  931. flex-direction: column;
  932. justify-content: space-between;
  933. padding: 20rpx;
  934. box-sizing: border-box;
  935. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.4) 100%);
  936. }
  937. .control-row {
  938. display: flex;
  939. justify-content: space-between;
  940. align-items: center;
  941. width: 100%;
  942. }
  943. .top-controls {
  944. height: 80rpx;
  945. }
  946. .center-controls {
  947. height: 120rpx;
  948. justify-content: center;
  949. align-items: center;
  950. }
  951. .bottom-controls {
  952. height: 80rpx;
  953. }
  954. .signal-indicator {
  955. display: flex;
  956. align-items: center;
  957. color: #FFFFFF;
  958. font-size: 24rpx;
  959. background-color: rgba(0, 0, 0, 0.5);
  960. padding: 8rpx 16rpx;
  961. border-radius: 30rpx;
  962. }
  963. .signal-indicator svg {
  964. margin-right: 8rpx;
  965. }
  966. .signal-text {
  967. font-weight: 500;
  968. }
  969. .fullscreen-button {
  970. width: 60rpx;
  971. height: 60rpx;
  972. display: flex;
  973. align-items: center;
  974. justify-content: center;
  975. color: #FFFFFF;
  976. background-color: rgba(0, 0, 0, 0.5);
  977. border-radius: 50%;
  978. transition: all 0.2s;
  979. }
  980. .fullscreen-button:active {
  981. background-color: rgba(76, 175, 80, 0.7);
  982. transform: scale(0.9);
  983. }
  984. .video-time {
  985. color: #FFFFFF;
  986. font-size: 26rpx;
  987. background-color: rgba(0, 0, 0, 0.5);
  988. padding: 6rpx 16rpx;
  989. border-radius: 30rpx;
  990. font-weight: 500;
  991. }
  992. .play-button {
  993. width: 100rpx;
  994. height: 100rpx;
  995. border-radius: 50%;
  996. background-color: rgba(255, 255, 255, 0.9);
  997. display: flex;
  998. align-items: center;
  999. justify-content: center;
  1000. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.5);
  1001. transition: all 0.2s;
  1002. transform: scale(1);
  1003. }
  1004. .play-button:active {
  1005. transform: scale(0.92);
  1006. background-color: rgba(255, 255, 255, 1);
  1007. }
  1008. .center-button-container {
  1009. width: 100%;
  1010. height: 100%;
  1011. display: flex;
  1012. align-items: center;
  1013. justify-content: center;
  1014. }
  1015. .pause-icon {
  1016. width: 80rpx;
  1017. height: 80rpx;
  1018. border-radius: 50%;
  1019. background-color: rgba(0, 0, 0, 0.5);
  1020. display: flex;
  1021. align-items: center;
  1022. justify-content: center;
  1023. opacity: 0;
  1024. transition: opacity 0.3s;
  1025. }
  1026. .center-button-container:active .pause-icon {
  1027. opacity: 1;
  1028. background-color: rgba(76, 175, 80, 0.7);
  1029. }
  1030. .refresh-btn {
  1031. width: 48rpx;
  1032. height: 48rpx;
  1033. background-color: rgba(76, 175, 80, 0.1);
  1034. border-radius: 50%;
  1035. display: flex;
  1036. align-items: center;
  1037. justify-content: center;
  1038. padding: 12rpx;
  1039. transition: transform 0.3s ease;
  1040. }
  1041. .refresh-btn:active {
  1042. transform: rotate(180deg);
  1043. }
  1044. .section-title {
  1045. font-size: 30rpx;
  1046. font-weight: 600;
  1047. color: #333333;
  1048. margin-bottom: 20rpx;
  1049. padding: 0 10rpx;
  1050. display: flex;
  1051. align-items: center;
  1052. }
  1053. .alert-badge {
  1054. background-color: #F56C6C;
  1055. color: #FFFFFF;
  1056. font-size: 22rpx;
  1057. border-radius: 30rpx;
  1058. padding: 2rpx 12rpx;
  1059. margin-left: 12rpx;
  1060. font-weight: normal;
  1061. min-width: 32rpx;
  1062. text-align: center;
  1063. }
  1064. /* 告警信息列表 */
  1065. .alerts-section {
  1066. margin: 0 30rpx;
  1067. background-color: #FFFFFF;
  1068. border-radius: 20rpx;
  1069. padding: 24rpx;
  1070. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  1071. }
  1072. .alerts-list {
  1073. display: flex;
  1074. flex-direction: column;
  1075. }
  1076. .alert-item {
  1077. display: flex;
  1078. align-items: center;
  1079. padding: 24rpx 20rpx;
  1080. border-radius: 12rpx;
  1081. margin-bottom: 16rpx;
  1082. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  1083. position: relative;
  1084. }
  1085. .alert-urgent {
  1086. background-color: #FEF3F3;
  1087. border-left: 4rpx solid #F56C6C;
  1088. }
  1089. .alert-warning {
  1090. background-color: #FFF8E6;
  1091. border-left: 4rpx solid #E6A23C;
  1092. }
  1093. .alert-info {
  1094. background-color: #F2FAF5;
  1095. border-left: 4rpx solid #67C23A;
  1096. }
  1097. .alert-item-icon {
  1098. width: 50rpx;
  1099. height: 50rpx;
  1100. display: flex;
  1101. align-items: center;
  1102. justify-content: center;
  1103. margin-right: 16rpx;
  1104. }
  1105. .alert-item-info {
  1106. flex: 1;
  1107. display: flex;
  1108. flex-direction: column;
  1109. }
  1110. .alert-item-type {
  1111. font-size: 28rpx;
  1112. color: #333333;
  1113. font-weight: 500;
  1114. margin-bottom: 8rpx;
  1115. }
  1116. .alert-item-level {
  1117. font-size: 24rpx;
  1118. color: #999999;
  1119. }
  1120. .alert-item-time {
  1121. font-size: 24rpx;
  1122. color: #999999;
  1123. margin-left: 16rpx;
  1124. min-width: 100rpx;
  1125. text-align: right;
  1126. }
  1127. .empty-alert {
  1128. padding: 60rpx 0;
  1129. display: flex;
  1130. justify-content: center;
  1131. align-items: center;
  1132. }
  1133. .empty-text {
  1134. font-size: 28rpx;
  1135. color: #999999;
  1136. }
  1137. </style>