monitor.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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,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.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. type:"",
  303. name:"",
  304. speed:"",
  305. params:{
  306. tid:"",
  307. vol:"",
  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.subAddrr.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 wenchangGetStartList(){
  346. let obj = {
  347. page:'1',
  348. count:'2',
  349. deviceIds:this.itemData.hardwareNUM
  350. };
  351. const {data} = await wenchangGetStartList(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/wenchang/stream/';
  356. let url = data.data[i].result.body.data.fmp4;
  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 nanhuGetStartList(){
  371. let obj = {
  372. page:'1',
  373. count:'2',
  374. deviceIds:this.itemData.hardwareNUM
  375. };
  376. const {data} = await nanhuGetStartList(obj);
  377. if(data.code == 200){
  378. let list = [];
  379. for(let i=0;i<data.data.length;i++){
  380. let text = 'https://lab.sxitdlc.com/nanhu/stream/';
  381. let url = data.data[i].result.body.data.fmp4;
  382. url = url.split("rtp/");
  383. let newUrl = text+'rtp/'+url[1];
  384. let obj = {
  385. id:data.data[i].result.body.data.deviceID,
  386. url:newUrl,
  387. }
  388. list.push(obj)
  389. console.log("obj",obj)
  390. }
  391. this.urlList = list;
  392. }
  393. },
  394. //查询摄像头地址
  395. async getChannels(){
  396. let obj = {
  397. page:'1',
  398. count:'2',
  399. deviceIds:this.itemData.hardwareNUM
  400. };
  401. const {data} = await getChannels(obj);
  402. if(data.code == 200){
  403. let list = [];
  404. for(let i=0;i<data.data.length;i++){
  405. let obj = {
  406. id:data.data[i].result.body.data.deviceID,
  407. url:data.data[i].result.body.data.fmp4,
  408. }
  409. list.push(obj)
  410. }
  411. this.urlList = list;
  412. }
  413. },
  414. videoErrorCallback(e){
  415. console.log("播放失败",e);
  416. // uni.showToast({
  417. // title: '视频播放失败',
  418. // icon:"none",
  419. // mask:true,
  420. // duration: 3000
  421. // });
  422. },
  423. }
  424. }
  425. </script>
  426. <style lang="stylus" scoped>
  427. #monitor{
  428. padding:10rpx 20rpx;
  429. background #fff
  430. .name-box{
  431. line-height:50rpx;
  432. font-size:30rpx;
  433. color:#333;
  434. }
  435. .address-box{
  436. line-height:50rpx;
  437. font-size:28rpx;
  438. color:#666;
  439. margin-bottom:20rpx;
  440. }
  441. .max-viode-box{
  442. height: 720rpx;
  443. overflow-y scroll;
  444. video{
  445. width:710rpx;
  446. height:355rpx;
  447. }
  448. }
  449. .gb-box{
  450. margin-top:20rpx;
  451. .radio-box{
  452. display flex;
  453. font-size:26rpx;
  454. .radio-title{
  455. font-size:28rpx;
  456. margin:20rpx 0 20rpx 20rpx;
  457. line-height:40rpx;
  458. }
  459. .radio-max-button{
  460. display flex
  461. margin:0 100rpx;
  462. height:40rpx;
  463. margin-top:20rpx;
  464. .radio-button{
  465. flex:1;
  466. margin-left:75rpx;
  467. font-size:26rpx;
  468. }
  469. }
  470. }
  471. .input-box{
  472. .textarea-title{
  473. font-size:28rpx;
  474. margin:20rpx 0 20rpx 20rpx;
  475. line-height:40rpx;
  476. }
  477. textarea{
  478. width:630rpx;
  479. height:200rpx;
  480. margin:20rpx 20rpx 0;
  481. font-size:26rpx;
  482. border: 1rpx solid #E0E0E0;
  483. border-radius:10rpx;
  484. padding:20rpx;
  485. }
  486. .input-button{
  487. margin:20rpx auto;
  488. width:600rpx;
  489. height:80rpx;
  490. line-height:80rpx;
  491. color:#fff;
  492. background #007AFF;
  493. text-align center;
  494. border-radius:20rpx;
  495. }
  496. }
  497. .device-box{
  498. margin-bottom:50rpx;
  499. .device-title{
  500. font-size:28rpx;
  501. margin:20rpx 0 20rpx 20rpx;
  502. line-height:40rpx;
  503. }
  504. .device-for-max-box{
  505. margin-top :22rpx;
  506. .trumpet-for-box{
  507. display:inline-block !important;
  508. width:204rpx;
  509. height:60rpx;
  510. line-height:60rpx;
  511. font-size:24rpx;
  512. text-align center;
  513. cursor: pointer;
  514. overflow: hidden;
  515. border: 1rpx solid #E0E0E0;
  516. border-radius:10rpx;
  517. color: #E0E0E0;
  518. justify-content :center;
  519. // margin-right :30rpx;
  520. margin: 10rpx 16rpx;
  521. .trumpet-for-min-box{
  522. display flex
  523. >img{
  524. display:inline-block !important;
  525. width:36rpx;
  526. height:34rpx;
  527. margin :13rpx 20rpx 0 25rpx;
  528. }
  529. view{
  530. display:inline-block !important;
  531. }
  532. }
  533. }
  534. .trumpet-color-a{
  535. border:1px solid #0183FA;
  536. color:#0183FA;
  537. }
  538. .trumpet-color-b{
  539. border:1px solid #CCCCCC;
  540. color:#999;
  541. }
  542. }
  543. .broadcast_m{
  544. width :100%;
  545. .broadcast_m_t{
  546. width: 142rpx;
  547. height: 142rpx;
  548. margin :30rpx 0 0 258rpx;
  549. margin:30rpx auto 0;
  550. position :relative;
  551. font-size: 24rpx;
  552. font-family: PingFang SC;
  553. font-weight: 500;
  554. line-height: 170rpx;
  555. text-align center
  556. >img{
  557. width: 142rpx;
  558. height: 142rpx;
  559. position :absolute;
  560. }
  561. >label{
  562. width :100%;
  563. font-size: 24rpx;
  564. font-family: PingFang SC;
  565. font-weight: 500;
  566. color: #0183FA;
  567. line-height: 24rpx;
  568. display :inline-block;
  569. text-align :center;
  570. position :absolute;
  571. top:76rpx;
  572. }
  573. /* 按下 */
  574. .press_color{
  575. color: #FFFFFF;
  576. }
  577. /* 松开 */
  578. .slip_color{
  579. color: #0183FA;
  580. }
  581. }
  582. .broadcast_m_t_back_a{
  583. background:url(@/images/icon_sskz_skfs.png);
  584. background-size 100%
  585. color: #FFFFFF;
  586. }
  587. .broadcast_m_t_back_b{
  588. background:url(@/images/icon_sskz_azsh.png);
  589. background-size 100%
  590. color: #0183FA;
  591. }
  592. .broadcast_m_b{
  593. font-size: 24rpx;
  594. font-family: PingFang SC;
  595. font-weight: 500;
  596. color: #999999;
  597. line-height: 24rpx;
  598. text-align center;
  599. margin-top :14rpx;
  600. }
  601. }
  602. }
  603. }
  604. }
  605. </style>