南昌市物联网技防平台-前端
shuishen
2021-03-20 8c372e643f381f0bf17b976eddf694d9cf7aef33
src/views/realTimePolice/real.vue
@@ -2,7 +2,7 @@
 * @Author: Morpheus
 * @Date: 2021-03-17 15:21:33
 * @Last Modified by: Morpheus
 * @Last Modified time: 2021-03-20 11:38:56
 * @Last Modified time: 2021-03-20 16:47:06
 */
<template>
  <basic-container>
@@ -129,6 +129,7 @@
      :visible.sync="dialogTableVisible"
      :append-to-body="true"
      :close-on-click-modal="false"
      @opened="videoConversationReal = true"
      @close="(videoConversationReal = false), (oldVideoSatart = false)"
    >
      <el-dialog
@@ -144,7 +145,7 @@
      >
        <video
          src=""
          id="video_conversation"
          id="real_video_conversation"
          style="width: 100%; height: 100%; object-fit: fill"
          controls
        ></video>
@@ -166,7 +167,7 @@
          muted="muted"
          autoplay="autoplay"
          loop
          id="old_video"
          id="real_old_video"
          style="width: 100%; height: 100%; object-fit: fill"
          controls
        ></video>
@@ -260,7 +261,7 @@
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="警情类别">
            <el-form-item label="警情类型">
              <el-input
                disabled="true"
                v-model="form.waringType"
@@ -288,11 +289,20 @@
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col span="12">
          <!-- <el-col span="12">
            <el-form-item label="接警时间">
              <el-input
                disabled="true"
                v-model="form.jjTime"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-col> -->
          <el-col span="12">
            <el-form-item label="报警内容">
              <el-input
                disabled="true"
                v-model="form.content"
                autocomplete="off"
              ></el-input>
            </el-form-item>
@@ -315,10 +325,10 @@
                :class="{ active: isActive }"
                type="success"
                @click.stop="
                  (videoConversationReal = !videoConversationReal),
                    (oldVideoSatart = false),
                    aKeyToCall(form)
                  (videoConversationReal = true), (oldVideoSatart = false)
                "
                @mousedown.native="aKeyToCall"
                @mouseup.native="aKeyStopCall"
                >视频通话
              </el-button>
              <el-button
@@ -333,15 +343,6 @@
        </el-row>
        <el-row>
          <el-col span="12">
            <el-form-item label="报警内容">
              <el-input
                disabled="true"
                v-model="form.content"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col span="12">
            <el-form-item label="备注">
              <el-input v-model="form.bz" autocomplete="off"></el-input>
