/** * 自定义控件书写模板 */ (function (KDApi, $) { // 构造函数,变量名随意,与最后一句代码的KDApi.register的第二个参数一致即可 function HelloWorld(model) { this._setModel(model) } // 原型中封装生命周期函数,固定格式 HelloWorld.prototype = { _setModel: function (model) { this.model = model }, init: function (props) { initFunc(this.model, props) }, update: function (props) { updateFunc(this.model, props) }, destoryed: function () { close() } } var initFunc = function (model, props) { console.warn(props) console.warn('init') // KDApi.loadFile可以通过路径加载js或css文件,并且在html文件头生成script或者link标签,第一个参数是路径,第二个参数是model,第三个参数是加载完成后执行的回调函数 KDApi.loadFile('./css/style.css', model, function () { // 通过路径去获取html字符串,第一个参数是路径,第二个参数是model,第三个参数是HTML模板中变量的值 KDApi.getTemplateStringByFilePath('./html/violet-test.html', model, { //text: '' }).then(function (result) { model.dom.innerHTML = result }) }) KDApi.loadFile('./js/allWebPlugin.Common.v2.0.0.30.js', model, function () { // 通过路径去获取html字符串,第一个参数是路径,第二个参数是model,第三个参数是HTML模板中变量的值 KDApi.getTemplateStringByFilePath('./html/violet-test.html', model, { //text: '' }).then(function (result) { model.dom.innerHTML = result KDApi.loadFile('./js/allWebPlugin.UI.v2.0.0.30.js', model, function () { // 通过路径去获取html字符串,第一个参数是路径,第二个参数是model,第三个参数是HTML模板中变量的值 KDApi.getTemplateStringByFilePath('./html/violet-test.html', model, { //text: '' }).then(function (result) { model.dom.innerHTML = result KDApi.loadFile('./js/allWebPlugin.Main.v2.0.0.30.js', model, function () { // 通过路径去获取html字符串,第一个参数是路径,第二个参数是model,第三个参数是HTML模板中变量的值 KDApi.getTemplateStringByFilePath('./html/violet-test.html', model, { //text: '' }).then(function (result) { model.dom.innerHTML = result initOffice() openFile(model, props) initEvent(model, props) }) }) }) }) }) }) } var initEvent = function (model, props) { const ele = document.getElementById('violet-pra-btn') ele.onclick = function () { model.invoke('click', 0) } const closeEle = document.getElementById('violet-close-btn') closeEle.onclick = function () { close() model.invoke('click', 2) } } var updateFunc = function (model, props) { textFromProps = props.data.textKey001 + '' const ele = document.getElementById('violet-pra-btn') ele.innerText = textFromProps } var initOffice = function (model, props) { var installPackageUrl = "http://127.0.0.1:6651/install/allwebPlugin_x86_v2.0.1.16_20240806.exe"; var installPackageVersion = "2.0.0.30"; console.warn('initOffice') console.warn(awp_IsInstall(installPackageVersion, installPackageUrl)) if (awp_IsInstall(installPackageVersion, installPackageUrl)) { awp_CreatePlugin("allWebOfficeAx", "{6888ECA8-57D0-6E0E-9B9B-F1FF9B2DBD86}"); allWebOfficeAx.GetDisplayStyle().ShowOpenProgress = true; } } var openFile = function (model, props) { var pluginUtilityObj = awp_getPluginUtility(); var httpclientObj = awp_getHttpClient(); httpclientObj.Clear(); //https://www.gov.cn/gzdt/att/att/site1/20100917/0019b90463ff0dfd641102.pdf //https://local.zsignyun.com:6652/test2.docx console.warn(props) var url = "https://srm-dev.cmoc.cloud:8022/ierp/attachment/download.do?path=/1d969f1a75006800&kd_cs_ticket=KKFDWRkv8aTFjgbz574ddO5Jj0gudMX3&access_token=2117884374501299200_v7LFmgmezCNo6qxtuNS2xYPo7W1fquIeRE7ODdVLkez3YFMfplpgNEdBxjW6MOIwKLXxocwBt7GNH2qlsDPt4STblUEpoavI6A9E09"; if (props?.data?.fileurl) { url = props.data.fileurl } if (httpclientObj.Open(0, url, false)) { httpclientObj.Send().then(function (data) { if (httpclientObj.GetStatus() == 200) { var varTempPath = pluginUtilityObj.GetTempPath(); var varFile = pluginUtilityObj.GetTempFileName(varTempPath, "zso") + ".docx"; httpclientObj.ResponseSaveToFile(varFile); allWebOfficeAx.Open(varFile); allWebOfficeAx.DeleteAfterClose = true; } else { var httpStatus = httpclientObj.GetStatus(); if (httpclientObj.GetStatus() == 0) { alert("LoadFile test2.docx Error:" + httpclientObj.GetErrorText()); } else { alert("LoadFile test2.docx Status:" + httpStatus + ",请确保安装目录下web/doc目录存在test2.docx"); } } httpclientObj.Close(); }); } } var close = function () { allWebOfficeAx.Close_Asyn(0).then(function (data) { }); } // 你只需知道第一个参数是你接下来要新增控件方案时填的方案id,第二个参数是上面声明的构造函数 KDApi.register('violet-test', HelloWorld) })(window.KDApi, jQuery) // 这里的jQuery不是必须要传进去的,可移除,要用到的时候才传,PC端系统默认会有jQuery对象,版本是1.12.4