monitor.vue 17 KB

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