我当前有个项目 需要做一个图片的生成 使用preload调用写好的页面进行生成 ,页面在加载的时候就会生成图片 , 现在有个问题就是 页面是在数据提交后调用的预加载进行加载,我不需要显示出来,因为只是功能性页面 , app启动后的第一次是正常的可以使用 第二次不起作用 当我的数据提交后页面会做window.location.reload() 在这个页面的所有preload()怎么做刷新重新加载?
以下是调用预加载的代码
if(data != 'false') {
/////////////////打印start*******/////
var pringPage = mui.preload({
id: 'prints.html',
url: 'prints.html',
extras:{
tzsId:data,
year: feedback.year.value,
lines: feedback.lines.value,
towers: feedback.towers.value,
positionName: feedback.positionName.value,
nowDes: feedback.nowDes.value,
question: feedback.question.value,
answer: feedback.answer.value,
imageList: JSON.stringify(imagePaths), //上传图片
jSignatureImg: feedback.jSignatureImg.src, //签名图片
Jpeopers: feedback.Jpeopers.value,
Jtel: feedback.Jtel.value,
peopers: feedback.peopers.value,
tel: feedback.tel.value,
company: feedback.company.value,
s_dept: dept
}
});
/////**********打印end*****************////
console.log("上传成功");
feedback.clearForm();
setTimeout(function() {
window.location.reload();
}, 300);
以下是需要执行的页面代码
<script type="text/javascript">
console.log("=======>>> Print Page Start ·······");
mui.init();
mui.plusReady(function() {
var _dateY = new Date().getFullYear();
var _dateM = new Date().getMonth() + 1;
var _dateD = new Date().getDate();
var _date = _dateY + '年' + _dateM + '月' + _dateD + '日';
var self = plus.webview.currentWebview();
var tzsId = self.tzsId;
if(tzsId == 'undefined' || tzsId == '' || tzsId == null) {
return mui.toast('通知书生成失败!');
}
var year = self.year;
var lines = self.lines;
var towers = self.towers;
var positionName = self.positionName;
var nowDes = self.nowDes;
var question = self.question;
var answer = self.answer;
var jSignatureImg = self.jSignatureImg;
var naming = self.naming;
var peopers = self.peopers;
var tel = self.tel;
var Jpeopers = self.Jpeopers;
var Jtel = self.Jtel;
var company = self.company;
var dept = self.s_dept;
var _count = '';
//查询统计数量 按照年份
mui.ajax(_httpUrl + 'api/appuser/getTzsCountByDept', {
data: {
DEPT_NAME: dept
},
dataType: 'json',
type: 'post',
timeout: 30000,
success: function(data) {
_count = data;
},
error: function(xhr, type, errorThrown) {
mui.toast('网络异常,请稍后再试!');
console.log('网络异常,请稍后再试!');
}
});
mui.later(function() {
/**
*数据绑定填充
*/
html2canvas(document.getElementsByTagName("body"), {
allowTaint: true,
taintTest: false,
height: $("#content").outerHeight(),
onrendered: function(canvas) {
canvas.id = "mycanvas";
//document.body.appendChild(canvas);
//生成base64图片数据
var dataUrl = canvas.toDataURL();
var tzsImgPath = '';
var datas = {
imgSrcStr: dataUrl,
modelName: '隐患通知书'
};
console.log("=======>>> 图片存储 Start·····");
$.ajax({
type: "post",
url: _httpUrl + 'api/img/imgUpload',
async: true,
data: datas,
dataType: 'json',
success: function(data) {
if(data.error == "success") {
var imgPath = JSON.stringify(data.imgPath);
console.log('通知书生成后图片存储路径:' + imgPath.substr(1, imgPath.length - 2));
console.log("将要更新的通知书ID:"+tzsId);
$.ajax({
type: "post",
url: _httpUrl + 'api/appuser/updataTzsDyimgById',
async: true,
data: {
ID: tzsId,
DYIMG: imgPath.substr(1, imgPath.length - 2)
},
dataType: 'json ',
success: function(data) {
if(data) {
console.log('通知书图片更新成功!');
} else {
console.log('通知书图片更新失败!');
}
console.log('完成通知书生成及数据更新!');
self.clear();
mui.back();
},
error: function(xhr, type, errorThrown) {
mui.toast('网络异常,请稍后再试!');
console.log('网络异常,请稍后再试!');
}
});
} else {
console.log('图片上传失败:' + data.error);
}
},
error: function(xhr, type, errorThrown) {
mui.toast('网络异常,请稍后再试!');
console.log('网络异常,请稍后再试!');
}
});
}
});
}, 500);
})
</script>
注: 当前在这个功能页面reload自己行不通 他会死循环去生成图片
0 个回复