安琪酵母(西藏)益生菌信息采集中心智能实验室
longyvfengyun
2023-08-24 fe936486ee0023e4be8d17625471aad6e8e284ff
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import {ref, watch} from "vue";
import slideMenu from "@/views/mainLayout/js/slideMenu";
 
/**
 *  海康威视模块内容
 */
const hkModule = ()=>{
  const {isCollapse} = slideMenu();
  const divPlugin = ref(null);
  const iWndowType = ref(3);
  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: true, //是否支持单窗口双击全屏
      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, iWndIndex)=>{
    WebVideoCtrl.I_GetDevicePort(data.ip).then(res=>{
      console.log(res);
    }).catch(error=>{
      if(error.errorCode == 2000) {
        login(data, iWndIndex);
      }
      console.log(error);
    });
  }
 
  const login = (data, iWndIndex)=>{
    WebVideoCtrl.I_Login(data.ip, 1, data.port, data.username, data.password, {
      timeout: 3000,
      success: function () {
        console.log("开始预览");  //不能删除
        const szId = data.ip+"_"+data.port;
 
        // 模拟通道
        const getAnalog = WebVideoCtrl.I_GetAnalogChannelInfo(szId, {
          timeout: 3000,
          success: function (xmlDoc) {
            console.log("模拟通道成功");
          },
          error: function (oError) {
            console.log("模拟通道失败");
          }
        });
 
        Promise.all([getAnalog]).then(res=>{
          console.log("数据成功");
          setTimeout(()=>{
            initPlay(data.ip, data.port, iWndIndex);
          }, 3000);
        }).catch(error=>{
          console.log("数据失败");
          setTimeout(()=>{
            initPlay(data.ip, data.port, iWndIndex);
          }, 3000);
        });
      },
      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, iWndIndex)=>{
    let oWndInfo = WebVideoCtrl.I_GetWindowStatus(iWndIndex);
    if (oWndInfo != null) {// 已经在播放了,先停止
      WebVideoCtrl.I_Stop({
        iWndIndex,
        success: function () {
          startRealPlay(ip, port, iWndIndex);
        },
        error: function() {
          startRealPlay(ip, port, iWndIndex);
        }
      });
    } else {
      startRealPlay(ip, port, iWndIndex);
    }
 
  }
 
  const startRealPlay = (ip, port, iWndIndex)=>{
    WebVideoCtrl.I_StartRealPlay(ip, {
      iStreamType: 1,
      iChannelID: 1,
      iWndIndex,
      bZeroChannel: false,
      success: function () {
        console.log("开始预览成功!");
      },
      error: function (oError) {
        setTimeout(()=>{
          initPlay(ip, port, iWndIndex);
        }, 3000);
        console.log("开始预览失败!");
        console.log(oError);
      }
    });
  }
 
  watch(
    iWndowType,
    (newVal)=>{
      changeWndNum(newVal[0]);
    },
  );
  watch(
    isCollapse,
    (newVal)=>{
      setTimeout(()=>{
        WebVideoCtrl.I_My_Resize();
      }, 300);
 
    },
  );
 
  return {
    divPlugin, iWndowType, gIWndIndex,
    videoInitPlugin, clickLogin, changeWndNum, initPlay
  };
}
export default hkModule;