背景
JT2Go是一款西门子公司出品的三维图形轻量化预览解决工具,包含精确3D测量、基本3D剖面、PMI显示和改进的选项过滤器等强大的功能。JT2Go控件是一个标准的ActiveX控件,曾经主要在IE浏览器使用,由于微软禁用IE浏览器,导致JT2Go控件无法使用。因此,网友希望能在谷歌、火狐、Edge等浏览器上使用这个控件。
allWebPlugin中间件是一款为用户提供安全、可靠、便捷的浏览器插件服务的中间件产品,致力于将浏览器插件重新应用到所有浏览器。它不仅可以实现ActiveX控件在现代浏览器上使用,而且集成也非常方便。
准备工作
1、下载allWebPlugin中间件产品,具体如下:
链接:百度网盘 请输入提取码
提取码:z3q0
如下图所示,下载allWebPlugin_x86_v2.0.0.22_Stable_20241016.zip安装包。
运行效果
运行效果如下图所示:
控件集成
JT2Go控件主要有3个接口(StartAutomation、Open、StopAutomation),集成代码如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>JT2Go 3D演示页面</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
.style1
{
font-size: xx-large;
font-family: 宋体, Arial, Helvetica, sans-serif;
color: #FF3399;
}
.style2
{
font-size: 16px;
font-family: 宋体, Arial, Helvetica, sans-serif;
color: #FF3399;
}
.style3
{
font-size: 12px;
font-family: 宋体, Arial, Helvetica, sans-serif;
color: #000000;
}
.style4
{
font-size: 12px;
font-family: 宋体, Arial, Helvetica, sans-serif;
color: #FF0000;
}
</style>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/allWebPlugin.Common.js"></script>
<script type="text/javascript" src="js/allWebPlugin.UI.js"></script>
<script language="javascript" type="text/javascript">
var JT2GoObj;
var hostCnt = null;
function init(){
CreateContainer();
}
function CreateContainer(){
var canvas = document.getElementById('pluginUI');
var license = "1q1Sc/tJ1FY2I0gjyovEBlL5O+XF5WrNG0Aq8HHaqVcms51Cl0VS4bYdxltvoHzOdQDEmT8XQhfQhaGxcNiqLQ7oiY85BP8ZsOWCPD3ZYQ5mr14faRu6F8yxXVpgkOeRRlN4clA0lwQi3c0+X/Tvd7BRJKX9uDxkShM9orLUJA119NS++hnfEOcexzvMhL2FWjkNGa2ufV2WjC1M8hbdQSr7uy8b2H7Fiz/HMiWYEFmAnrjDytIx4njwJtO7GYCBKYIE1VGI7iWq9iz4XCIKk1sp1hje01FJCtYPj51+uHfLuWWKatvlFHzSb2IMOSpzAAAA8AEAAQMCTeMq4Dd1nDTk0VXbvFd/Yei0Ojtv60nU4n3yDQuFlxUPwKCQDmQifomaE8DZQR8bEhucH7wk2cabDLm4KCi+wUGvsoKR5r83cLSNLWtaRVtbPoWwMgpFnTmlMtnXrRvPjLx+l/UWPbMMuu9ObsWUU7kdG2mEJRyAFHvRqI+G5Zz8oSets7FNwxdwS2trEiCV4qsAkci3oWhu0ddb02uHzEyOg6sjqKLd9XfKYp4NGdWraSFUYhBsiU7LajQNwmlAeEXWnuNnT5XzoP4icvfojjZZjzw6Ar40ldB7kd9gLDsryZWfwDFsObrXeb9VRVHi8yJ9E17zXMLtpTjtBiIzsQABAYICCgGCMOohm/ugukXrQrv9ulJbVqBTGph9ScEeDPMd5ll5a+dDkRDGlb74ZElzA2gcCi9Xn+FtdXTegKWXRUH5ea5xKhN/6eZgBGL4isdUwaclkKUdq1k60BDQgbvrIx2aRt+io7NnbVJortQQpPWpy/jzQV/aFu+PB/PWwdt/wBHfqgXQw7a1R99EaK6VLtrP7PUURODEIRGk+lP+rFD08z6O/wIXk722B87lfRh+gBoRvhRchXcvlvhqBC3OM7XEBbDLgcvHQvYzm67qxcWvSNJnub+9YxB/7eYR3sE8iJ+h9sfkNE7BYeQ0HwyQpIfCp+3s7nWn8nHBOtbx2Vf5sFBaxHYAAAEOAAAAAUFXUEY=";
var installPackageUrl = "http://127.0.0.1:6651/install/allwebPlugin_x86_v2.0.1.16_20240806.exe";
var installPackageVersion = "2.0.0.20";
hostCnt = new PluginHostCnt();
if(hostCnt.IsInstall() == false){
//未安装,需要手动安装
if(confirm("allWebPlugin中间件未安装或未启动,是否立即安装?")){
window.open(installPackageUrl, '_blank');
}
}else{
//已安装,检测是否需要版本更新
if(hostCnt.IsNewVersion(installPackageVersion) == false)
{
if(hostCnt.createContainer(canvas,"PluginContainer",license,false,true) == true)
{
//hostCnt.UI.ForceShowUI(false);//创建时隐藏插件,需要调用这句,隐藏插件
CreatePlugin();
}
}else{
//需要升级
alert("检测到升级包,立即升级。");
hostCnt.UpdateVersion(installPackageUrl).then(function(data){
if(data.code == 0)
{ //检测是否安装成功
var checkInstall = setInterval(function(){
if(hostCnt.GetVersion() == installPackageVersion){
window.location.reload();
clearTimeout(checkInstall);
}
}, 1000);
}
else{
window.open(installPackageUrl, '_blank');//直接下载包,手动安装
}
}).catch(function(strErr){
window.open(installPackageUrl, '_blank');//直接下载包,手动安装
});
}
}
}
function CreatePlugin(){
if(hostCnt == null)
return;
JT2GoObj = hostCnt.createProxyPlugin("{AD0DEF5C-DEC1-4950-AC57-1533F90C6BAD}");
if(JT2GoObj){
JT2GoObj.StartAutomation();
JT2GoObj.Open("");
}
}
function openFile()
{
if(JT2GoObj){
var pluginUtilityObj = hostCnt.getPluginUtility();
pluginUtilityObj.GetLocalOpenDialog("jt文件(*.jt);;所有文件(*.*)").then(function(varFile){
console.log(varFile);
if(varFile != "")
JT2GoObj.Open(varFile);
});
}
}
function openWebFile()
{
if(JT2GoObj){
var pluginUtilityObj = hostCnt.getPluginUtility();
var httpclientObj = hostCnt.getHttpClient();
httpclientObj.Clear();
if (httpclientObj.Open(0, "https://local.zsignyun.com:6652/doc/test.jt", false)) {
httpclientObj.Send().then(function(data){
if (httpclientObj.GetStatus() == 200) {
var varTempPath = pluginUtilityObj.GetTempPath();
var varFile = pluginUtilityObj.GetTempFileName(varTempPath,"zso") + ".jt";
httpclientObj.ResponseSaveToFile(varFile);
JT2GoObj.Open(varFile);
}
else{
var httpStatus = httpclientObj.GetStatus();
if(httpclientObj.GetStatus() == 0)
{
alert("LoadFile test.jt Error:" + httpclientObj.GetErrorText());
}else{
alert("LoadFile test.jt Status:" + httpStatus + ",请确保安装目录下web\doc目录存在test.jt");
}
}
httpclientObj.Close();
});
}
}
}
</script>
</head>
<body onload="init()" >
<p align="center"><b><span class="style1">JT2Go 3D演示页面</span><br class="style1" /></p>
<button onclick="openFile()">打开文档</button>
<button onclick="openWebFile()">打开在线文档</button>
<table style="width:100%;height:80%" border="0" align="center">
<tr style="width:100%;height:80%">
<td style="width:100%;height:80%">
<canvas id="pluginUI" style="width:100%;height:100%">
<p class="error">Sorry, It looks as though your browser does not support the canvas tag.</p>
</canvas>
</td>
</tr>
</table>
</body>
</html>