安琪酵母(西藏)益生菌信息采集中心智能实验室
longyvfengyun
2023-07-03 365031c165038b7e1e3fc38ca8f91962f90c72d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import {ref, watch} from "vue";
import slideMenu from "@/views/mainLayout/js/slideMenu";
 
/**
 *  海康威视模块内容
 */
const hkModule = ()=>{
  const {isCollapse} = slideMenu();
  const divPlugin = ref(null);
  const iWndowType = ref(1);
  const gIWndIndex = ref(0);
  const videoInitPlugin = (cbComplete)=>{
    let iRet = WebVideoCtrl.I_CheckPluginInstall();
    if (iRet === -1) {
      alert("您还未安装过插件,请安装WebComponentsKit.exe插件!");
      return;
    }
    initPlugin(cbComplete);
  }
 
  const initPlugin = (cbComplete)=>{
    WebVideoCtrl.I_InitPlugin({
      bWndFull: false, //是否支持单窗口双击全屏
      iWndowType: iWndowType.value,
      bDebugMode:true,
      cbSelWnd: function (xmlDoc){
        gIWndIndex.value = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
      },
      cbInitPluginComplete: function() {
        console.log("初始化插件完成");
        WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
        if(cbComplete && typeof cbComplete === "function") {
          setTimeout(()=>{
            cbComplete();
          }, 500);
 
        }
      }
    });
  }
 
  const clickLogin = (data)=>{
    console.log(data);
    WebVideoCtrl.I_Login(data.ip, 1, data.port, data.username, data.password, {
      timeout: 3000,
      success: function () {
        console.log("开始预览");  //不能删除
        setTimeout(()=>{
          initPlay(data.ip, data.port);
        }, 1000);
      },
      error: function () {
        console.log("login error");
      }
    });
  }
 
  const changeWndNum = (num)=>{
    let value = parseInt(num, 10);
    WebVideoCtrl.I_ChangeWndNum(value).then(() => {
      console.log("窗口分割成功!");
    }, (oError) => {
      console.log("窗口分割失败!");
    });
  };
 
  const initPlay = (ip, port)=>{
    let oWndInfo = WebVideoCtrl.I_GetWindowStatus(0);
    if (oWndInfo != null) {// 已经在播放了,先停止
      WebVideoCtrl.I_Stop({
        success: function () {
          startRealPlay(ip, port);
        }
      });
    } else {
      startRealPlay(ip, port);
    }
 
  }
 
  const startRealPlay = (ip, port)=>{
    WebVideoCtrl.I_StartRealPlay(ip, {
      iStreamType: 1,
      iChannelID: 1,
      bZeroChannel: false,
      success: function () {
        console.log("开始预览成功!");
      },
      error: function (oError) {
        console.log("开始预览失败!");
        console.log(oError);
      }
    });
  }
 
  watch(
    iWndowType,
    (newVal)=>{
      changeWndNum(newVal[0]);
    },
  );
  watch(
    isCollapse,
    (newVal)=>{
      //changeWndNum(newVal[0]);
      setTimeout(()=>{
        WebVideoCtrl.I_My_Resize();
      }, 0);
 
    },
  );
 
  return {
    divPlugin, iWndowType, gIWndIndex,
    videoInitPlugin, clickLogin, changeWndNum, initPlay
  };
}
export default hkModule;