monitor.vue 16 KB

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