monitor.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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. 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. // if(this.deptId == 102){
  95. // this.wenchangGetStartList();
  96. // }else if(this.deptId == 113){
  97. // this.nanhuGetStartList();
  98. // }
  99. this.jinanGetStartList();
  100. this.getDeviceListBySub();
  101. // this.getChannels();
  102. },
  103. onShow(){
  104. // wx.getSystemInfo({
  105. // success (res) {
  106. // console.log("res",res)
  107. // }
  108. // })
  109. },
  110. methods: {
  111. voiceButton(){
  112. let self = this;
  113. if(!this.text){
  114. uni.showToast({
  115. title: '请输入广播内容',
  116. icon:"none",
  117. mask:true,
  118. duration: 2000
  119. });
  120. return
  121. }
  122. uni.showModal({
  123. // title: '确认要退出吗?',
  124. content: '确认播放吗?',
  125. cancelColor:"#999",
  126. confirmColor:"#0183FA",
  127. success: function (res) {
  128. if (res.confirm) {
  129. self.voice();
  130. console.log('用户点击确定');
  131. } else if (res.cancel) {
  132. console.log('用户点击取消');
  133. }
  134. }
  135. });
  136. },
  137. //播放
  138. async voice(){
  139. let obj = {
  140. txt:this.text,
  141. type:'1'
  142. };
  143. const {data} = await voice(this.itemData.id,obj);
  144. if(data.code == 200){
  145. this.text = "";
  146. uni.showToast({
  147. title: '播放成功',
  148. icon:"none",
  149. mask:true,
  150. duration: 2000
  151. });
  152. }
  153. },
  154. //点击选择喇叭
  155. trumpetClick(index){
  156. this.trumpetList[index].type = !this.trumpetList[index].type
  157. },
  158. //录制
  159. recordButton(e){
  160. console.log("按下")
  161. let self = this;
  162. let num = 0;
  163. for(let i=0;i<self.trumpetList.length;i++){
  164. if(self.trumpetList[i].type){
  165. num++
  166. }
  167. }
  168. if(num == 0){
  169. uni.showToast({
  170. title: '请选择喇叭',
  171. icon:"none",
  172. mask:true,
  173. duration: 2000
  174. });
  175. return
  176. }
  177. this.liveType=true;
  178. console.log('录制',e)
  179. this.startPoint = e.touches[0];//记录长按时开始点信息,后面用于计算上划取消时手指滑动的距离。
  180. const options = {
  181. duration: 10000,
  182. sampleRate: 16000,
  183. numberOfChannels: 1,
  184. encodeBitRate: 48000,
  185. format: 'mp3',
  186. frameSize: 50
  187. }
  188. this.recorderManager.start(options);//开始录音
  189. this.recorderManager.onStart(() => {
  190. console.log('recorder start')
  191. })
  192. this.recorderManager.onError((res) => {
  193. console.log(res);
  194. })
  195. wx.showToast({
  196. title: "正在录音,上划取消发送",
  197. icon: "none",
  198. duration: 60000//先定义个60秒,后面可以手动调用wx.hideToast()隐藏
  199. });
  200. this.sendLock = false;//长按时是不上锁的。
  201. },
  202. //取消
  203. cancelButton(e){
  204. console.log("移动")
  205. let self = this;
  206. let num = 0;
  207. for(let i=0;i<self.trumpetList.length;i++){
  208. if(self.trumpetList[i].type){
  209. num++
  210. }
  211. }
  212. if(num == 0){
  213. return
  214. }
  215. this.liveType=false;
  216. console.log('取消',e)
  217. let moveLenght = e.touches[e.touches.length - 1].clientY - this.startPoint.clientY; //移动距离
  218. if (Math.abs(moveLenght) > 50) {
  219. wx.showToast({
  220. title: "松开手指,取消发送",
  221. icon: "none",
  222. duration: 60000
  223. });
  224. this.sendLock = true;//触发了上滑取消发送,上锁
  225. } else {
  226. wx.showToast({
  227. title: "正在录音,上划取消发送",
  228. icon: "none",
  229. duration: 60000
  230. });
  231. this.sendLock = false;//上划距离不足,依然可以发送,不上锁
  232. }
  233. },
  234. //发送
  235. sendButton(e){
  236. console.log("松开")
  237. let self = this;
  238. let num = 0;
  239. for(let i=0;i<self.trumpetList.length;i++){
  240. if(self.trumpetList[i].type){
  241. num++
  242. }
  243. }
  244. if(num == 0){
  245. return
  246. }
  247. this.liveType=false;
  248. console.log('发送',e)
  249. wx.hideToast();//结束录音、隐藏Toast提示框
  250. this.recorderManager.stop();//结束录音
  251. this.recorderManager.onStop((res) => {
  252. if(!this.sendLock){
  253. console.log('1', this.recorderManager)
  254. this.uploadImg(res.tempFilePath);
  255. }
  256. console.log('停止录音', res.tempFilePath)
  257. console.log("sendLock",this.sendLock);
  258. })
  259. },
  260. //上传MP3
  261. async uploadImg(tempFilePaths){
  262. var self = this;
  263. uni.uploadFile({
  264. url: config.base_url+'/file/upload', //仅为示例,非真实的接口地址
  265. header:{'Authorization':uni.getStorageSync('token')},
  266. filePath: tempFilePaths,
  267. name: 'file',
  268. formData: {
  269. 'user': 'test'
  270. },
  271. success: (uploadFileRes) => {
  272. let res = JSON.parse(uploadFileRes.data);
  273. if(res.code == 200){
  274. console.log("上传成功",res)
  275. self.textParseUrlIps(config.base_url+ '/' +res.data.url);
  276. // self.newData.imgList.push(res.data.url);
  277. }else{
  278. uni.showToast({
  279. title: res.msg,
  280. icon:"none",
  281. mask:true,
  282. duration: 2000
  283. });
  284. }
  285. },
  286. fail: err => {
  287. uni.hideLoading()
  288. },
  289. complete: () => {
  290. }
  291. });
  292. },
  293. //发送语音
  294. async textParseUrlIps(text){
  295. let self = this;
  296. let newList = [];
  297. for(let i=0;i<self.trumpetList.length;i++){
  298. if(self.trumpetList[i].type){
  299. let obj = {
  300. sn:self.trumpetList[i].deviceSn,
  301. port:self.trumpetList[i].port,
  302. deviceIp:self.trumpetList[i].deviceIp,
  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.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>