videoMonitoring.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <!-- 视频监控-->
  2. <template>
  3. <view class="earlyWarning">
  4. <scroll-view scroll-x @scrolltolower="scrollGet" class="header">
  5. <view class="tabTitle_tow">
  6. <view class="tabTitle_tow_li" @tap="tabClickTow(item,index)" :key="index" v-for="(item,index) in videoHardwareList">
  7. <view :class="{on:curTabTow==index}" class="tabTitle_tow_text">{{item.name}}</view>
  8. <view :class="{on:curTabTow==index}" class="tabTitle_tow_across"></view>
  9. </view>
  10. </view>
  11. </scroll-view>
  12. <scroll-view scroll-y @scrolltolower="scrollGet" class="info-max-box">
  13. <!-- 视频部分 -->
  14. <view class="video-max-box" v-if="urlList[0]">
  15. <video v-for="(item,index) in urlList" :key="index" ref="videoRef" :src="item.url"
  16. :poster="videoCover" :custom-cache='false' :autoplay="true" :controls="true"
  17. :enable-danmu="false" :muted="true" :show-fullscreen-btn="true" :show-center-play-btn="false"
  18. :show-play-btn="false" @error="videoErrorCallback">
  19. </video>
  20. </view>
  21. <view class="broadcast">
  22. <view class="broadcast_t">语音广播<label>选择喇叭位置</label></view>
  23. <!-- 按钮部分 -->
  24. <view class="trumpet-max-box">
  25. <view @click="trumpetClick(index)" class="trumpet-for-box"
  26. :class="item.type?'trumpet-color-a':'trumpet-color-b'" v-for="(item,index) in trumpetList"
  27. :key="index">
  28. <img src="@/images/icon_sskz_zc.png" v-if="!item.type">
  29. <img src="@/images/icon_sskz_xz.png" v-if="item.type">
  30. {{item.name}}
  31. </view>
  32. </view>
  33. <view class="broadcast_m">
  34. <view class="broadcast_m_t" :class="liveType?'broadcast_m_t_back_a':'broadcast_m_t_back_b'"
  35. @longpress.stop="recordButton" @touchmove.stop="cancelButton" @touchend.stop="sendButton">
  36. {{liveType?'松开发送':'按住说话'}}
  37. </view>
  38. <view class="broadcast_m_b" v-if="!liveType">按住说话,录入广播内容</view>
  39. <view class="broadcast_m_b" v-if="liveType">松开发送,向上滑动取消发送</view>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. </view>
  44. </template>
  45. <script>
  46. import { config } from '@/api/request/config.js'
  47. import {laboratoryInfo,getCameraByFloor,GetStartList,getDeviceListBySub,sparseHardwareList} from '@/api/index.js'
  48. export default {
  49. name: "rectifyList",
  50. components: {
  51. },
  52. data() {
  53. return {
  54. videoCover: uni.getStorageSync('videoCover'),
  55. tabTextTow:[{name:'RFID摄像头'},{name:'房间内监控1'},{name:'房间内监控2'},{name:'房间内监控3'},{name:'房间内监控3'},{name:'房间内监控3'},],
  56. curTabTow:0,
  57. //视频数据
  58. urlList: [{}],
  59. videoHardwareNUM:[], //实验室和楼道摄像头编码
  60. trumpetList:[],
  61. //广播相关
  62. liveType: false,
  63. sendLock: true, //发送锁,当为true时上锁,false时解锁发送
  64. recorderManager: wx.getRecorderManager(),
  65. videoHardwareList:[],//获取所有摄像头编码
  66. hardwareList:[],//硬件列表
  67. subId:'96',
  68. floorId:'58',
  69. }
  70. },
  71. onLoad(option) {
  72. // if(option.subId || option.floorId){
  73. // this.subId=option.subId
  74. // this.floorId=option.floorId
  75. // }
  76. },
  77. onShow() {
  78. },
  79. mounted(){
  80. //this.laboratoryInfo()
  81. //this.getDeviceList()
  82. //this.getCameraByFloor()
  83. this.sparseHardwareList()
  84. },
  85. methods: {
  86. //顶部tab点击
  87. tabClickTow(item,index) {
  88. this.curTabTow = index;
  89. this.GetStartList(item)
  90. },
  91. //滚动事件
  92. scrollGet(){
  93. let self=this;
  94. },
  95. videoErrorCallback(e){
  96. console.log("播放失败",e);
  97. },
  98. //获取实验室摄像头
  99. async laboratoryInfo() {
  100. let _this = this;
  101. const {
  102. data
  103. } = await laboratoryInfo(_this.subId);
  104. if (data.code == 200) {
  105. let list = data.data[0];
  106. list.labHardwareVOList.forEach(function(item) {
  107. if (item.hardwareTypeEnum.enumName == 'VIDEO_MONITOR') {
  108. _this.videoHardwareList.push({name:item.hardwareName,num:item.hardwareNUM})
  109. }
  110. })
  111. _this.GetStartList(_this.videoHardwareList[0])
  112. console.log(_this.videoHardwareList)
  113. }
  114. },
  115. //获取疏散硬件列表
  116. async sparseHardwareList() {
  117. let _this = this;
  118. const {
  119. data
  120. } = await sparseHardwareList()
  121. if (data.code == 200) {
  122. if(data.rows[0]){
  123. this.hardwareList=data.rows;
  124. this.getCameraByFloor();
  125. }else{
  126. this.laboratoryInfo();
  127. }
  128. }
  129. },
  130. //获取楼层摄像头列表
  131. async getCameraByFloor() {
  132. let _this = this;
  133. const {
  134. data
  135. } = await getCameraByFloor({
  136. floorId: this.floorId
  137. })
  138. if (data.code == 200) {
  139. for(let i=0;i<data.data.length;i++){
  140. for(let k=0;k<_this.hardwareList.length;k++){
  141. if(data.data[i]==_this.hardwareList[k].hardwareNum){
  142. _this.videoHardwareList.push({name:_this.hardwareList[k].name,num:_this.hardwareList[k].hardwareNum})
  143. }
  144. }
  145. }
  146. this.laboratoryInfo()
  147. }
  148. },
  149. async GetStartList(rows) {
  150. console.log(rows)
  151. let self = this;
  152. if(!rows[0]){
  153. return
  154. }
  155. let list = rows.num;
  156. let obj = {
  157. page: "1",
  158. count: "100",
  159. deviceIds: list,
  160. };
  161. const {
  162. data
  163. } = await GetStartList(obj)
  164. if (data.code == 200) {
  165. let list = [];
  166. for(let i=0;i<data.data.length;i++){
  167. let text = uni.getStorageSync('cameraUrl');
  168. let url = data.data[i].hls;
  169. url = url.split("rtp/");
  170. let newUrl = text + 'rtp/' + url[1];
  171. let obj = {
  172. name: "楼道监控" + (i + 1),
  173. id:data.data[i].deviceID,
  174. url: newUrl,
  175. videoContext:wx.createVideoContext(data.data[i].deviceID)
  176. }
  177. list.push(obj)
  178. }
  179. this.urlList = list;
  180. }
  181. },
  182. //获取喇叭列表
  183. async getDeviceList() {
  184. let obj = {
  185. subId: this.subId,
  186. floorId: this.floorId,
  187. page: 1,
  188. pageSize: 100,
  189. };
  190. const {
  191. data
  192. } = await getDeviceListBySub(obj)
  193. if (data.code == 200) {
  194. for (let i = 0; i < data.data.length; i++) {
  195. data.data[i].type = false;
  196. }
  197. this.$set(this, 'trumpetList', data.data)
  198. }
  199. },
  200. //点击选择喇叭
  201. trumpetClick(index) {
  202. this.trumpetList[index].type = !this.trumpetList[index].type
  203. },
  204. //录制
  205. recordButton(e) {
  206. console.log("按下")
  207. let self = this;
  208. let num = 0;
  209. for (let i = 0; i < self.trumpetList.length; i++) {
  210. if (self.trumpetList[i].type) {
  211. num++
  212. }
  213. }
  214. if (num == 0) {
  215. uni.showToast({
  216. title: '请选择喇叭',
  217. icon: "none",
  218. mask: true,
  219. duration: 2000
  220. });
  221. return
  222. }
  223. this.liveType = true;
  224. console.log('录制', e)
  225. this.startPoint = e.touches[0]; //记录长按时开始点信息,后面用于计算上划取消时手指滑动的距离。
  226. const options = {
  227. duration: 10000,
  228. sampleRate: 16000,
  229. numberOfChannels: 1,
  230. encodeBitRate: 48000,
  231. format: 'mp3',
  232. frameSize: 50
  233. }
  234. this.recorderManager.start(options); //开始录音
  235. this.recorderManager.onStart(() => {
  236. console.log('recorder start')
  237. })
  238. this.recorderManager.onError((res) => {
  239. console.log(res);
  240. })
  241. wx.showToast({
  242. title: "正在录音,上划取消发送",
  243. icon: "none",
  244. duration: 60000 //先定义个60秒,后面可以手动调用wx.hideToast()隐藏
  245. });
  246. this.sendLock = false; //长按时是不上锁的。
  247. },
  248. //取消
  249. cancelButton(e) {
  250. console.log("移动")
  251. let self = this;
  252. let num = 0;
  253. for (let i = 0; i < self.trumpetList.length; i++) {
  254. if (self.trumpetList[i].type) {
  255. num++
  256. }
  257. }
  258. if (num == 0) {
  259. return
  260. }
  261. this.liveType = false;
  262. console.log('取消', e)
  263. let moveLenght = e.touches[e.touches.length - 1].clientY - this.startPoint.clientY; //移动距离
  264. if (Math.abs(moveLenght) > 50) {
  265. wx.showToast({
  266. title: "松开手指,取消发送",
  267. icon: "none",
  268. duration: 60000
  269. });
  270. this.sendLock = true; //触发了上滑取消发送,上锁
  271. } else {
  272. wx.showToast({
  273. title: "正在录音,上划取消发送",
  274. icon: "none",
  275. duration: 60000
  276. });
  277. this.sendLock = false; //上划距离不足,依然可以发送,不上锁
  278. }
  279. },
  280. //发送
  281. sendButton(e) {
  282. console.log("松开")
  283. let self = this;
  284. let num = 0;
  285. for (let i = 0; i < self.trumpetList.length; i++) {
  286. if (self.trumpetList[i].type) {
  287. num++
  288. }
  289. }
  290. if (num == 0) {
  291. return
  292. }
  293. this.liveType = false;
  294. console.log('发送', e)
  295. wx.hideToast(); //结束录音、隐藏Toast提示框
  296. this.recorderManager.stop(); //结束录音
  297. this.recorderManager.onStop((res) => {
  298. if (!this.sendLock) {
  299. console.log('1', this.recorderManager)
  300. this.uploadImg(res.tempFilePath);
  301. }
  302. console.log('停止录音', res.tempFilePath)
  303. console.log("sendLock", this.sendLock);
  304. })
  305. },
  306. //上传MP3
  307. async uploadImg(tempFilePaths) {
  308. var self = this;
  309. uni.uploadFile({
  310. url: config.base_url + '/base/file/upload', //仅为示例,非真实的接口地址
  311. header: {
  312. 'Authorization': uni.getStorageSync('token')
  313. },
  314. filePath: tempFilePaths,
  315. name: 'file',
  316. formData: {
  317. 'user': 'test'
  318. },
  319. success: (uploadFileRes) => {
  320. let res = JSON.parse(uploadFileRes.data);
  321. if (res.code == 200) {
  322. console.log("上传成功", res)
  323. self.textParseUrlIps(config.base_url + '/' + res.data.url);
  324. } else {
  325. uni.showToast({
  326. title: res.msg,
  327. icon: "none",
  328. mask: true,
  329. duration: 2000
  330. });
  331. }
  332. },
  333. fail: err => {
  334. uni.hideLoading()
  335. },
  336. complete: () => {}
  337. });
  338. },
  339. //发送语音
  340. async textParseUrlIps(text) {
  341. let self = this;
  342. let newList = [];
  343. for (let i = 0; i < self.trumpetList.length; i++) {
  344. if (self.trumpetList[i].type) {
  345. let obj = {
  346. sn: self.trumpetList[i].deviceSn,
  347. port: self.trumpetList[i].port,
  348. deviceIp: self.trumpetList[i].deviceIp,
  349. type: "",
  350. name: "",
  351. speed: "",
  352. params: {
  353. tid: "",
  354. vol: self.trumpetList[i].deviceVol,
  355. urls: []
  356. }
  357. };
  358. newList.push(obj);
  359. }
  360. }
  361. const {
  362. data
  363. } = await textParseUrlIps(newList, text)
  364. if (data.code == 200) {
  365. uni.showToast({
  366. title: '发送成功',
  367. icon: "none",
  368. mask: true,
  369. duration: 2000
  370. });
  371. }
  372. },
  373. handleClick(row,doType){
  374. let self=this;
  375. if( doType=='detail'){//详情
  376. }
  377. },
  378. }
  379. }
  380. </script>
  381. <style lang="stylus" scoped>
  382. .earlyWarning{
  383. height:100%;
  384. display flex;
  385. padding-bottom: 30rpx;
  386. box-sizing: border-box;
  387. .header{
  388. width:750rpx;
  389. height: 100rpx;
  390. position: fixed;
  391. top: 0rpx;
  392. z-index: 100;
  393. background: #fff;
  394. .tabTitle_tow{
  395. height: 100rpx;
  396. white-space: nowrap;
  397. display: inline-flex;
  398. .tabTitle_tow_li{
  399. position: relative;
  400. width:210rpx;
  401. height: 100rpx;
  402. text-align center;
  403. padding-top: 26rpx;
  404. box-sizing: border-box;
  405. .tabTitle_tow_text{
  406. display: inline-block;
  407. font-size: 30rpx;
  408. font-family: PingFang SC;
  409. font-weight: 500;
  410. color: #333333;
  411. line-height: 46rpx;
  412. position: relative;
  413. &.on{
  414. color:#0183FA;
  415. }
  416. }
  417. .tabTitle_tow_across{
  418. width: 50rpx;
  419. height: 4rpx;
  420. background: #0183FA;
  421. border-radius: 2rpx;
  422. margin-left: 33%;
  423. display none;
  424. &.on{
  425. display block;
  426. }
  427. }
  428. }
  429. }
  430. }
  431. .video-max-box {
  432. width: 690rpx;
  433. height: 420rpx;
  434. margin: 116rpx 30rpx 20rpx;
  435. video {
  436. width: 690rpx;
  437. height: 420rpx;
  438. }
  439. }
  440. .broadcast {
  441. width: 690rpx;
  442. background: #FFFFFF;
  443. border-radius: 20rpx;
  444. padding:22rpx 30rpx 30rpx;
  445. box-sizing: border-box;
  446. margin: 20rpx 30rpx 0;
  447. .broadcast_t {
  448. font-size: 30rpx;
  449. font-family: PingFang SC;
  450. font-weight: 500;
  451. color: #333333;
  452. line-height: 30rpx;
  453. >label {
  454. font-size: 24rpx;
  455. font-family: PingFang SC;
  456. font-weight: 500;
  457. color: #999999;
  458. line-height: 30rpx;
  459. margin-left: 16rpx;
  460. }
  461. }
  462. .trumpet-max-box {
  463. display: flex;
  464. justify-content: flex-start;
  465. margin-top: 22rpx;
  466. flex-wrap: wrap;
  467. .trumpet-for-box {
  468. display: inline-block;
  469. width: auto;
  470. height: 60rpx;
  471. line-height: 60rpx;
  472. font-size: 24rpx;
  473. text-align: center;
  474. cursor: pointer;
  475. overflow: hidden;
  476. border: 1rpx solid #E0E0E0;
  477. border-radius: 10rpx;
  478. color: #E0E0E0;
  479. display: flex;
  480. justify-content: center;
  481. margin-right: 20rpx;
  482. margin-bottom: 10rpx;
  483. padding: 0 12rpx;
  484. box-sizing: border-box;
  485. >img {
  486. width: 36rpx;
  487. height: 34rpx;
  488. margin: 12rpx 20rpx 0 25rpx;
  489. }
  490. }
  491. .trumpet-color-a {
  492. border: 1px solid #0183FA;
  493. color: #0183FA;
  494. }
  495. .trumpet-color-b {
  496. border: 1px solid #CCCCCC;
  497. color: #999;
  498. }
  499. }
  500. .broadcast_m {
  501. width: 100%;
  502. .broadcast_m_t {
  503. width: 142rpx;
  504. height: 142rpx;
  505. margin: 30rpx 0 0 258rpx;
  506. position: relative;
  507. font-size: 24rpx;
  508. font-family: PingFang SC;
  509. font-weight: 500;
  510. line-height: 170rpx;
  511. text-align: center;
  512. >img {
  513. width: 142rpx;
  514. height: 142rpx;
  515. position: absolute;
  516. }
  517. >label {
  518. width: 100%;
  519. font-size: 24rpx;
  520. font-family: PingFang SC;
  521. font-weight: 500;
  522. color: #0183FA;
  523. line-height: 24rpx;
  524. display: inline-block;
  525. text-align: center;
  526. position: absolute;
  527. top: 76rpx;
  528. }
  529. /* 按下 */
  530. .press_color {
  531. color: #FFFFFF;
  532. }
  533. /* 松开 */
  534. .slip_color {
  535. color: #0183FA;
  536. }
  537. }
  538. .broadcast_m_t_back_a {
  539. background: url(@/images/icon_sskz_skfs.png);
  540. background-size: 100%;
  541. color: #FFFFFF;
  542. }
  543. .broadcast_m_t_back_b {
  544. background: url(@/images/icon_sskz_azsh.png);
  545. background-size: 100%;
  546. color: #0183FA;
  547. }
  548. .broadcast_m_b {
  549. font-size: 24rpx;
  550. font-family: PingFang SC;
  551. font-weight: 500;
  552. color: #999999;
  553. line-height: 24rpx;
  554. text-align: center;
  555. margin-top: 14rpx;
  556. }
  557. }
  558. /* 疏散按钮 */
  559. .evacuation-button-box {
  560. width: 650rpx;
  561. height: 100rpx;
  562. background: #0183FA;
  563. color: #fff;
  564. text-align center;
  565. line-height: 100rpx;
  566. font-size: 28rpx;
  567. margin: 88rpx auto 0;
  568. border-radius: 20rpx;
  569. }
  570. }
  571. }
  572. </style>