monitor.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. let _this=this;
  162. if(_this.trumpetList[index].type==true){
  163. _this.trumpetList.forEach(function(item2) {
  164. if(item2.deviceSn==_this.trumpetList[index].deviceSn){
  165. item2.type=true
  166. }else{
  167. item2.type=false
  168. }
  169. })
  170. }
  171. },
  172. //录制
  173. recordButton(e){
  174. console.log("按下")
  175. let self = this;
  176. let num = 0;
  177. for(let i=0;i<self.trumpetList.length;i++){
  178. if(self.trumpetList[i].type){
  179. num++
  180. }
  181. }
  182. if(num == 0){
  183. uni.showToast({
  184. title: '请选择喇叭',
  185. icon:"none",
  186. mask:true,
  187. duration: 2000
  188. });
  189. return
  190. }
  191. this.liveType=true;
  192. console.log('录制',e)
  193. this.startPoint = e.touches[0];//记录长按时开始点信息,后面用于计算上划取消时手指滑动的距离。
  194. const options = {
  195. duration: 10000,
  196. sampleRate: 16000,
  197. numberOfChannels: 1,
  198. encodeBitRate: 48000,
  199. format: 'mp3',
  200. frameSize: 50
  201. }
  202. this.recorderManager.start(options);//开始录音
  203. this.recorderManager.onStart(() => {
  204. console.log('recorder start')
  205. })
  206. this.recorderManager.onError((res) => {
  207. console.log(res);
  208. })
  209. wx.showToast({
  210. title: "正在录音,上划取消发送",
  211. icon: "none",
  212. duration: 60000//先定义个60秒,后面可以手动调用wx.hideToast()隐藏
  213. });
  214. this.sendLock = false;//长按时是不上锁的。
  215. },
  216. //取消
  217. cancelButton(e){
  218. console.log("移动")
  219. let self = this;
  220. let num = 0;
  221. for(let i=0;i<self.trumpetList.length;i++){
  222. if(self.trumpetList[i].type){
  223. num++
  224. }
  225. }
  226. if(num == 0){
  227. return
  228. }
  229. this.liveType=false;
  230. console.log('取消',e)
  231. let moveLenght = e.touches[e.touches.length - 1].clientY - this.startPoint.clientY; //移动距离
  232. if (Math.abs(moveLenght) > 50) {
  233. wx.showToast({
  234. title: "松开手指,取消发送",
  235. icon: "none",
  236. duration: 60000
  237. });
  238. this.sendLock = true;//触发了上滑取消发送,上锁
  239. } else {
  240. wx.showToast({
  241. title: "正在录音,上划取消发送",
  242. icon: "none",
  243. duration: 60000
  244. });
  245. this.sendLock = false;//上划距离不足,依然可以发送,不上锁
  246. }
  247. },
  248. //发送
  249. sendButton(e){
  250. console.log("松开")
  251. let self = this;
  252. let num = 0;
  253. for(let i=0;i<self.trumpetList.length;i++){
  254. if(self.trumpetList[i].type){
  255. num++
  256. }
  257. }
  258. if(num == 0){
  259. return
  260. }
  261. this.liveType=false;
  262. console.log('发送',e)
  263. wx.hideToast();//结束录音、隐藏Toast提示框
  264. this.recorderManager.stop();//结束录音
  265. this.recorderManager.onStop((res) => {
  266. if(!this.sendLock){
  267. console.log('1', this.recorderManager)
  268. this.uploadImg(res.tempFilePath);
  269. }
  270. console.log('停止录音', res.tempFilePath)
  271. console.log("sendLock",this.sendLock);
  272. })
  273. },
  274. //上传MP3
  275. async uploadImg(tempFilePaths){
  276. var self = this;
  277. uni.uploadFile({
  278. url: config.base_url+'/file/upload', //仅为示例,非真实的接口地址
  279. header:{'Authorization':uni.getStorageSync('token')},
  280. filePath: tempFilePaths,
  281. name: 'file',
  282. formData: {
  283. 'user': 'test'
  284. },
  285. success: (uploadFileRes) => {
  286. let res = JSON.parse(uploadFileRes.data);
  287. if(res.code == 200){
  288. console.log("上传成功",res)
  289. self.textParseUrlIps(config.base_url+ '/' +res.data.url);
  290. // self.newData.imgList.push(res.data.url);
  291. }else{
  292. uni.showToast({
  293. title: res.msg,
  294. icon:"none",
  295. mask:true,
  296. duration: 2000
  297. });
  298. }
  299. },
  300. fail: err => {
  301. uni.hideLoading()
  302. },
  303. complete: () => {
  304. }
  305. });
  306. },
  307. //发送语音
  308. async textParseUrlIps(text){
  309. let self = this;
  310. let newList = [];
  311. for(let i=0;i<self.trumpetList.length;i++){
  312. if(self.trumpetList[i].type){
  313. let obj = {
  314. sn:self.trumpetList[i].deviceSn,
  315. port:self.trumpetList[i].port,
  316. deviceIp:self.trumpetList[i].deviceIp,
  317. type:"",
  318. name:"",
  319. speed:"",
  320. params:{
  321. tid:"",
  322. vol:self.trumpetList[i].deviceVol,
  323. urls:[]
  324. }
  325. };
  326. newList.push(obj);
  327. }
  328. }
  329. const {data} = await textParseUrlIps(newList,text)
  330. if(data.code == 200){
  331. uni.showToast({
  332. title: '发送成功',
  333. icon:"none",
  334. mask:true,
  335. duration: 2000
  336. });
  337. }
  338. },
  339. radioChange(e){
  340. this.current = e.detail.value;
  341. },
  342. //获取喇叭列表
  343. async getDeviceListBySub(){
  344. let obj = {
  345. floorId:5,
  346. subId:this.itemData.id,
  347. page:1,
  348. pageSize:100
  349. }
  350. const {data} = await getDeviceListBySub(obj);
  351. if(data.code == 200){
  352. for(let i=0;i<data.data.length;i++){
  353. data.data[i].type = false;
  354. }
  355. this.$set(this,'trumpetList',data.data)
  356. // console.log(data);
  357. }
  358. },
  359. //查询摄像头地址(矿大文昌大学)
  360. async GetVideoList(){
  361. let obj = {
  362. page:'1',
  363. count:'10',
  364. deviceIds:this.itemData.hardwareNUM
  365. };
  366. const {data} = await wenchangGetStartList(obj);
  367. if(data.code == 200){
  368. let list = [];
  369. for(let i=0;i<data.data.length;i++){
  370. let text = 'https://lab.sxitdlc.com/wenchang/stream/';
  371. let url = data.data[i].result.body.data.hls;
  372. url = url.split("rtp/");
  373. let newUrl = text+'rtp/'+url[1];
  374. let obj = {
  375. id:data.data[i].result.body.data.deviceID,
  376. url:newUrl,
  377. }
  378. list.push(obj)
  379. console.log("obj",obj)
  380. }
  381. this.urlList = list;
  382. }
  383. },
  384. videoErrorCallback(e){
  385. console.log("播放失败",e);
  386. // uni.showToast({
  387. // title: '视频播放失败',
  388. // icon:"none",
  389. // mask:true,
  390. // duration: 3000
  391. // });
  392. },
  393. }
  394. }
  395. </script>
  396. <style lang="stylus" scoped>
  397. #monitor{
  398. padding:10rpx 20rpx;
  399. background #fff
  400. .name-box{
  401. line-height:50rpx;
  402. font-size:30rpx;
  403. color:#333;
  404. }
  405. .address-box{
  406. line-height:50rpx;
  407. font-size:28rpx;
  408. color:#666;
  409. margin-bottom:20rpx;
  410. }
  411. .max-viode-box{
  412. height: 720rpx;
  413. overflow-y scroll;
  414. video{
  415. width:710rpx;
  416. height:355rpx;
  417. }
  418. }
  419. .gb-box{
  420. margin-top:20rpx;
  421. .radio-box{
  422. display flex;
  423. font-size:26rpx;
  424. .radio-title{
  425. font-size:28rpx;
  426. margin:20rpx 0 20rpx 20rpx;
  427. line-height:40rpx;
  428. }
  429. .radio-max-button{
  430. display flex
  431. margin:0 100rpx;
  432. height:40rpx;
  433. margin-top:20rpx;
  434. .radio-button{
  435. flex:1;
  436. margin-left:75rpx;
  437. font-size:26rpx;
  438. }
  439. }
  440. }
  441. .input-box{
  442. .textarea-title{
  443. font-size:28rpx;
  444. margin:20rpx 0 20rpx 20rpx;
  445. line-height:40rpx;
  446. }
  447. textarea{
  448. width:630rpx;
  449. height:200rpx;
  450. margin:20rpx 20rpx 0;
  451. font-size:26rpx;
  452. border: 1rpx solid #E0E0E0;
  453. border-radius:10rpx;
  454. padding:20rpx;
  455. }
  456. .input-button{
  457. margin:20rpx auto;
  458. width:600rpx;
  459. height:80rpx;
  460. line-height:80rpx;
  461. color:#fff;
  462. background #007AFF;
  463. text-align center;
  464. border-radius:20rpx;
  465. }
  466. }
  467. .device-box{
  468. margin-bottom:50rpx;
  469. .device-title{
  470. font-size:28rpx;
  471. margin:20rpx 0 20rpx 20rpx;
  472. line-height:40rpx;
  473. }
  474. .device-for-max-box{
  475. margin-top :22rpx;
  476. .trumpet-for-box{
  477. display:inline-block !important;
  478. width:204rpx;
  479. height:60rpx;
  480. line-height:60rpx;
  481. font-size:24rpx;
  482. text-align center;
  483. cursor: pointer;
  484. overflow: hidden;
  485. border: 1rpx solid #E0E0E0;
  486. border-radius:10rpx;
  487. color: #E0E0E0;
  488. justify-content :center;
  489. // margin-right :30rpx;
  490. margin: 10rpx 16rpx;
  491. .trumpet-for-min-box{
  492. display flex
  493. >img{
  494. display:inline-block !important;
  495. width:36rpx;
  496. height:34rpx;
  497. margin :13rpx 20rpx 0 25rpx;
  498. }
  499. view{
  500. display:inline-block !important;
  501. }
  502. }
  503. }
  504. .trumpet-color-a{
  505. border:1px solid #0183FA;
  506. color:#0183FA;
  507. }
  508. .trumpet-color-b{
  509. border:1px solid #CCCCCC;
  510. color:#999;
  511. }
  512. }
  513. .broadcast_m{
  514. width :100%;
  515. .broadcast_m_t{
  516. width: 142rpx;
  517. height: 142rpx;
  518. margin :30rpx 0 0 258rpx;
  519. margin:30rpx auto 0;
  520. position :relative;
  521. font-size: 24rpx;
  522. font-family: PingFang SC;
  523. font-weight: 500;
  524. line-height: 170rpx;
  525. text-align center
  526. >img{
  527. width: 142rpx;
  528. height: 142rpx;
  529. position :absolute;
  530. }
  531. >label{
  532. width :100%;
  533. font-size: 24rpx;
  534. font-family: PingFang SC;
  535. font-weight: 500;
  536. color: #0183FA;
  537. line-height: 24rpx;
  538. display :inline-block;
  539. text-align :center;
  540. position :absolute;
  541. top:76rpx;
  542. }
  543. /* 按下 */
  544. .press_color{
  545. color: #FFFFFF;
  546. }
  547. /* 松开 */
  548. .slip_color{
  549. color: #0183FA;
  550. }
  551. }
  552. .broadcast_m_t_back_a{
  553. background:url(@/images/icon_sskz_skfs.png);
  554. background-size 100%
  555. color: #FFFFFF;
  556. }
  557. .broadcast_m_t_back_b{
  558. background:url(@/images/icon_sskz_azsh.png);
  559. background-size 100%
  560. color: #0183FA;
  561. }
  562. .broadcast_m_b{
  563. font-size: 24rpx;
  564. font-family: PingFang SC;
  565. font-weight: 500;
  566. color: #999999;
  567. line-height: 24rpx;
  568. text-align center;
  569. margin-top :14rpx;
  570. }
  571. }
  572. }
  573. .null-device-box{
  574. text-align: center;
  575. color:#999;
  576. line-height:100rpx;
  577. }
  578. }
  579. }
  580. </style>