@@ -488,10 +489,6 @@
              },
            ],
          },
          // {
          //   label: "报警内容",
          //   prop: "content",
          // },
          {
            label: "主要负责人",
            prop: "oneContacts",
@@ -671,8 +668,6 @@
      peopleList: [],
      peopleName: "",
      peoplePhone: "",
      aKeyToCallFlag: false,
      aKeyToCallTime: null,
    };
  },
  computed: {
@@ -695,6 +690,7 @@
  },
  created() {
    this.dateTime = this.getDate();
    Recorder.getPermission().then(() => {});
    this.recorder = new Recorder({
      sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
@@ -820,9 +816,33 @@
        this.$router.query != null &&
        this.$router.query != ""
      ) {
        params = {
          alarmType: this.$router.query.alarmType,
        };
        if (this.$router.query.status) {
          this.activeClass = this.$router.query.status;
          this.page.currentPage = 1;
          if (this.$router.query.status == 0) {
            params = {
              waringType: this.$router.query.waringType,
              beginTime: this.dateTime.day.beginTime,
              endTime: this.dateTime.day.endTime,
            };
          } else if (this.$router.query.status == 1) {
            params = {
              waringType: this.$router.query.waringType,
              beginTime: this.dateTime.week.beginTime,
              endTime: this.dateTime.week.endTime,
            };
          } else if (this.$router.query.status == 2) {
            params = {
              waringType: this.$router.query.waringType,
              beginTime: this.dateTime.month.beginTime,
              endTime: this.dateTime.month.endTime,
            };
          }
        } else {
          params = {
            waringType: this.$router.query.waringType,
          };
        }
      }
      if (releaseTimeRange) {
@@ -1003,13 +1023,17 @@
      this.onLoad(this.page, params);
    },
    rowStyle({ row, column, rowIndex }) {
      if (row.jtype == "1") {
      if (row.jtype == "0") {
        return {
          color: "#ff2727",
        };
      } else if (row.jtype == "1") {
        return {
          color: "#15a2fe",
        };
      } else {
        return {
          color: "#ff2727",
          color: "#000000",
        };
      }
    },
@@ -1054,7 +1078,6 @@
      this.peopleName = row.oneContacts;
      this.peoplePhone = row.onePhone;
      this.dialogTableVisible = true;
      this.videoConversationReal = true;
    },
    updateJtyep(row, jtype, t) {
      var that = this;
@@ -1069,8 +1092,8 @@
              jtype: jtype,
              rid: row.alarmId,
              bz: row.bz,
              snumber: row.alarmPeople,
              sname: row.alarmId,
              snumber: row.alarmId,
              sname: row.alarmPeople,
              zc: t,
              zctime: that.getDate().current,
            },
@@ -1078,8 +1101,7 @@
        )
        .then(function () {
          that.onLoad(that.page, that.query);
          that.videoConversationReal = false;
          that.oldVideoSatart = false;
          that.dialogTableVisible = false;
        });
    },
    beginTimeOrEndTime(time) {
@@ -1143,7 +1165,6 @@
    },
    // 视频通话打开关闭事件
    openRealVideoBox() {
      var that = this;
      var newAxios = axios.create({
        baseURL: "https://web.byisf.com:18000",
        withCredentials: false,
@@ -1172,9 +1193,7 @@
              this.videoSource = result.data.data.m3u8;
              if (Hls.isSupported()) {
                var dom = document.getElementById("video_conversation");
                // if (dom.volume) dom.volume = 1.0;
                var dom = document.getElementById("real_video_conversation");
                this.hls = new Hls();
@@ -1189,35 +1208,10 @@
                });
              }
            });
          //   newAxios
          //     .post(
          //       "/api_control",
          //       {},
          //       {
          //         params: {
          //           param: JSON.stringify({
          //             PktType: "RemotePlayback",
          //             accessToken: res.data.data.accessToken,
          //             deviceCode: "001231409472",
          //             startTime: "20210130150000",
          //             endTime: "20210130160000",
          //             chl: data.serialNumber
          //           })
          //         }
          //       }
          //     )
          //     .then(result => {
          //       this.videoConversationReal = true;
          //       this.videoSource = result.data.data.m3u8;
          //     });
        });
    },
    closeRealVideoBox() {
      var dom = document.getElementById("video_conversation");
      var dom = document.getElementById("real_video_conversation");
      if (dom.getAttribute("src") != "") {
        dom.pause();
@@ -1230,16 +1224,41 @@
    // 历史视频打开关闭事件
    openOldVideoBox() {
      var dom = document.getElementById("old_video");
      var dom = document.getElementById("real_old_video");
      dom.currentTime = 0;
      dom.play();
    },
    closeOldVideoBox() {
      var dom = document.getElementById("old_video");
      var dom = document.getElementById("real_old_video");
      dom.pause();
    },
    aKeyToCall(e, form) {
    aKeyToCall() {
      var that = this;
      if (this.recorder == null) {
        this.recorder = new Recorder({
          sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
          sampleRate: 8000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
          numChannels: 1, // 声道,支持 1 或 2, 默认是1
          // compiling: false,(0.x版本中生效,1.x增加中)  // 是否边录边转换,默认是false
        });
      }
      this.isActive = true;
      // 一键呼叫相关函数
      that.recorder.start().then(
        () => {
          // 开始录音
        },
        (error) => {
          // 出错了
          console.log(`${error.name} : ${error.message}`);
        }
      );
    },
    // 序列号后期待修改
    aKeyStopCall() {
      var newCallAxios = axios.create({
        baseURL: "https://web.byisf.com:18000",
        withCredentials: false,
@@ -1248,195 +1267,44 @@
        },
      });
      var that = this;
      that.isActive = false;
      if (that.recorder == null) {
        that.recorder = new Recorder({
          sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
          sampleRate: 8000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
          numChannels: 1, // 声道,支持 1 或 2, 默认是1
          // compiling: false,(0.x版本中生效,1.x增加中)  // 是否边录边转换,默认是false
        });
      }
      if (this.aKeyToCallFlag == false) {
        this.aKeyToCallFlag = true;
        videoPhone();
        Recorder.getPermission().then(() => {
          // 一键呼叫相关函数
          that.aKeyToCallTime = setInterval(() => {
            that.recorder.start().then(
              () => {
                // 开始录音
                setTimeout(() => {
                  newCallAxios
                    .post(
                      `/api_control`,
                      {},
                      {
                        params: {
                          param: { PktType: "GetAccessToken" },
                        },
                      }
                    )
                    .then((result) => {
                      var formData = new FormData();
                      var blob = that.recorder.getPCMBlob(); //获取pcm格式音频数据
                      //此处获取到blob对象后需要设置fileName满足当前项目上传需求,其它项目可直接传把blob作为file塞入formData
                      var newbolb = new Blob([blob], { type: "audio/pcm" });
                      var fileOfBlob = new File(
                        [newbolb],
                        new Date().getTime() + ".pcm"
                      );
                      formData.append("file", fileOfBlob);
                      // var dom = document.getElementById("real_audio");
                      // dom.setAttribute("src", URL.createObjectURL(blob));
                      // this.recorder.play();
                      newCallAxios
                        .post(`/api_control`, blob, {
                          params: {
                            param: {
                              PktType: "Talk",
                              accessToken: result.data.data.accessToken,
                              // deviceCode: form.channelNumber,
                              deviceCode: "001241945990",
                            },
                          },
                        })
                        .then((result) => {});
                    });
                }, 5000);
              },
              (error) => {
                // 出错了
                console.log(`${error.name} : ${error.message}`);
              }
            );
          }, 6000);
        });
      } else {
        this.aKeyToCallFlag = false;
        that.recorder.destroy().then(function () {
          that.recorder = null;
        });
        window.clearInterval(that.aKeyToCallTime);
      }
      function videoPhone() {
        that.recorder.start().then(
          () => {
            // 开始录音
            setTimeout(() => {
              newCallAxios
                .post(
                  `/api_control`,
                  {},
                  {
                    params: {
                      param: { PktType: "GetAccessToken" },
                    },
                  }
                )
                .then((result) => {
                  var formData = new FormData();
                  var blob = that.recorder.getPCMBlob(); //获取pcm格式音频数据
                  //此处获取到blob对象后需要设置fileName满足当前项目上传需求,其它项目可直接传把blob作为file塞入formData
                  var newbolb = new Blob([blob], { type: "audio/pcm" });
                  var fileOfBlob = new File(
                    [newbolb],
                    new Date().getTime() + ".pcm"
                  );
                  formData.append("file", fileOfBlob);
                  // var dom = document.getElementById("real_audio");
                  // dom.setAttribute("src", URL.createObjectURL(blob));
                  // this.recorder.play();
                  newCallAxios
                    .post(`/api_control`, blob, {
                      params: {
                        param: {
                          PktType: "Talk",
                          accessToken: result.data.data.accessToken,
                          // deviceCode: form.channelNumber,
                          deviceCode: "001241945990",
                        },
                      },
                    })
                    .then((result) => {});
                });
            }, 5000);
          },
          (error) => {
            // 出错了
            console.log(`${error.name} : ${error.message}`);
      newCallAxios
        .post(
          `/api_control`,
          {},
          {
            params: {
              param: { PktType: "GetAccessToken" },
            },
          }
        );
      }
    },
    aKeyToCall111(e, form) {
      var newCallAxios = axios.create({
        baseURL: "https://web.byisf.com:18000",
        withCredentials: false,
        headers: {
          "Content-Type": "application/json;",
        },
      });
      setInterval(() => {
        Recorder.getPermission().then(() => {
          this.recorder.start().then(() => {
            // 开始录音
            newCallAxios
              .post(
                `/api_control`,
                {},
                {
                  params: {
                    param: { PktType: "GetAccessToken" },
                  },
                }
              )
              .then((result) => {
                var formData = new FormData();
                var blob = this.recorder.getPCMBlob(); //获取pcm格式音频数据
                //此处获取到blob对象后需要设置fileName满足当前项目上传需求,其它项目可直接传把blob作为file塞入formData
                var newbolb = new Blob([blob], { type: "audio/pcm" });
                var fileOfBlob = new File(
                  [newbolb],
                  new Date().getTime() + ".pcm"
                );
                formData.append("file", fileOfBlob);
                // var dom = document.getElementById("real_audio");
                // dom.setAttribute("src", URL.createObjectURL(blob));
                // this.recorder.play();
                newCallAxios
                  .post(`/api_control`, blob, {
                    params: {
                      param: {
                        PktType: "Talk",
                        accessToken: result.data.data.accessToken,
                        // deviceCode: form.channelNumber,
                        deviceCode: "001241945990",
                      },
                    },
                  })
                  .then((result) => {});
        )
        .then((result) => {
          var formData = new FormData();
          var blob = that.recorder.getPCMBlob(); //获取pcm格式音频数据
          //此处获取到blob对象后需要设置fileName满足当前项目上传需求,其它项目可直接传把blob作为file塞入formData
          var newbolb = new Blob([blob], { type: "audio/pcm" });
          var fileOfBlob = new File([newbolb], new Date().getTime() + ".pcm");
          formData.append("file", fileOfBlob);
          newCallAxios
            .post(`/api_control`, blob, {
              params: {
                param: {
                  PktType: "Talk",
                  accessToken: result.data.data.accessToken,
                  // deviceCode: form.channelNumber,
                  deviceCode: "001241945990",
                },
              },
            })
            .then(() => {
              that.recorder.destroy().then(function () {
                that.recorder = null;
              });
          });
            });
        });
        // 一键呼叫相关函数
      }, 200000);
    },
    peopleOrPhone(e) {
      this.peopleList.forEach((item) => {
        if (item.label == e) {