阅读:3153
回复:9
|
子表自定义导入功能导入时间过长
H3BPM版本:9.2.6.10922
问题描述:需要自己写子表的导入功能,导入90行数据,需要6分钟,浏览器多次无响应。经调试发现,时间大部分都耗在了给子表新加行上了。这个问题需要怎么解决呢? 代码: for (var i = 0; i <90; i++) { $.MvcSheetUI.GetElement('WLXXB').SheetUIManager()._AddRow()} 这两行代码在浏览器上运行了5分钟多一些才执行完毕。 |
1楼#
发布于:2018-06-14 13:37
你的需求是什么?
1.这里如果只是加载其它数据源的数据,不需要具有修改、保存权限的话,你可以用其它控件去加载表格。 2.如果需要具有修改权限并保存数据的话。可以换一种思路。用两个流程去实现,把明细的东西放到另外的流程里面。只是不设置审批流。用H3的表单去去缓存。 |
|
|
2楼#
发布于:2018-06-14 14:03
我需要保存和修改的权限,在后续的流程节点需要使用表中的数据进行一些业务动作。还是放在一个流程里面合适一些吧?
|
|
3楼#
发布于:2018-06-15 15:27
@H3BPM 有么有方案
|
|
|
5楼#
发布于:2018-06-21 14:17
|
|
|
7楼#
发布于:2018-06-22 08:49
附件传不上去,直接贴代码了
/// <reference path="MvcSheetUI.js" /> //JS框架,JS框架加载所有JS部件,提供与后台通讯方法 //属性定义 //定义MvcSheet命名控件 jQuery.extend({ MvcSheet: { Version: "V1.0", AjaxUrl: window.location.href.replace("#", "&") + "&T=" + (Math.random() * 1000000).toString().substring(0, 6), LOADKEY: "load", // 加载表单 Actions: [], // 执行事件:保存、提交... InitFunctions: [], // 初始化之前的函数集合 ReadyFunctions: [], // 加载完成需要执行事件集合 //ActionKey Action_Save: "Save", Action_ViewInstance: "ViewInstance", Action_PreviewParticipant: "PreviewParticipant", Action_Print: "Print", Action_CancelInstance: "CancelInstance", Action_Reject: "Reject", Action_Submit: "Submit", Action_FinishInstance: "FinishInstance", Action_Forward: "Forward", Action_Assist: "Assist", Action_Consult: "Consult", Action_Circulate: "Circulate", Action_AdjustParticipant: "AdjustParticipant", Action_LockInstance: "LockInstance", Action_UnLockInstance: "UnLockInstance", Action_Close: "Close", Action_RetrieveInstance: "RetrieveInstance", Action_Viewed: "Viewed",//已阅 //默认Actions SaveAction: { Action: "Save", Icon: "fa-save", Text: "保存", en_us: "Save", OnActionPreDo: null, OnActionDone: null }, PrintAction: { Action: "Print", Icon: "fa-print", Text: "打印", en_us: "Print", OnActionDone: function () { } }, ViewedAction: { Action: "Viewed", Icon: "fa-check", Text: "已阅", en_us: "View", OnActionDone: function () { } }, CancelInstanceAction: { Action: "CancelInstance", Icon: "fa-square-o", en_us: "Cancel", Text: "取消流程" }, RejectAction: { Action: "Reject", Icon: "fa-mail-reply", Text: "驳回", en_us: "Reject", OnActionDone: function () { } }, SubmitAction: { Action: "Submit", Icon: "fa-check", Text: "提交", en_us: "Submit", OnActionDone: function () { } }, RetrieveInstanceAction: { Action: "RetrieveInstance", Icon: "fa-sign-in", en_us: "Reject", Text: "取回" }, ViewInstanceAction: { Action: "ViewInstance", Icon: "fa-ellipsis-v", Text: "流程状态", en_us: "State" }, PreviewParticipantAction: { Action: "PreviewParticipant", Icon: "fa-coumns", Text: "预览", en_us: "Preview" }, FinishInstanceAction: { Action: "FinishInstance", Icon: "fa-square", Text: "结束流程", en_us: "Finish Instance" }, ForwardAction: { Action: "Forward", Icon: "fa-mail-forward", Text: "转发", en_us: "Forward" }, AssistAction: { Action: "Assist", Icon: "fa-qrcode", Text: "协办", en_us: "Assist" }, ConsultAction: { Action: "Consult", Icon: "fa-phone", Text: "征询意见", en_us: "Consult" }, CirculateAction: { Action: "Circulate", Icon: "fa-share-square-o", Text: "传阅", en_us: "Circulate" }, AdjustParticipantAction: { Action: "AdjustParticipant", Icon: "fa-random", Text: "加签", en_us: "Plus" }, LockInstanceAction: { Action: "LockInstance", Icon: "fa-unlock-alt", Text: "锁定", en_us: "Lock" }, UnLockInstanceAction: { Action: "UnLockInstance", Icon: "fa-unlock-alt", Text: "解锁", en_us: "UnLock" }, CloseAction: { Action: "Close", Icon: "fa-times", Text: "关闭", en_us: "Close" } } }); //函数定义 jQuery.extend( $.MvcSheet, { //初始化 Init: function (_AfterMvcInit) { this.LoadData(_AfterMvcInit); }, //初始化工具栏 InitToolBar: function () { //工具栏 if ($.MvcSheet.Actions.length == 0) { $.MvcSheet.AddDefaultActions(); } var manager = $(".SheetToolBar").SheetToolBar($.MvcSheet.Actions); if ($.MvcSheetUI.SheetInfo.IsMobile) { var _Actions = []; var _GetProxy = function (_thatAction, _actionKey) { return { text: _thatAction.Text, handler: function () { _thatAction.ActionClick(); }, actionKey: _actionKey } } for (_Action in manager.ControlManagers) { var that = manager.ControlManagers[_Action]; if (that.MobileVisible) { _Actions.push(_GetProxy(that, _Action)); } }; var _ActionButton = $("#btnShowActions"); //无按钮 if (_Actions.length == 0) { _ActionButton.hide(); } //1个按钮 else if (_Actions.length == 1) { _ActionButton.text(_Actions[0].text); _ActionButton.click(function () { manager.ControlManagers[_Actions[0].actionKey].ActionClick(); }); } //多个按钮 else { _ActionButton.click(function () { //显示所有按钮 $.ui.actionsheet(_Actions); }); } } }, //初始化HiddenFields InitHiddenFields: function () { $("input:hidden").each(function () { if ($(this).data("type") == "SheetHiddenField") { $(this).SheetHiddenField(); } }); }, //加载数据 LoadData: function (_AfterMvcInit) { var loadText = "正在努力加载..."; $.MvcSheetUI.Loading = true; if (this.AjaxUrl.toLowerCase().indexOf("ismobile") > -1) loadText = ""; $.LoadingMask.Show(loadText, false); // 添加征询意见DOM元素,与数据项Sheet__ConsultComment关联 $(".divContent:last").append('<div class="row tableContent"><div class="col-md-2"><span data-type="SheetLabel" data-datafield="Sheet__ConsultComment">征询意见</span></div><div class="col-md-10"><div data-datafield="Sheet__ConsultComment" data-type="SheetComment"></div></div></div>'); this.GetSheet( { "Command": this.LOADKEY }, function (data) { var d1 = new Date(); //结束时间 $.MvcSheetUI.SheetInfo = data; if (data.Message) { alert(data.Message); if (data.Close) { $.MvcSheet.ClosePage(); return; } } $.MvcSheet.PreInit.apply(this, [$.MvcSheetUI.SheetInfo]); // 初始化事件 if ($.MvcSheet.InitFunctions.length > 0) { for (var index in $.MvcSheet.InitFunctions) { $.MvcSheet.InitFunctions[index].call(this, $.MvcSheetUI.SheetInfo); } } // 初始化语言 $.MvcSheet.PreInitLanguage(); //工具栏 $.MvcSheet.InitToolBar(); //判断元素类型,渲染成MvcControl var datafields = $("[" + $.MvcSheetUI.PreDataKey + $.MvcSheetUI.DataFieldKey.toLowerCase() + "]"); // 子表中的控件会在子表中进行初始化,故过滤掉子表模板行中的控件 var filterDataFields = []; // 正常顺序加载的控件 var delayDataFields = []; // 需要延迟加载的控件 for (var i = 0, len = datafields.length; i < len; i++) { var datafield = datafields; if (datafield.tagName.toLowerCase() == "table") { delayDataFields.push(datafield); } else if ($(datafield).parents("tr.template").length == 0) { filterDataFields.push(datafield); } } for (i = 0, len = filterDataFields.length; i < len; i++) { $(filterDataFields).SheetUIManager(); } for (i = 0, len = delayDataFields.length; i < len; i++) { $(delayDataFields).SheetUIManager(); } //$("[" + $.MvcSheetUI.PreDataKey + $.MvcSheetUI.DataFieldKey.toLowerCase() + "]").each(function () { // //初始化控件 // $(this).SheetUIManager(); //}); //HiddenFields $.MvcSheet.InitHiddenFields(); //移动端布局 if ($.MvcSheetUI.SheetInfo.IsMobile) { //是否找到默认审批控件 var _DefaultCommentFound = false; //将第一个可编辑的审批控件及其标题移到最首位 for (c in $.MvcSheetUI.ControlManagers) { if ($.MvcSheetUI.ControlManagers[c] instanceof $.MvcSheetUI.Controls.SheetComment) { var parent = $($.MvcSheetUI.ControlManagers[c].Element).parent("div"); var title = $($.MvcSheetUI.ControlManagers[c].Element).parent("div").prev(".col-md-2"); $(title).removeClass("col-md-2").addClass("bannerTitle"); var _Element = $.MvcSheetUI.ControlManagers[c].Element; //主容器 .panel-body var panelBody = $(_Element).parents("div.panel-body"); $(_Element).addClass("sheet-comment") if ($.MvcSheetUI.ControlManagers[c].Editable && !_DefaultCommentFound) { $(_Element).prependTo(panelBody); $(title).prependTo(panelBody); _DefaultCommentFound = true; } else { //非默认审批控件移到主体表单后 $(panelBody).append(title); $(title).after(_Element); } parent.hide(); } } $(".col-md-2,.col-md-4,col-md-10").filter(function () { return $(this).children().length == 0 && (!$(this).text() || $(this).text().trim() == "") }).hide(); } else { //处理不可见布局 $("div[class^='col-md-']").each(function () { var needHide = true; if ($(this).text()) { needHide = false; } else { var DataFieldElements = $(this).find("[" + $.MvcSheetUI.PreDataKey + $.MvcSheetUI.DataFieldKey.toLowerCase() + "]"); for (var i = 0; i < DataFieldElements.length; i++) { var manager = $(DataFieldElements).SheetUIManager(); if (!manager) { var datafield = $(DataFieldElements).attr($.MvcSheetUI.PreDataKey + $.MvcSheetUI.DataFieldKey.toLowerCase()); alert("数据项:{" + datafield + "}不存在"); return; } if (manager.Visiable) { needHide = false; break; } } } if (needHide) { $(this).hide(); } }); //处理不可见布局 $("div[class='row']").each(function () { if ($(this).find("div:visible[class^='col-md-']").length == 0) { $(this).hide(); } }); } if (typeof (_AfterMvcInit) == "function") { _AfterMvcInit(); } $.MvcSheet.RenderLanguage();// 多语言初始化 $.MvcSheet.Rendered.apply(this, [$.MvcSheetUI.SheetInfo]); $.MvcSheetUI.Loading = false; $.LoadingMask.Hide(); $.MvcSheet.Loaded.apply(this, [$.MvcSheetUI.SheetInfo]); if ($.MvcSheet.ReadyFunctions.length > 0) { for (var index in $.MvcSheet.ReadyFunctions) { $.MvcSheet.ReadyFunctions[index].call(this, $.MvcSheetUI.SheetInfo); } } var d2 = new Date(); //结束时间 var d3 = d2.getTime() - d1.getTime(); console.log("MvcLoad Used Time -> " + d3); }, function (e) { alert("Load ERROR->" + e.responseText); }); }, //MvcSheet完成事件 Ready: function (fn) { $.MvcSheet.ReadyFunctions.push(fn); }, PreInitLanguage: function () { var language = $.MvcSheetUI.SheetInfo.Language; if (typeof (SheetLanguages[language]) == "undefined" || SheetLanguages[language] == null) { language = "zh_cn"; } $.extend(SheetLanguages.Current, SheetLanguages[language]); }, RenderLanguage: function () { // 多语言初始化 var language = $.MvcSheetUI.SheetInfo.Language; if (language) { language = $.MvcSheetUI.PreDataKey + language.replace("-", "_"); $("span[" + language + "],label[" + language + "]").each(function () { $(this).html($(this).attr(language)); }); } }, PreInit: function () { }, PreLoad: function (fn) { $.MvcSheet.InitFunctions.push(fn); }, Loaded: function () { }, Rendered: function () { // 注册输入框鼠标样式 $("input,textarea,select").addClass($.MvcSheetUI.Css.inputMouseOut).unbind("mouseover.style").bind("mouseover.style", function () { var target = $(this); if (target.parent().is("li") && target.parent().parent().parent().is("div")) { target = target.parent().parent().parent(); } target.removeClass($.MvcSheetUI.Css.inputMouseOut).addClass($.MvcSheetUI.Css.inputMouseMove); }) .unbind("mouseenter.style").bind("mouseenter.style", function () { var target = $(this); if (target.parent().is("li") && target.parent().parent().parent().is("div")) { target = target.parent().parent().parent(); } target.removeClass($.MvcSheetUI.Css.inputMouseMove).addClass($.MvcSheetUI.Css.inputMouseEnter); }) .unbind("mouseout.style").bind("mouseout.style", function () { var target = $(this); if (target.parent().is("li") && target.parent().parent().parent().is("div")) { target = target.parent().parent().parent(); } target.removeClass($.MvcSheetUI.Css.inputMouseEnter).removeClass($.MvcSheetUI.Css.inputMouseMove).addClass($.MvcSheetUI.Css.inputMouseOut); }); // 原表单运行对象-待合并之后完全删除 $.MvcSheetUI.MvcRuntime = new Sheet(); }, //执行动作: {Action:"方法名称",Datas:[{数据项1},{数据项2}]} Action: function (actionControl) { if (typeof (actionControl.Mask) == "undefined" || actionControl.Mask) { $.LoadingMask.Show((actionControl.Text || SheetLanguages.Current.Doing) + "..."); } //执行动作标示 var actionName = actionControl.Action; //参数:[{数据项1},{数据项2},...]或["#ID1","#ID2",...]或["数据1","数据2"]或混合 var datas = actionControl.Datas; //console.log(actionName + ":Do..."); //构造数据项的值 var CommandParams = { Command: actionName }; var params = []; if (typeof (actionControl.LoadControlValue) == "undefined" || actionControl.LoadControlValue) { if (datas) { for (var i = 0; i < datas.length; i++) { if (datas.toString().indexOf("{") == 0) { var key = datas.replace("{", "").replace("}", ""); params.push($.MvcSheetUI.GetControlValue(key)); } else if (datas.toString().indexOf("#") == 0) { var key = datas.replace("#"); params.push($.MvcSheetUI.GetControlValue(datas)); } else { params.push(datas); } } } } else { params = datas; } CommandParams["Param"] = JSON.stringify(params); if (actionControl.PostSheetInfo) { CommandParams["MvcPostValue"] = JSON.stringify(this.GetMvcPostValue(this.actionName)); } var that = this; //提交到后台执行 this.PostSheet( CommandParams, function (data) { if (actionControl.OnActionDone) { actionControl.OnActionDone.apply(actionControl, [data]); } that.ResultHandler.apply(that, [actionControl, data]); if (actionControl.CloseAfterAction) { $.MvcSheet.ClosePage(); } $.LoadingMask.Hide(); }, undefined, actionControl.Async ); //console.log(actionName + ":Done..."); }, ConfirmAction: function (message, doneCallback) { if ($.ui && $.ui.popup) { $.ui.blockUI(0.5); $.ui.popup({ title: SheetLanguages.Current.Notice, message: message, doneText: SheetLanguages.Current.OK, cancelText: SheetLanguages.Current.Cancel, cancelOnly: false, doneCallback: function (r) { doneCallback(); } }) } else if (confirm(message)) { doneCallback(); } }, //校验 ActionValidata: function (actionControl, effective) { var result = true; if (this.Validate) { result = this.Validate.apply(actionControl); } if (result || result == undefined) { return $.MvcSheetUI.Validate(effective); } else return false; }, //保存 Save: function (actionControl) { if (!$.MvcSheet.ActionValidata(actionControl, true)) return false; $.LoadingMask.Show(SheetLanguages.Current.Saving); var SheetPostValue = this.GetMvcPostValue(this.Action_Save); var that = this; this.PostSheet( { Command: this.Action_Save, MvcPostValue: JSON.stringify(SheetPostValue) }, function (data) { that.ResultHandler.apply(that, [actionControl, data]); } ); }, //提交 Submit: function (actionControl, text, destActivity, postValue, groupValue) { if (!$.MvcSheet.ActionValidata(actionControl)) return false; var that = this; $.MvcSheet.ConfirmAction(SheetLanguages.Current.ConfirmDo + "[" + text + "]" + SheetLanguages.Current.Operation + "?", function () { $.LoadingMask.Show(SheetLanguages.Current.Sumiting); var SheetPostValue = that.GetMvcPostValue(that.Action_Submit, destActivity, postValue, groupValue); that.PostSheet( { Command: that.Action_Submit, MvcPostValue: JSON.stringify(SheetPostValue) }, function (data) { that.ResultHandler.apply(that, [actionControl, data]); }); }) }, // 控件初始化事件 ControlInit: function () { }, // 控件初始化之前函数 ControlPreRender: function () { }, // 控件加载完成事件 ControlRendered: function () { }, //驳回 Reject: function (actionControl, destActivity) { //if (!$.MvcSheet.ActionValidata(actionControl)) return false; var that = this; $.MvcSheet.ConfirmAction(SheetLanguages.Current.ConfirmDo + "[驳回]" + SheetLanguages.Current.Operation + "?", function () { $.LoadingMask.Show(SheetLanguages.Current.Rejecting); var SheetPostValue = that.GetMvcPostValue(that.Action_Reject, destActivity); that.PostSheet( { Command: that.Action_Reject, MvcPostValue: JSON.stringify(SheetPostValue) }, function (data) { that.ResultHandler.apply(that, [actionControl, data]); }); }) }, //结束流程 FinishInstance: function (actionControl) { var that = this; $.LoadingMask.Show(SheetLanguages.Current.Finishing); var SheetPostValue = that.GetMvcPostValue(that.Action_FinishInstance); this.PostSheet( { Command: that.Action_FinishInstance, MvcPostValue: JSON.stringify(SheetPostValue) }, function (data) { that.ResultHandler.apply(that, [actionControl, data]); }); }, //取回流程 RetrieveInstance: function (actionControl) { $.LoadingMask.Show(SheetLanguages.Current.Retrieving); var that = this; this.GetSheet( { Command: this.Action_RetrieveInstance }, function (data) { that.ResultHandler.apply(that, [actionControl, data]); }); }, //获取Mvc表单传给后台的数据 GetMvcPostValue: function (actionName, destActivity, postValue, groupValue) { var SheetPostValue = { Command: actionName, DestActivityCode: destActivity, PostValue: postValue, // 获取或设置提交时的岗位身份 ERROR,需要获取 GroupValue: groupValue, // 获取或设置提交时的组身份 ERROR,需要获取 BizObjectId: $.MvcSheetUI.SheetInfo.BizObjectID, InstanceId: $.MvcSheetUI.SheetInfo.InstanceId, BizObject: {}//当前表单的数据项集合值 }; SheetPostValue.BizObject.DataItems = $.MvcSheetUI.SaveSheetData(actionName); SheetPostValue.Priority = $.MvcSheetUI.Priority; SheetPostValue.HiddenFields = $.MvcSheetUI.HiddenFields; //if($.MvcSheetUI.PrioritySelector!=null) // ***= $.MvcSheetUI.PrioritySelector.GetVale(); return SheetPostValue; }, //回调函数处理 ResultHandler: function (actionControl, data) { if ($.MvcSheet.ActionDone) { $.MvcSheet.ActionDone.apply(actionControl, [data]) } if (data == "undefined" || data == null) return; if (data.Successful) { if ($.MvcSheetUI.SheetInfo.IsMobile) { window.location.href = data.MobileReturnUrl; } else { if (data.ClosePage) { // TODO:关闭当前页面,并且刷新父页面 $.MvcSheet.ClosePage(); } else if (data.Url) { window.location.href = data.Url; } else if (data.Message) { //alert(data.Message); if (data.Refresh) { var href = window.location.href; href = href.replace("&T=", "&T=" + Math.round(Math.random() * 100, 0)); window.location.href = href; } } else { // 不需要 Reload // window.location.reload(); } } } else { //Error:错误提示方式需要修改 if (data.Errors) { for (var i = 0; i < data.Errors.length; i++) { alert(data.Errors); } } } $.LoadingMask.Hide(); }, //关闭页面 ClosePage: function () { if (window.opener != null && window.opener.location != null && window.opener.location.href != window.location.href && $.MvcSheetUI.QueryString("Mode").toLowerCase() != "originate") { window.opener.location.reload(); } window.opener = null; window.open("", "_self"); window.close(); }, //添加默认的事件 AddDefaultActions: function () { this.Actions.splice(0, this.Actions.length, this.RetrieveInstanceAction, this.SaveAction, this.ViewInstanceAction, this.PreviewParticipantAction, this.PrintAction, this.ViewedAction, this.CancelInstanceAction, this.RejectAction, this.SubmitAction, this.FinishInstanceAction, this.ForwardAction, this.AssistAction, this.ConsultAction, this.CirculateAction, this.AdjustParticipantAction, this.LockInstanceAction, this.UnLockInstanceAction, this.CloseAction ); }, //添加自定义事件 AddAction: function (option) { // Actions.length为0时,说明Load的异步返回数据还没返回,添加到Actions里面就可以了,系统Load回来会执行 if ($.MvcSheetToolbar.AddButton) { $.MvcSheetToolbar.AddButton(option); } else { if (this.Actions.length == 0) { this.AddDefaultActions(); } } if (option.PreAction) { for (var i in this.Actions) { if (this.Actions.Action == option.PreAction) { if (i < this.Actions.length - 1) i++; this.Actions.splice(i, 0, option); break; } } } else { this.Actions.push(option); } }, //用get方式可传送简单数据,但大小一般限制在1KB下,数据追加到url中发送(http的header传送), //也就是说,浏览器将各个表单字段元素及其数据按照URL参数的格式附加在请求行中的资源路径后面。 //另外最重要的一点是,它会被客户端的浏览器缓存起来,那么,别人就可以从浏览器的历史记录中,读取到此客户的数据,比如帐号和密码等。 //因此,在某些情况下,get方法会带来严重的安全性问题;GET方式传送数据量小,处理效率高,安全性低,会被缓存,而POST反之 GetSheet: function (data, callback, errorhandler, async) { $.ajax({ type: "GET", url: this.AjaxUrl, data: data, dataType: "json", async: async != null ? async : true, success: callback, error: errorhandler }); }, //当使用POST方式时,浏览器把各表单字段元素及其数据作为HTTP消息的实体内容发送给Web服务器, //而不是作为URL地址的参数进行传递,使用POST方式传递的数据量要比使用GET方式传送的数据量大的多 PostSheet: function (data, callback, errorhandler, async) { var ajaxUrl = this.AjaxUrl; if (ajaxUrl.toLowerCase().indexOf("&bizobjectid=") == -1) { ajaxUrl = this.AjaxUrl + "&BizObjectID=" + $.MvcSheetUI.SheetInfo.BizObjectID; } if (typeof (async) == "undefined") async = true; $.ajax({ type: "POST", url: ajaxUrl, data: data, dataType: "json", async: async, success: callback, error: errorhandler }); } }); |
|
8楼#
发布于:2018-06-22 11:16
|
|