monitor.vue 15 KB

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