videoMonitoring.vue 13 KB

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