<!DOCTYPE html>
|
<html xmlns:th="http://www.thymeleaf.org">
|
<head>
|
<meta charset="UTF-8"/>
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<title th:text="${file_title}"></title>
|
<style type="text/css">
|
html, body {
|
margin: 0;
|
padding: 0;
|
height: 100vh;
|
}
|
|
.openOffice {
|
height: calc(100% - 20px);
|
width: 100%;
|
margin: 0;
|
padding: 0;
|
}
|
</style>
|
<script type="text/javascript" src="/lx/static/js/jquery.min.js"></script>
|
</head>
|
<body>
|
|
|
<div style="height: 100%" id="openOffice-area">
|
<script type="text/javascript">
|
if (!!window.ActiveXObject || "ActiveXObject" in window) {
|
document.write('<object class="openOffice" classid="clsid:FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5" codebase="http://www.officectrl.com/weboffice/WebOffice.ocx#Version=2018,1,6,2" id="WebOffice" width="100%" height="900" >');
|
document.write('</object>');
|
} else {
|
document.write('<object class="openOffice" id="WebOffice" CLSID="{FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5}" TYPE="application/x-itst-activex" width=100% height=900></object>');
|
}
|
</script>
|
</div>
|
</body>
|
|
<script type="text/javascript" src="/lx/static/js/crypto-js.min.js"></script>
|
<script type="text/javascript" src="/lx/static/js/qs.min.js"></script>
|
<script type="text/javascript" th:inline="javascript">
|
var requestPrefix = window.location.protocol + "//" + window.location.host + "/lx/api"
|
var saveFileApi = requestPrefix + "/office/save-office/v1"
|
var getFileApi = requestPrefix + "/office/get-file/v1"
|
var nestFileApi = requestPrefix + "/office/get-nest-red-file/v1"
|
let WebOffice;
|
var readOnly = 1;
|
var formData;
|
var signature;
|
var fileType;
|
var nestRedDocument = [[${nestDocument}]];
|
|
/**
|
* 正在编辑状态发送
|
*/
|
function beingEditedStatusSend() {
|
//每15秒标识一次正在编辑 配合后端 redis 过期时间设置定时发送时间
|
// setTimeout(function () {
|
// $.ajaxSettings.async = true;
|
// $.post("/lx/api/office/reset-document-edit-time/v1", {
|
// 'signature': signature,
|
// 'formData': formData
|
// }, function (success, data) {
|
// if (!data || data.code != 200) {
|
// if (data) {
|
// if (confirm(data.msg)) {
|
// readOnly = 1
|
// WebMenubar(false);
|
// getOffice().ProtectDoc(1, 1, new Date().toString() + Math.random() * 10);
|
// } else {
|
// //退出
|
// customCloseWindow();
|
// }
|
// } else {
|
// readOnly = 1
|
// alert('标识文档编辑状态错误!');
|
// customCloseWindow();
|
// }
|
// }
|
// }, 'json')
|
// $.ajaxSettings.async = true;
|
// beingEditedStatusSend()
|
// }, 15000)
|
|
}
|
|
/**
|
* 打开文档
|
*/
|
function openOffice() {
|
try {
|
getOffice().UserName = "成都龙欣软件有限公司";
|
getOffice().Authorizer = "www.officectrl.com";
|
getOffice().Open(
|
getFileApi + '?signature=' + signature + '&formData=' + encodeURI(formData), true, fileType
|
)
|
//不允许新建
|
getOffice().SetSecurity(254);
|
//不允许打开
|
getOffice().SetSecurity(253);
|
if (readOnly == 1) {
|
// WebToolbar(false)
|
WebMenubar(false);
|
getOffice().ProtectDoc(1, 1, new Date().toString() + Math.random() * 10);
|
} else {
|
beingEditedStatusSend();
|
autoSave()
|
}
|
} catch (e) {
|
if (e.message && e.message.indexOf('消息筛选器显示应用程序正在使用中') != -1) {
|
alert('WPS 或 Microsoft Office 应用程序正在被占用')
|
}
|
// alert(e.message)
|
console.error(e);
|
}
|
}
|
|
/**
|
* 计划开始编辑文档
|
* @param signature
|
* @param formData
|
*/
|
function planEditDocument() {
|
if (readOnly != 1) {
|
|
$.post("/lx/api/office/document-edit-plan/v1", {
|
'signature': signature,
|
'formData': encodeURI(formData)
|
}, function (data, status) {
|
if (data && data.code == 200) {
|
setTimeout(openOffice, 500)
|
} else {
|
if (data.code == '90043') {
|
WebMenubar(false);
|
if (confirm(data.msg)) {
|
readOnly = 1
|
planEditDocument()
|
} else {
|
customCloseWindow();
|
}
|
return;
|
}
|
//计划编辑文档错误
|
console.error(data ? data.msg : '请求错误')
|
alert('打开文档错误,请联系系统管理员!')
|
}
|
|
}, 'json');
|
|
} else {
|
//只读
|
setTimeout(openOffice, 500)
|
}
|
|
|
}
|
|
window.onload = function () {
|
|
$.ajaxSettings.async = false;
|
WebTitlebar(false)
|
WebMenubar(true);
|
signature = [[${signature}]];
|
let data = JSON.parse([[${requestParaTemp}]]);
|
if (!data.fileType) {
|
alert('文件类型获取失败')
|
return;
|
}
|
formData = JSON.stringify(data);
|
readOnly = (String(data.readOnly) != undefined && String(data.readOnly) != '' && String(data.readOnly) != null) ? String(data.readOnly) : 1
|
fileType = data.fileType;
|
setMenu();
|
planEditDocument()
|
|
}
|
/**
|
* 自动保存标识
|
* @type {null}
|
*/
|
var autoSaveStatus = null;
|
|
/**
|
* 自动保存
|
*/
|
function autoSave() {
|
if (readOnly == 1 || autoSaveStatus === false) {
|
return;
|
}
|
|
autoSaveStatus = true;
|
//每30秒自动保存一次
|
setTimeout(function () {
|
customSave();
|
autoSave();
|
}, 30000)
|
}
|
|
window.close = function () {
|
window.opener = null;
|
window.open("", "_self");
|
window.close();
|
}
|
|
function cutArray(array, subLength) {
|
let count = 1;
|
let newArr = [];
|
let resultArr = [];
|
if (array.length < subLength) {
|
return [array];
|
}
|
array.forEach(function (item) {
|
newArr.push(item);
|
if (count % subLength == 0) {
|
resultArr.push(newArr);
|
newArr = [];
|
}
|
if (count == array.length - 1) {
|
resultArr.push(newArr);
|
}
|
count++;
|
});
|
return resultArr;
|
}
|
|
function setMenu() {
|
getOffice()
|
var menuCount = Array.isArray(nestRedDocument) && nestRedDocument.length > 0 ? (Math.ceil(nestRedDocument.length / 10)) + 2 : 2
|
WebOffice.SetMenuName(0, '保存');//修改文件菜单名称为:新建文件
|
WebOffice.CustomMenuCount = menuCount;//设置新增的菜单个数
|
WebOffice.SetMenuName(1, '保存并关闭');
|
WebOffice.SetMenuName(2, '关闭');
|
// WebOffice.SetMenuName(3, '关闭自动保存');
|
if (menuCount > 2) {
|
for (let i = 0; i < Math.ceil(nestRedDocument.length / 10); i++) {
|
WebOffice.SetMenuName(i + 3, '套红' + (i > 0 ? (i + 1) : ''));
|
}
|
}
|
|
setTimeout(function () {
|
if (Array.isArray(nestRedDocument) && nestRedDocument.length > 0) {
|
let array = cutArray(nestRedDocument, 10);
|
for (let i = 0; i < array.length; i++) {
|
var group = array[i];
|
for (let j = 0; j < group.length; j++) {
|
var e = group[j];
|
WebOffice.WebAddMenuItem(3 + i, e.title, "5" + (3 + i) + "0" + (j == 9 ? '10' : '0' + (j + 1)))
|
}
|
}
|
}
|
WebOffice.WebClearMenuItem(0);//清除控件默认文件菜单里的所有子项
|
}, 1500)
|
}
|
|
function customSave() {
|
var strSaveUrl = saveFileApi;
|
try {
|
WebOffice.HttpInit();
|
var signature = [[${signature}]];
|
let data = JSON.parse([[${requestParaTemp}]]);
|
var formData = JSON.stringify(data);
|
WebOffice.HttpAddPostString('signature', signature);
|
WebOffice.HttpAddPostString('~table~', 'product_sys_attachments');
|
WebOffice.HttpAddPostString('formData', formData);
|
WebOffice.HttpAddPostCurrFile("docfile", "");//此句为固定语句,不管是保存word还是excel,ppt等都这样写
|
|
//strResults用于获得网页提交后的返回数据,可用以调试服务器端代码。
|
var strResults = WebOffice.HttpPost(strSaveUrl);
|
console.log(strResults)
|
if (strResults) {
|
var res = JSON.parse(strResults);
|
if (res && res.code != 200) {
|
if (res.code == "90021" || res.code == '90044') {
|
autoSaveStatus = false;
|
alert(res.msg);
|
customCloseWindow();
|
return;
|
}
|
alert(res.msg);
|
}
|
// alert(strResults)
|
// JSON.parse()
|
}
|
// alert(strResults);//用alert语句可以显示服务器端网页返回的数据
|
// strResults;//如果保存成功,编程时让服务器接收代码如upload.jsp,upload.aspx,upload.php等返回空值或OK字串。
|
} catch (e) {
|
console.error(e);
|
alert('发生错误!请使用查阅返回值!');
|
}
|
}
|
|
function customSaveClose() {
|
customSave()
|
customCloseWindow()
|
}
|
|
function customCloseWindow() {
|
window.opener = null;
|
window.open("", "_self");
|
window.close();
|
}
|
|
/**
|
* 设置当前用户名称 (wps 测试好像无效)
|
*/
|
function setCurrentUserName() {
|
getOffice().SetCurrUserName([[${user_name}]])
|
}
|
|
|
function getOffice() {
|
if (!WebOffice) {
|
WebOffice = document.getElementById('WebOffice');
|
}
|
return WebOffice;
|
}
|
|
/**
|
* 标题栏
|
* @param e
|
* @constructor
|
*/
|
function WebTitlebar(e) {
|
getOffice().Titlebar = e
|
}
|
|
/**
|
* 菜单栏
|
* @param e
|
* @constructor
|
*/
|
function WebMenubar(e) {
|
getOffice().MenuBars = e;
|
}
|
|
/**
|
* 工具栏
|
* @param e
|
* @constructor
|
*/
|
function WebToolbar(e) {
|
getOffice().Toolbars = e
|
}
|
|
/**
|
* 套红文档
|
*/
|
function nestRedDocumentInsert(menuId) {
|
if (!menuId) {
|
return;
|
}
|
|
try {
|
var data;
|
try {
|
var groupId = parseInt(menuId.substring(1, 2)) - 3;
|
var menuItemCount = parseInt(menuId.substring(menuId.length - 2));
|
var index = (groupId * 10) + menuItemCount - 1
|
data = nestRedDocument[index];
|
} catch (e) {
|
return;
|
}
|
if (!data) {
|
return;
|
}
|
if (confirm("套红后文档将自动保存,是否继续?")) {
|
WebOffice.HttpInit();
|
WebOffice.HttpAddPostString('signature', data.signature);
|
// WebOffice.HttpAddPostString('~table~', 'product_sys_attachments');
|
WebOffice.HttpAddPostString('formData', data.formJson);
|
WebOffice.HttpAddPostCurrFile("docfile", "");//此句为固定语句,不管是保存word还是excel,ppt等都这样写
|
|
//strResults用于获得网页提交后的返回数据,可用以调试服务器端代码。
|
var strResults = WebOffice.HttpPost(nestFileApi);
|
openOffice();
|
}
|
// console.log(data.signature, data.formJson)
|
// WebOffice.InSertFile(nestFileApi + "?location=1&formData=" + (encodeURI(data.formJson)) + "&signature=" + data.signature, 1)
|
// if (data.document_template_tail) {
|
// WebOffice.InSertFile(nestFileApi + "?location=2&formData=" + (encodeURI(data.formJson)) + "&signature=" + data.signature, 2)
|
// }
|
} catch (e) {
|
console.error(e);
|
alert('套红失败,未知错误')
|
}
|
|
}
|
|
|
</script>
|
<script language="javascript" for="WebOffice" event="OnMenuCommand(param1,param2)">
|
|
switch (param1) {
|
case 50100:
|
//控件菜单的第一个标题是固定值:50100,第二个是:50101,第三个50102,依次类推,一共支持最大20个值,即最后一个值为:50120
|
// alert('您点击了第一个菜单');
|
customSave()
|
break;
|
case 50101:
|
customSaveClose()
|
break;
|
case 50102:
|
customCloseWindow()
|
break;
|
// case 50103:
|
// if (typeof autoSaveStatus == 'boolean') {
|
// autoSaveStatus = !autoSaveStatus
|
// getOffice().SetMenuName(3, autoSaveStatus ? '关闭' : '开启' + '自动保存');
|
// }
|
// break;
|
default:
|
var p = String(param1)
|
if (p.indexOf("50") != 0) {
|
//套红
|
nestRedDocumentInsert(p)
|
}
|
|
}
|
</script>
|
</html>
|