monitor.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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">
  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. videoCover:uni.getStorageSync('videoCover'),
  65. itemData:{},
  66. urlList:[],
  67. deptId:"",
  68. text:"",
  69. type:"",
  70. items:[
  71. {
  72. name:"文字",
  73. value:"1"
  74. },
  75. {
  76. name:"音频",
  77. value:"2"
  78. },
  79. ],
  80. current:1,
  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. deviceIp:self.trumpetList[i].deviceIp,
  304. type:"",
  305. name:"",
  306. speed:"",
  307. params:{
  308. tid:"",
  309. vol:"",
  310. urls:[]
  311. }
  312. };
  313. newList.push(obj);
  314. }
  315. }
  316. const {data} = await textParseUrlIps(newList,text)
  317. if(data.code == 200){
  318. uni.showToast({
  319. title: '发送成功',
  320. icon:"none",
  321. mask:true,
  322. duration: 2000
  323. });
  324. }
  325. },
  326. radioChange(e){
  327. this.current = e.detail.value;
  328. },
  329. //获取喇叭列表
  330. async getDeviceListBySub(){
  331. let obj = {
  332. floorId:this.itemData.floorId,
  333. subId:this.itemData.id,
  334. page:1,
  335. pageSize:100
  336. }
  337. const {data} = await getDeviceListBySub(obj);
  338. if(data.code == 200){
  339. for(let i=0;i<data.data.length;i++){
  340. data.data[i].type = false;
  341. }
  342. this.$set(this,'trumpetList',data.data)
  343. // console.log(data);
  344. }
  345. },
  346. //查询摄像头地址(暨南大学)
  347. async jinanGetStartList(){
  348. let obj = {
  349. page:'1',
  350. count:'2',
  351. deviceIds:this.itemData.hardwareNUM
  352. };
  353. const {data} = await jinanGetStartList(obj);
  354. if(data.code == 200){
  355. let list = [];
  356. for(let i=0;i<data.data.length;i++){
  357. let text = 'https://lab.sxitdlc.com/jinandaxue/stream/';
  358. let url = data.data[i].result.body.data.fmp4;
  359. url = url.split("rtp/");
  360. let newUrl = text+'rtp/'+url[1];
  361. let obj = {
  362. id:data.data[i].result.body.data.deviceID,
  363. url:newUrl,
  364. }
  365. list.push(obj)
  366. console.log("obj",obj)
  367. }
  368. this.urlList = list;
  369. }
  370. },
  371. //查询摄像头地址(文昌)
  372. async wenchangGetStartList(){
  373. let obj = {
  374. page:'1',
  375. count:'2',
  376. deviceIds:this.itemData.hardwareNUM
  377. };
  378. const {data} = await wenchangGetStartList(obj);
  379. if(data.code == 200){
  380. let list = [];
  381. for(let i=0;i<data.data.length;i++){
  382. let text = 'https://lab.sxitdlc.com/wenchang/stream/';
  383. let url = data.data[i].result.body.data.fmp4;
  384. url = url.split("rtp/");
  385. let newUrl = text+'rtp/'+url[1];
  386. let obj = {
  387. id:data.data[i].result.body.data.deviceID,
  388. url:newUrl,
  389. }
  390. list.push(obj)
  391. console.log("obj",obj)
  392. }
  393. this.urlList = list;
  394. }
  395. },
  396. //查询摄像头地址(南湖)
  397. async nanhuGetStartList(){
  398. let obj = {
  399. page:'1',
  400. count:'2',
  401. deviceIds:this.itemData.hardwareNUM
  402. };
  403. const {data} = await nanhuGetStartList(obj);
  404. if(data.code == 200){
  405. let list = [];
  406. for(let i=0;i<data.data.length;i++){
  407. let text = 'https://lab.sxitdlc.com/nanhu/stream/';
  408. let url = data.data[i].result.body.data.fmp4;
  409. url = url.split("rtp/");
  410. let newUrl = text+'rtp/'+url[1];
  411. let obj = {
  412. id:data.data[i].result.body.data.deviceID,
  413. url:newUrl,
  414. }
  415. list.push(obj)
  416. console.log("obj",obj)
  417. }
  418. this.urlList = list;
  419. }
  420. },
  421. videoErrorCallback(e){
  422. console.log("播放失败",e);
  423. // uni.showToast({
  424. // title: '视频播放失败',
  425. // icon:"none",
  426. // mask:true,
  427. // duration: 3000
  428. // });
  429. },
  430. }
  431. }
  432. </script>
  433. <style lang="stylus" scoped>
  434. #monitor{
  435. padding:10rpx 20rpx;
  436. background #fff
  437. .name-box{
  438. line-height:50rpx;
  439. font-size:30rpx;
  440. color:#333;
  441. }
  442. .address-box{
  443. line-height:50rpx;
  444. font-size:28rpx;
  445. color:#666;
  446. margin-bottom:20rpx;
  447. }
  448. .max-viode-box{
  449. height: 720rpx;
  450. overflow-y scroll;
  451. video{
  452. width:710rpx;
  453. height:355rpx;
  454. }
  455. }
  456. .gb-box{
  457. margin-top:20rpx;
  458. .radio-box{
  459. display flex;
  460. font-size:26rpx;
  461. .radio-title{
  462. font-size:28rpx;
  463. margin:20rpx 0 20rpx 20rpx;
  464. line-height:40rpx;
  465. }
  466. .radio-max-button{
  467. display flex
  468. margin:0 100rpx;
  469. height:40rpx;
  470. margin-top:20rpx;
  471. .radio-button{
  472. flex:1;
  473. margin-left:75rpx;
  474. font-size:26rpx;
  475. }
  476. }
  477. }
  478. .input-box{
  479. .textarea-title{
  480. font-size:28rpx;
  481. margin:20rpx 0 20rpx 20rpx;
  482. line-height:40rpx;
  483. }
  484. textarea{
  485. width:630rpx;
  486. height:200rpx;
  487. margin:20rpx 20rpx 0;
  488. font-size:26rpx;
  489. border: 1rpx solid #E0E0E0;
  490. border-radius:10rpx;
  491. padding:20rpx;
  492. }
  493. .input-button{
  494. margin:20rpx auto;
  495. width:600rpx;
  496. height:80rpx;
  497. line-height:80rpx;
  498. color:#fff;
  499. background #007AFF;
  500. text-align center;
  501. border-radius:20rpx;
  502. }
  503. }
  504. .device-box{
  505. margin-bottom:50rpx;
  506. .device-title{
  507. font-size:28rpx;
  508. margin:20rpx 0 20rpx 20rpx;
  509. line-height:40rpx;
  510. }
  511. .device-for-max-box{
  512. margin-top :22rpx;
  513. .trumpet-for-box{
  514. display:inline-block !important;
  515. width:204rpx;
  516. height:60rpx;
  517. line-height:60rpx;
  518. font-size:24rpx;
  519. text-align center;
  520. cursor: pointer;
  521. overflow: hidden;
  522. border: 1rpx solid #E0E0E0;
  523. border-radius:10rpx;
  524. color: #E0E0E0;
  525. justify-content :center;
  526. // margin-right :30rpx;
  527. margin: 10rpx 16rpx;
  528. .trumpet-for-min-box{
  529. display flex
  530. >img{
  531. display:inline-block !important;
  532. width:36rpx;
  533. height:34rpx;
  534. margin :13rpx 20rpx 0 25rpx;
  535. }
  536. view{
  537. display:inline-block !important;
  538. }
  539. }
  540. }
  541. .trumpet-color-a{
  542. border:1px solid #0183FA;
  543. color:#0183FA;
  544. }
  545. .trumpet-color-b{
  546. border:1px solid #CCCCCC;
  547. color:#999;
  548. }
  549. }
  550. .broadcast_m{
  551. width :100%;
  552. .broadcast_m_t{
  553. width: 142rpx;
  554. height: 142rpx;
  555. margin :30rpx 0 0 258rpx;
  556. margin:30rpx auto 0;
  557. position :relative;
  558. font-size: 24rpx;
  559. font-family: PingFang SC;
  560. font-weight: 500;
  561. line-height: 170rpx;
  562. text-align center
  563. >img{
  564. width: 142rpx;
  565. height: 142rpx;
  566. position :absolute;
  567. }
  568. >label{
  569. width :100%;
  570. font-size: 24rpx;
  571. font-family: PingFang SC;
  572. font-weight: 500;
  573. color: #0183FA;
  574. line-height: 24rpx;
  575. display :inline-block;
  576. text-align :center;
  577. position :absolute;
  578. top:76rpx;
  579. }
  580. /* 按下 */
  581. .press_color{
  582. color: #FFFFFF;
  583. }
  584. /* 松开 */
  585. .slip_color{
  586. color: #0183FA;
  587. }
  588. }
  589. .broadcast_m_t_back_a{
  590. background:url(@/images/icon_sskz_skfs.png);
  591. background-size 100%
  592. color: #FFFFFF;
  593. }
  594. .broadcast_m_t_back_b{
  595. background:url(@/images/icon_sskz_azsh.png);
  596. background-size 100%
  597. color: #0183FA;
  598. }
  599. .broadcast_m_b{
  600. font-size: 24rpx;
  601. font-family: PingFang SC;
  602. font-weight: 500;
  603. color: #999999;
  604. line-height: 24rpx;
  605. text-align center;
  606. margin-top :14rpx;
  607. }
  608. }
  609. }
  610. }
  611. }
  612. </style>