videoMonitoring.vue 15 KB

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