videoMonitoring.vue 14 KB

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