哦,页面还有一些其他操作,最耗时的是spread.fromJSON(json),一共用了11秒多
我在后台用zip压缩了,放到前台解压。这个话费了大约2秒的时间
加载了json之后,后继操作尽管使用了spread.isPaintSuspended(true),仍然很慢
也使用过spread.suspendCalcService(true),但是没有效果
总得来说,耗时操作发生在下面几个操作上
spread.fromJSON、sheet.recalcAll()、
sheet.getCell(xx, xx).locked (xxx)、
sheet.setValue(xx, xx, xxx)
根据我的理解,使用了spread.isPaintSuspended(true)之后,这些操作应该不会太耗费时间才对
但是对spread的操作也耗费了接近10秒的时间
麻烦帮着看下可能是哪儿的问题。
我这边使用console打印了时间,整个页面耗时超过22秒,结果如下:
JSP初始化: 1511449963080
document complete: 146
assemble complete: 175
new GC.Spread.Sheets.Workbook complete: 377
data loaded: 901
unzip completed: 2703
fromJSON completed: 14122
bind completed: 14135
visible completed: 14135
recalcAll completed: 15871
lockSheet completed: 16088
lockD completed: 17862
lockPriceCell completed: 19171
bind rateObject completed: 19172
bind EditEnded completed: 19173
!referenceReviewData completed: 22568
$(function() {
console.log("document complete:", new Date().getTime() - t1); //当前时间:1511449963080
checkPrice = reviewData.reviewCost;
assemble();
console.log("assemble complete:", new Date().getTime() - t1); //总耗时 146
loadSpreadData();
//初始化工作流信息
initFixFlow();
});
function loadSpreadData() {
zip.workerScriptsPath = "/emp/static/js/spread/patternReview/";
if (spread == null) {
spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadDiv'), {});
console.log("new GC.Spread.Sheets.Workbook complete:", new Date().getTime() - t1); //总耗时 377
}
$.messager.progress({title:'初始化', msg:'正在加载数据...'});
$.ajax({
url: "/emp/spread/patternReview/" + (referenceReviewData != null ? referenceReviewData.id : reviewData.id),
type: "POST",
dataType: 'binary',
processData: false,
success: function(blob){
console.log("data loaded:", new Date().getTime() - t1); //总耗时 901
zip.createReader(new zip.BlobReader(blob), function(reader) {
reader.getEntries(function(entries) {
if (entries.length) {
entries[0].getData(new zip.TextWriter(), function(text) {
console.log("unzip completed:", new Date().getTime() - t1); //总耗时 2703
spread.fromJSON(JSON.parse(text));
console.log("fromJSON completed:", new Date().getTime() - t1); //总耗时 14122
spread.isPaintSuspended(true);
//spread.suspendCalcService(true);
spread.options.allowUndo = true;
spread.options.allowUserDragDrop = false;
//spread.allowUndo(true);
//spread.getActiveSheet().canUserDragDrop(false);
spread.getActiveSheet().bind(GC.Spread.Sheets.Events.SelectionChanging, function (e, info) {
var sumValue = 0;
var cellCount = 0;
var selections = info.sheet.getSelections();
for (var i = 0; i < selections.length; i++) {
for (var row = selections[i].row; row < selections[i].row + selections[i].rowCount; row++) {
for (var col = selections[i].col; col < selections[i].col + selections[i].colCount; col++) {
if (sheet.getValue(row, col) && !isNaN(sheet.getValue(row, col))) {
var cellValue = sheet.getValue(row, col) * 1;
if (isNaN(cellValue) == false) {
sumValue += cellValue;
}
}
cellCount++;
}
}
}
$("#count").html(cellCount);
$("#sum").html(sumValue.toFixed(2));
$("#count1").html(cellCount);
$("#sum1").html(sumValue.toFixed(2));
});
console.log("bind completed:", new Date().getTime() - t1); //总耗时 14135
for (var i = 1; i < spread.sheets.length; i++) {
spread.sheets[i].visible(false);
}
console.log("visible completed:", new Date().getTime() - t1); //总耗时 14135
//给excel赋值公司代码
if (reviewData.modelTypeName == "塑模") {
sheet = spread.getSheetFromName('评审');
sheet.recalcAll();
console.log("recalcAll completed:", new Date().getTime() - t1); //总耗时 15871
lockSheet();
console.log("lockSheet completed:", new Date().getTime() - t1); //总耗时 16088
sheet.setValue(0, 2, '1100');
lockD("SM");//用于低签单毛利说明限制
console.log("lockD completed:", new Date().getTime() - t1); //总耗时 17862
if (reviewData.dataStatus == "待核算" || reviewData.dataStatus == "待成本主管审核") {
lockPriceCell(true, true);
} else if (reviewData.dataStatus == "待报价" && (reviewData.approveStatus == "初始" || reviewData.approveStatus == "暂存")) {
lockPriceCell(false, true);
} else if (false) {
lockPriceCell(false, false);
} else if (reviewData.dataStatus == "待成交" && (reviewData.approveStatus == "完成" || reviewData.approveStatus == "暂存")) {
lockPriceCell(true, false);
} else {
lockPriceCell(true, true);
}
console.log("lockPriceCell completed:", new Date().getTime() - t1); //总耗时 19171
var option = {allowResizeColumns:true};
sheet.options.protectionOptions = option;
sheet.options.isProtected = true;
if ('check' == 'view') {
} else {
switch (sheet.getValue(39, 17)) {
case "美元" : sheet.setValue(43, 20, rateObject.USD); sheet.setValue(39, 20, rateObject.USD); break;
case "欧元" : sheet.setValue(43, 20, rateObject.EUR); sheet.setValue(39, 20, rateObject.EUR); break;
case "日元" : sheet.setValue(43, 20, rateObject.JPY); sheet.setValue(39, 20, rateObject.JPY); break;
case "人民币" : sheet.setValue(43, 20, 1); sheet.setValue(39, 20, 1); break;
}
sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, selectMaterial);
sheet.bind(GC.Spread.Sheets.Events.ValueChanged, function (sender, args) {
if (args.col == 17 && args.row == 39){
switch (args.newValue) {
case "美元" : sheet.setValue(43, 20, rateObject.USD); sheet.setValue(39, 20, rateObject.USD); break;
case "欧元" : sheet.setValue(43, 20, rateObject.EUR); sheet.setValue(39, 20, rateObject.EUR); break;
case "日元" : sheet.setValue(43, 20, rateObject.JPY); sheet.setValue(39, 20, rateObject.JPY); break;
case "人民币" : sheet.setValue(43, 20, 1); sheet.setValue(39, 20, 1); break;
}
}
});
console.log("bind rateObject completed:", new Date().getTime() - t1); //总耗时 19172
sheet.bind(GC.Spread.Sheets.Events.EditEnded, function (sender, args) {
if (reviewData.dataStatus == "待核算") {
if (reviewData.modelTypeName == "塑模" && args.col == 24 && args.row == 3) {
var editedText = sheet.getValue(args.row, args.col);
$.messager.confirm('询问', '您确定要参考核算单【' + editedText + '】?',function(r){
if (r) {
try {
$.messager.progress({title:'参考', msg:'加载中...'});
$.ajax({
url : contextPath + '/spread/patternReview/costOrder',
type : "POST",
dataType : "json",
data : {
costOrderNo : sheet.getValue(args.row, args.col),
modelType : 'suM001',
},
success : function(result) {
if (result) {
referenceReviewData = result;
//reviewData.reLoad = true;
setTimeout(loadSpreadData, 0);
} else {
$.messager.alert("提示", "核算单【" + editedText + "】不存在!", "error");
}
$.messager.progress('close');
},
error : function(data){
$.messager.alert("错误", "加载参照核算单号失败!", "error");
$.messager.progress('close');
}
});
} catch (e) {
$.messager.alert("错误", "加载参照核算单号失败!", "error");
$.messager.progress('close');
}
}
});
} else {
}
}
});
console.log("bind EditEnded completed:", new Date().getTime() - t1); //总耗时 19173
}
try {
if (referenceReviewData != null) {
sheet.setValue(0, 20, reviewData.costOrderNo); //订单编号
sheet.setValue(2, 8, reviewData.customerName); //客户名称
sheet.setValue(2, 3, reviewData.projectName); //项目名称
sheet.setValue(6, 8, reviewData.mouldName); //模具名称
sheet.setValue(2, 14, reviewData.doorTypeName); //门类
sheet.setValue(7, 3, reviewData.appearanceRequire); //外观要求
sheet.setValue(8, 3, reviewData.runners); //流道
sheet.setValue(9, 3, reviewData.sendAddress); //发送地
sheet.setValue(7, 8, reviewData.shotTime); //模具寿命
console.log("referenceReviewData completed:", new Date().getTime() - t1); //总耗时
} else {
sheet.setValue(0, 20, reviewData.costOrderNo); //订单编号
sheet.setValue(2, 8, reviewData.customerName); //客户名称
sheet.setValue(2, 3, reviewData.projectName); //项目名称
sheet.setValue(6, 8, reviewData.mouldName); //模具名称
sheet.setValue(2, 14, reviewData.doorTypeName); //门类
sheet.setValue(7, 3, reviewData.appearanceRequire); //外观要求
sheet.setValue(8, 3, reviewData.runners); //流道
sheet.setValue(9, 3, reviewData.sendAddress); //发送地
sheet.setValue(7, 8, reviewData.shotTime); //模具寿命
var techRequire = '外观要求:' + defVal(reviewData.appearanceRequire) + ';'
+ '产品材料: ' + defVal(reviewData.productMaterial) + '; '
+ '皮纹费: ' + defVal(reviewData.viewTextureExes) + '; '
+ '结构说明: ' + defVal(reviewData.frameNote) + '; '
+ '前模: ' + defVal(reviewData.cavityInsert) + '; '
+ '后模: ' + defVal(reviewData.coreInsert) + '; '
+ '热流道: ' + defVal(reviewData.brand)
+ '-' + defVal(reviewData.frame)
+ '-' + defVal(reviewData.pointSize)
+ '-' + defVal(reviewData.runnerType);
sheet.setValue(5, 3, techRequire); //技术要求
sheet.setValue(8, 26, reviewData.cavityNum); //腔数
sheet.setValue(20, 19, reviewData.moldAmount); //发样数(开模数)
sheet.setValue(8, 8, reviewData.feedingMode); //供料方式
//sheet.setValue(10, 3, reviewData.feedingMode); //备注
//sheet.setValue(46, 5, reviewData.transPrice); //样件运输单价
sheet.setValue(56, 26, reviewData.viewMouldExes); //模具运费
//sheet.setValue(48, 5, reviewData.aftersalesExes); //售后服务费
//sheet.setValue(42, 5, reviewData.textureExes); //皮纹费
sheet.setValue(33, 26, reviewData.frameNote); //结构说明
if(reviewData.otherNote){
sheet.setValue(10, 3, reviewData.otherNote); //备注
}else{
sheet.setValue(10, 3, reviewData.note); //备注
}
//sheet.setValue(35, 17, reviewData.reviewCost); //核算成本
sheet.setValue(38, 17, reviewData.firstOffer); //首轮报价
sheet.setValue(42, 17, reviewData.isColosed); //是否成交:1成交,2未成交
sheet.setValue(44, 17, reviewData.colosedOffer); //成交价
sheet.setValue(48, 17, reviewData.instructGrossProfit); //责成毛利
sheet.setValue(49, 17, reviewData.profitChief); //毛利负责人
sheet.setValue(55, 26, reviewData.viewTransPrice); //样件运输单价(评审)
sheet.setValue(47, 11, reviewData.viewMouldExes); //模具运费(评审)
//sheet.setValue(48, 11, reviewData.viewAftersalesExes); //售后服务费(评审)
sheet.setValue(60, 26, reviewData.viewAftersalesExes); //售后服务费(评审)
sheet.setValue(42, 11, reviewData.viewTextureExes); //皮纹费(评审)
sheet.getValue(51, 4,reviewData.lowSignBillInstruction);//低毛利说明
if (reviewData.dataStatus == "待核算") {
sheet.setValue(36, 17, reviewData.defaultTargetGrossProfit); //目标毛利
}
if(reviewData.costOrderNo == '6000122102'){
sheet.setValue(37, 17, '0.43424');
}else if(reviewData.costOrderNo == '6000122101'){
sheet.setValue(37, 17, '0.43424');
}
materialTotal = defaultVal(sheet.getValue(36,7));
manufacturing = defaultVal(sheet.getValue(41,7));
moldTesting = defaultVal(sheet.getValue(43,7));
change = defaultVal(sheet.getValue(44,7));
console.log("!referenceReviewData completed:", new Date().getTime() - t1); //总耗时 22568
}
//根绝角色(1000001062设计成本查看),判断是否能看到数据
if(false){
var views = [];
views.push('36,17','37,17','38,17','39,17','39,20','40,17','43,17','43,20','44,17','45,17','46,17','47,17');
setView(views);
console.log("setView completed:", new Date().getTime() - t1);
}
//签单毛利率>目标毛利率-3% 时 设置在营销总监审批成交价 那一步不能填责成毛利率和毛利保证人
if(reviewData.approveStatus == '营销总监审核' && reviewData.colosedGrossProfit > reviewData.targetGrossProfit-0.03){
sheet.getCell(48, 17).locked(true);
sheet.getCell(48, 17).backColor("#CCFECC");
sheet.getCell(49, 17).locked(true);
sheet.getCell(49, 17).backColor("#CCFECC");
console.log("approveStatus completed:", new Date().getTime() - t1);
}
} finally {
}
//spread.suspendCalcService(false);
spread.isPaintSuspended(false);
spread.repaint();
var pictures = sheet.pictures.all();
for (var i = 0; i < pictures.length; i++) {
if (pictures[i].name() == "f2") {
document.getElementById("preview").src = pictures[i].src();
$("#spreadDiv").on('click', pictureClick);
viewer = new Viewer(document.getElementById("preview"), {});
}
}
$.messager.progress('close');
});
}
});
});
}
});
} |