shuishen
2021-04-08 a4e06ccd3cd976fbe4eef99e188d42ec9f3ad054
src/page/index/logo.vue
@@ -20,7 +20,7 @@
        :append-to-body="true"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        :show-close="false"
        @opened="onDialogTableVisible"
        @close="closeDialog"
      >
        <el-form
@@ -52,31 +52,50 @@
          <el-row>
            <el-col span="12">
              <el-form-item label="负责人">
                <el-input
                  disabled="true"
                  v-model="form.galarmPeople"
                  autocomplete="off"
                ></el-input>
                <el-select
                  v-model="peopleName"
                  placeholder="请选择"
                  @change="peopleOrPhone"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in peopleList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.label"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col span="12">
              <el-form-item label="负责人电话">
                <el-input
                  disabled="true"
                  v-model="form.phoneNumber"
                  v-model="peoplePhone"
                  autocomplete="off"
                  style="width: calc(100% - 110px)"
                ></el-input>
                <el-button
                  type="success"
                  style="
                    margin-left: 10px;
                    padding: 0px 8px;
                    width: 100px;
                    height: 28px;
                    vertical-align: top;
                  "
                >
                  <i class="el-icon-phone-outline"></i>
                  联系负责人
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col span="12">
              <el-form-item label="行政区">
                <el-input
                  disabled="true"
                  v-model="form.district"
                  autocomplete="off"
                ></el-input>
              <el-form-item label="省份" class="cityClassParams">
                <avue-form :option="itemOption" v-model="form"></avue-form>
              </el-form-item>
            </el-col>
            <el-col span="12">
@@ -91,7 +110,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"
@@ -120,10 +139,10 @@
              </el-form-item>
            </el-col>
            <el-col span="12">
              <el-form-item label="接警时间">
              <el-form-item label="报警内容">
                <el-input
                  disabled="true"
                  v-model="form.jjTime"
                  v-model="form.content"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
@@ -140,49 +159,60 @@
              </el-form-item>
            </el-col>
            <el-col span="12">
              <el-form-item label="监控视频">
                <el-button
                  :class="{ active: isActive }"
                  type="success"
                  @click.stop="
                    (videoConversationReal = true), (oldVideoSatart = false)
                  "
                  @mousedown.native="aKeyToCall"
                  @mouseup.native="aKeyStopCall"
                  >视频通话
                </el-button>
                <el-button
                  v-show="false"
                  type="primary"
                  @click.stop="
                    (oldVideoSatart = true), (videoConversationReal = false)
                  "
                  >查看历史
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col span="12">
              <el-form-item label="备注">
                <el-input v-model="form.bz" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="报警内容">
              <el-input
                disabled="true"
                v-model="form.content"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col span="12">
              <el-form-item label="视频通话">
                <el-button type="primary" @click.stop="queryOldVideo(form)"
                  >查看视频
                </el-button>
              </el-form-item>
            </el-col>
            <el-col span="12">
              <el-form-item label="历史视频">
                <el-button type="primary" @click.stop="queryOldVideo(form)"
                  >查看视频
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :align="center">
            <el-col class="opt-btn">
              <el-form-item>
                <el-button type="warning" @click.stop="revoke(form)"
                  >办结</el-button
                >
                <el-button type="danger" class="push-nmb-btn"
                  >推送110</el-button
                >
                <el-button type="primary" @click.stop="generate(form)"
                  >派发保安</el-button
                >
                <el-button
                  type="success"
                  @click.stop="updateJtyep(form, 1, '办结')"
                  >办结
                </el-button>
                <img
                  src="/img/police-num.png"
                  style="
                    margin-top: -20px;
                    height: 80px;
                    vertical-align: middle;
                  "
                  alt=""
                  @click.stop="updateJtyep(form, 1, '推送110')"
                />
                <el-button
                  type="primary"
                  @click.stop="updateJtyep(form, 1, '派送保安')"
                  >派送保安
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
@@ -193,15 +223,37 @@
        class="ss-video-dialog"
        :modal="false"
        width="100%"
        title="历史视频"
        :visible.sync="innerVisibleVideo"
        title="视频通话"
        :visible.sync="videoConversationReal"
        :close-on-press-escape="false"
        append-to-body
        @opened="openRealVideoBox"
        @close="closeRealVideoBox"
      >
        <video
          src=""
          id="video_conversation"
          style="width: 100%; height: 100%; object-fit: fill"
          controls
        ></video>
      </el-dialog>
      <el-dialog
        class="ss-video-dialog"
        :modal="false"
        width="100%"
        title="历史回放"
        :visible.sync="oldVideoSatart"
        :close-on-press-escape="false"
        append-to-body
        @opened="openOldVideoBox"
        @close="closeOldVideoBox"
      >
        <video
          src=""
          src="/oldVideo/ft.mp4"
          muted="muted"
          autoplay="autoplay"
          loop
          id="old_video"
          style="width: 100%; height: 100%; object-fit: fill"
          controls
