detail-camera.vue 34 KB

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