videoMonitoring.vue 14 KB

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