monitor.vue 15 KB

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