videoMonitoring.vue 13 KB

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