@@ -215,19 +267,88 @@
import { mapGetters } from "vuex";
import axios from "axios";
import Hls from "hls.js";
import Recorder from "js-audio-recorder";
var newAxios = axios.create({
  baseURL: "https://web.byisf.com:18000",
  withCredentials: false,
  headers: {
    "Content-type": "application/x-www-form-urlencoded",
  },
});
export default {
  name: "logo",
  data() {
    return {
      dialogTableVisible: false,
      innerVisibleVideo: false,
      videoConversationReal: false,
      oldVideoSatart: false,
      deviceId: null,
      form: {},
      itemOption: {
        menuBtn: false,
        column: [
          {
            disabled: true,
            row: false,
            prop: "province",
            type: "select",
            placeholder: "省份",
            props: {
              label: "name",
              value: "code",
            },
            cascaderItem: ["city", "district"],
            dicUrl: "/api/blade-system/region/select",
            span: 1,
            labelWidth: "0",
            className: "cityClassSelect",
          },
          {
            disabled: true,
            row: false,
            prop: "city",
            type: "select",
            placeholder: "地市",
            props: {
              label: "name",
              value: "code",
            },
            dicUrl: "/api/blade-system/region/select?code={{key}}",
            span: 1,
            labelWidth: "0",
            className: "cityClassSelect",
          },
          {
            disabled: true,
            row: false,
            prop: "district",
            type: "select",
            placeholder: "区县",
            props: {
              label: "name",
              value: "code",
            },
            dicUrl: "/api/blade-system/region/select?code={{key}}",
            span: 1,
            labelWidth: "0",
            className: "cityClassSelect",
          },
        ],
      },
      isActive: false,
      recorder: null,
      peopleList: [],
      peopleName: "",
      peoplePhone: "",
      ofX: null,
      ofY: null,
    };
  },
  created() {
    this.getData();
    this.websocketStart();
  },
  computed: {
    ...mapGetters(["website", "keyCollapse"]),
@@ -235,12 +356,15 @@
  methods: {
    getData() {
      var that = this;
      axios({
        url: "/api/blade-jfpts/alarm/alarm/getLimit",
        method: "get",
      }).then(function (response) {
        that.deviceId = response.data.data[0].id;
        if (response.data.data.length > 0) {
          that.deviceId = response.data.data[0].id;
        } else {
          that.deviceId = 0;
        }
        //获得最新ID,开启实时报警循环
        that.layerRealtime();
      });
@@ -248,169 +372,220 @@
    layerRealtime() {
      var that = this;
      window.clearTimeout(window.realTimeQuery);
      // that.deviceId = 334; // 测试用
      window.realTimeQuery = setInterval(function () {
        axios({
          url: "/api/blade-jfpts/alarm/alarm/selecttx?id=" + that.deviceId,
          method: "post",
        }).then(function (response) {
          var userId = JSON.parse(
            window.localStorage.getItem("物联网安保云服务平台-userInfo")
          ).content.user_id;
          if (response.data.data.length > 0) {
            that.deviceId = response.data.data[0].id;
            that.form = response.data.data[0];
            that.dialogTableVisible = true;
            that.innerVisibleVideo = true;
            that.$refs.realAudio.src = "./realVideo/audio.mp3";
            that.$refs.realAudio.play();
            newAxios
              .post(
                "/api_control",
                {},
                {
                  params: {
                    param: JSON.stringify({ PktType: "GetAccessToken" }),
                  },
                }
              )
              .then((res) => {
                newAxios
                  .get(
                    `https://web.byisf.com:18000/GetPlayUrl?deviceCode=${that.form.serialNumber}&chl=${that.form.channelNumber}`
                  )
                  .then((result) => {
                    axios({
                      method: "post",
                      url: `/api/blade-jfpts/rvideo/rVoids`,
                      params: {
                        url: result.data.data.flv,
                      },
                    }).then((resdata) => {});
                  });
              });
            if (
              response.data.data[0].waringType == "紧急求救" &&
              response.data.data[0].alarmId == userId
            ) {
              response.data.data[0].waringType = "一键求助";
              that.peopleList = [
                { label: that.form.oneContacts, value: that.form.onePhone },
                { label: that.form.twoContacts, value: that.form.twoPhone },
                { label: that.form.threeContacts, value: that.form.threePhone },
              ];
              that.peopleName = that.form.oneContacts;
              that.peoplePhone = that.form.onePhone;
              that.dialogTableVisible = true;
              that.ofX = null;
              that.ofY = null;
              window.addEventListener("mousemove", that.handleMousemove);
              that.$refs.realAudio.src = "./realVideo/audio.mp3";
              that.$refs.realAudio.play();
            }
          }
        });
      }, 5000);
    },
    closeDialog() {
      //关闭窗口回调,关闭警报
      this.$refs.realAudio.pause();
      this.videoConversationReal = false;
      this.oldVideoSatart = false;
    },
    generate(row) {
      var that = this;
      //关闭窗口回调,关闭警报
      that.$refs.realAudio.pause();
    getDate() {
      // 当前时间
      var timestamp = Date.parse(new Date());
      var serverDate = new Date(timestamp);
      axios({
        url: "/api/blade-jfpts/jingdan/jingdan/submit",
        method: "post",
        data: {
          rName: row.rname,
          galarmPeople: row.galarmPeople,
          phoneNumber: row.phoneNumber,
          place: row.place,
          alarmPeople: row.alarmPeople,
          content: row.content,
          galarmTime: row.alarmTime,
          waringType: row.waringType,
          deviceNumber: row.deviceNumber,
          type: "0",
          handleP: null,
          handleTime: null,
          handName: null,
          level: row.level,
          coordinate: null,
          jd: row.jd,
          wd: row.wd,
          district: row.district,
          city: row.city,
          province: row.province,
          czTime: row.czTime,
          jjTime: row.jjTime,
          bz: row.bz,
      // 本周周一的时间
      var mondayTime =
        timestamp - (serverDate.getDay() - 1) * 24 * 60 * 60 * 1000;
      var mondayData = new Date(mondayTime);
      //年
      var mondayY = mondayData.getFullYear();
      //月
      var mondayM =
        mondayData.getMonth() + 1 < 10
          ? "0" + (mondayData.getMonth() + 1)
          : mondayData.getMonth() + 1;
      //日
      var mondayD =
        mondayData.getDate() < 10
          ? "0" + mondayData.getDate()
          : mondayData.getDate();
      // 当前时间
      var currentData = new Date(timestamp);
      //年
      var currentY = currentData.getFullYear();
      //月
      var currentM =
        currentData.getMonth() + 1 < 10
          ? "0" + (currentData.getMonth() + 1)
          : currentData.getMonth() + 1;
      //日
      var currentD =
        currentData.getDate() < 10
          ? "0" + currentData.getDate()
          : currentData.getDate();
      //时
      var currenH =
        currentData.getHours() < 10
          ? "0" + currentData.getHours()
          : currentData.getHours();
      //分
      var currenM =
        currentData.getMinutes() < 10
          ? "0" + currentData.getMinutes()
          : currentData.getMinutes();
      //秒
      var currenS =
        currentData.getSeconds() < 10
          ? "0" + currentData.getSeconds()
          : currentData.getSeconds();
      return {
        day: {
          beginTime: currentY + "-" + currentM + "-" + currentD + " 00:00:00",
          endTime:
            currentY +
            "-" +
            currentM +
            "-" +
            currentD +
            " " +
            currenH +
            ":" +
            currenM +
            ":00",
        },
      })
        .then(function (response) {
          that.$message({
            message: "生成警单成功",
            type: "success",
          });
          that.updateJtyep(row);
          that.dialogTableVisible = false;
          that.innerVisibleVideo = false;
          var arr = [];
          that.$store.state.tags.tagList.forEach((item) => {
            if (item.label != "警情分发处置") {
              arr.push(item);
            }
          });
          that.$store.state.tags.tagList = arr;
          row.type = 0;
          row.id = response.data.data;
          that.$router.push({ path: "/distribution/index", query: row });
        })
        .catch(function (error) {
          that.dialogTableVisible = false;
          that.innerVisibleVideo = false;
        });
    },
    revoke(row) {
      var that = this;
      axios({
        url: "/api/blade-jfpts/alarm/alarm/deletejj?id=" + row.id,
        method: "post",
      }).then(function () {
        that.dialogTableVisible = false;
        that.innerVisibleVideo = false;
        //关闭窗口回调,关闭警报
        that.$refs.realAudio.pause();
      });
    },
    updateJtyep(row) {
      var that = this;
      axios({
        url:
          "/api/blade-jfpts/alarm/alarm/updateJtype?id=" +
          row.id +
          "&czTime=" +
          row.czTime +
          "&bz=" +
          row.bz,
        method: "post",
      }).then(function () {});
    },
    queryOldVideo(data) {
      var newAxios = axios.create({
        baseURL: "http://36.134.81.48:18000",
        withCredentials: false,
        headers: {
          "Content-type": "application/x-www-form-urlencoded",
        week: {
          beginTime: mondayY + "-" + mondayM + "-" + mondayD + " 00:00:00",
          endTime:
            currentY +
            "-" +
            currentM +
            "-" +
            currentD +
            " " +
            currenH +
            ":" +
            currenM +
            ":00",
        },
      });
      var time = this.beginTimeOrEndTime(data.alarmTime);
      newAxios
        month: {
          beginTime: mondayY + "-" + mondayM + "-01 00:00:00",
          endTime:
            currentY +
            "-" +
            currentM +
            "-" +
            currentD +
            " " +
            currenH +
            ":" +
            currenM +
            ":00",
        },
        current:
          currentY +
          "-" +
          currentM +
          "-" +
          currentD +
          " " +
          currenH +
          ":" +
          currenM +
          ":" +
          currenS,
      };
    },
    updateJtyep(row, jtype, t) {
      var that = this;
      axios
        .post(
          "/api_control",
          "/api/blade-jfpts/alarm/alarm/updateJtype",
          {},
          {
            params: {
              param: JSON.stringify({ PktType: "GetAccessToken" }),
              jid: row.id,
              jtype: jtype,
              rid: row.alarmId,
              bz: row.bz,
              snumber: row.alarmId,
              sname: row.alarmPeople,
              zc: t,
              zctime: that.getDate().current,
            },
          }
        )
        .then((res) => {
          newAxios
            .get(
              `/GetPlayUrl?deviceCode=${data.channelNumber}&chl=${data.serialNumber}`
            )
            .then((result) => {
              this.innerVisibleVideo = true;
        .then(function () {
          that.dialogTableVisible = false;
              this.videoSource = result.data.data.m3u8;
            });
          axios({
            method: "post",
            url: `/api/blade-jfpts/rvideo/stop`,
            params: {
              jid: row.id,
            },
          }).then((resdata) => {});
          //   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.innerVisibleVideo = true;
          //       this.videoSource = result.data.data.m3u8;
          //     });
          that.$router.push({
            path: "/policeTracking/track",
            query: that.form,
          });
        });
    },
    beginTimeOrEndTime(time) {
      var beginTime = new Date(time);
@@ -470,27 +645,48 @@
        end: endY + endM + endD + endH + endm + ends,
      };
    },
    openOldVideoBox() {
      if (Hls.isSupported()) {
        var dom = document.getElementById("old_video");
        // if (dom.volume) dom.volume = 1.0;
    // 视频通话打开关闭事件
    openRealVideoBox() {
      newAxios
        .post(
          "/api_control",
          {},
          {
            params: {
              param: JSON.stringify({ PktType: "GetAccessToken" }),
            },
          }
        )
        .then((res) => {
          newAxios
            .get(
              `https://web.byisf.com:18000/GetPlayUrl?deviceCode=${this.form.serialNumber}&chl=${this.form.channelNumber}`
            )
            .then((result) => {
              this.videoSource = result.data.data.m3u8;
        this.hls = new Hls();
              if (Hls.isSupported()) {
                var dom = document.getElementById("video_conversation");
        var m3u8Url = decodeURIComponent(this.videoSource);
                this.hls = new Hls();
        this.hls.loadSource(m3u8Url);
                var m3u8Url = decodeURIComponent(this.videoSource);
        this.hls.attachMedia(dom);
                this.hls.loadSource(m3u8Url);
        this.hls.on(Hls.Events.MANIFEST_PARSED, function () {
          dom.play();
                this.hls.attachMedia(dom);
                this.hls.on(Hls.Events.MANIFEST_PARSED, function () {
                  dom.play();
                });
              }
            });
        });
      }
    },
    closeOldVideoBox() {
      var dom = document.getElementById("old_video");
    closeRealVideoBox() {
      var dom = document.getElementById("video_conversation");
      if (dom.getAttribute("src") != "") {
        dom.pause();
@@ -499,6 +695,179 @@
        this.hls.destroy();
      }
    },
    // 历史视频打开关闭事件
    openOldVideoBox() {
      var dom = document.getElementById("old_video");
      dom.currentTime = 0;
      dom.play();
    },
    closeOldVideoBox() {
      var dom = document.getElementById("old_video");
      dom.pause();
    },
    aKeyToCall() {
      this.isActive = true;
      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
        });
      }
      // 一键呼叫相关函数
      that.recorder.start().then(
        () => {
          // 开始录音
        },
        (error) => {
          // 出错了
          console.log(`${error.name} : ${error.message}`);
        }
      );
    },
    // 序列号后期待修改
    aKeyStopCall() {
      this.isActive = false;
      var newCallAxios = axios.create({
        baseURL: "https://web.byisf.com:18000",
        withCredentials: false,
        headers: {
          "Content-Type": "application/json;",
        },
      });
      var that = this;
      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);
          newCallAxios
            .post(`/api_control`, blob, {
              params: {
                param: {
                  PktType: "Talk",
                  accessToken: result.data.data.accessToken,
                  deviceCode: this.form.serialNumber,
                },
              },
            })
            .then(() => {
              that.recorder.destroy().then(function () {
                that.recorder = null;
              });
            });
        });
    },
    peopleOrPhone(e) {
      this.peopleList.forEach((item) => {
        if (item.label == e) {
          this.peoplePhone = item.value;
        }
      });
    },
    // 监听鼠标的移动事件
    handleMousemove(e) {
      if (
        (this.ofX != null && e.offsetX != this.ofX) ||
        (this.ofY != null && e.offsetY != this.ofY)
      ) {
        this.$refs.realAudio.pause();
        window.removeEventListener("mousemove", this.handleMousemove);
      }
      this.ofX = e.offsetX;
      this.ofY = e.offsetY;
    },
    //启动websocket
    websocketStart() {
      var that = this;
      if (!window.WebSocket) {
        window.WebSocket = window.MozWebSocket;
      }
      if (window.WebSocket) {
        // https
        window.socket = new WebSocket("wss://web.byisf.com/wss/websocket/");
        //http
        // window.socket = new WebSocket("ws://localhost:9034/websocket");
        window.socket.onmessage = function (event) {};
        window.socket.onopen = function (event) {};
        window.socket.onclose = function (event) {};
        window.socket.error = function (event) {
          //执行重连
          that.websocketStart();
        };
      } else {
        console.log("WebSocket连接没有建立成功!!");
      }
      setTimeout(function () {
        window.clearTimeout(window.websockPing);
        if (!window.WebSocket) {
          return;
        }
        if (window.socket.readyState == WebSocket.OPEN) {
          var userId = JSON.parse(
            window.localStorage.getItem("物联网安保云服务平台-userInfo")
          ).content.user_id;
          window.socket.send(userId);
          //开启心跳传送
          window.websockPing = setInterval(function () {
            if (window.socket.readyState == WebSocket.OPEN) {
              window.socket.send("ping");
            } else {
              console.log("心跳停止,断开重连");
              //断开连接,重连
              window.clearTimeout(window.websockPing);
              //执行重连
              that.websocketStart();
            }
          }, 10000);
        } else {
          console.log("WebSocket连接没有建立成功!!");
          //执行重连
          that.websocketStart();
        }
      }, 3000);
    },
    onDialogTableVisible() {
      Recorder.getPermission().then(() => {});
      this.videoConversationReal = true;
    },
  },
};
@@ -585,7 +954,7 @@
  bottom: 0 !important;
  left: 0 !important;
  right: 400px !important;
  height: 630px !important;
  height: 558px !important;
  border-radius: 10px 10px 10px 10px;
}
@@ -593,10 +962,11 @@
  position: absolute !important;
  top: 0px !important;
  left: auto !important;
  right: 0px !important;
  right: 5px !important;
  bottom: 0 !important;
  margin: auto !important;
  width: 660px !important;
  width: 670px !important;
  z-index: 2200 !important;
}
.ss-video-dialog .el-dialog {
@@ -606,11 +976,17 @@
  right: 0 !important;
  bottom: 0 !important;
  margin: auto !important;
  height: 630px;
  height: 558px;
  border-radius: 10px 10px 10px 10px;
}
.ss-video-dialog .el-dialog .el-dialog__header {
  padding-top: 10px;
}
.ss-video-dialog .el-dialog .el-dialog__body {
  height: calc(100% - 54px);
  padding: 10px !important;
  height: calc(100% - 44px);
  box-sizing: border-box;
}
</style>