monitor.vue 16 KB

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