monitor.vue 15 KB

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