monitor.vue 16 KB

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