monitor.vue 14 KB

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