Files
fe_service_ebtp_frontend/public/officecontrol/ntko.20220624.js

123 lines
4.2 KiB
JavaScript

var ntko;//控件对象
//初始化去打开文档
function init(readonly, DocfileCode) {
ntko = document.getElementById("TANGER_OCX");
ntko.Menubar = false;//隐藏窗体左上侧文件菜单
ntko.TitleBar = false;//隐藏窗体左上图标
$.ajax({
url: "/api/sys-manager-ebtp-project/v1.0/files/queryReturn",
type: "POST",
contentType: "application/json;charset=UTF-8",
data: JSON.stringify([DocfileCode]),
success: function (result) {
if (window.navigator.platform == "Win32") {
ntko.AddDocTypePlugin(".pdf", "PDF.NtkoDocument", "4.0.1.0", "officecontrol/ntkooledocall.cab", 51, true);
}
if (window.navigator.platform == "Win64") {
ntko.AddDocTypePlugin(".pdf", "PDF.NtkoDocument", "4.0.1.0", "officecontrol/ntkooledocallx64.cab", 51, true);//PDF支持
}
if (result.success) {
if (result.data.length > 0) {
$.ajax({
url: "/api/sys-manager-ebtp-project/v1.0/files/getSecretKey?fileId=" + result.data[0].fileId,//获取密钥
type: "GET",
contentType: "application/json;charset=UTF-8",
success: function (response) {
ntko.BeginOpenFromURL("/api/sys-manager-ebtp-project/v1.0/files/getDownload?fileId=" + result.data[0].fileId + "&documentSecretKey=" + response.data);
}
})
} else {
ntko.OpenFromURL("ntkocreatnew.docx");
}
} else {
alert(JSON.stringify(result));
}
/*展示保存按钮*/
if (readonly == "false") {
$("#saveBTN").show();
}
ntko.Menubar = true;//展示窗体左上侧文件菜单
ntko.IsUseOfficeConvertDocToPDF = true;
ntko.CustomToolBar = false;
ntko.FileSave = false;
},
error: function () {
alert("请求文档中心失败,请您关闭当前编辑器,重新打开。")
}
});
}
//通用上传
function ntkoUpload(type, objectId, fileName) {
if (objectId !== null && objectId !== void 0 && objectId !== "") {
var path = "/api/sys-manager-ebtp-project/v1.0/files/upload";
var fileUploadName = "multipartFiles";
var params = "appCode=ebtp-cloud-frontend&objectId=" + objectId;
var msg
$.ajax({
url: "/api/sys-manager-ebtp-project/v1.0/files/queryReturn",
type: "POST",
async: false,
contentType: "application/json;charset=UTF-8",
data: JSON.stringify([objectId]),
success: function (result) {
if (result.success) {
if (result.data.length > 0) {
for (let i = 0; i < result.data.length; i++) {
const ele = result.data[i];
$.ajax({
url: "/api/sys-manager-ebtp-project/v1.0/files/disk" + "?fileId=" + ele.fileId,
type: "POST",
dataType: "json",
})
}
}
if (type == "Doc") {
msg = ntko.SaveToURL(path, fileUploadName, params, fileName, "");
} else if (type == "HTML") {
msg = ntko.PublishAsHTMLToURL(path, fileUploadName, params, fileName, "");
} else if (type == "PDF") {
msg = ntko.PublishAsPDFToURL(path, fileUploadName, params, fileName, "");
}
}
}
})
return msg;
}
}
//修改文件名
function ntkoUpdateFile(objectId, fileName) {
if (objectId !== null && objectId !== void 0 && objectId !== "") {
var msg;
$.ajax({
url: "/api/sys-manager-ebtp-project/v1.0/files/queryReturn",
type: "POST",
async: false,
contentType: "application/json;charset=UTF-8",
data: JSON.stringify([objectId]),
success: function (result) {
if (result.success) {
if (result.data.length > 0) {
$.ajax({
url: "/api/sys-manager-ebtp-project/v1.0/files/update",
type: "POST",
async: false,
contentType: "application/json;charset=UTF-8",
dataType: "json",
data: JSON.stringify([{ fileId: result.data[result.data.length - 1].fileId, originalName: fileName }]),
success: function (response) {
msg = response.success;
}
})
}
}
}
})
return msg;
}
}