monitor.vue 15 KB

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