Parcourir la source

完善网页版查询表单设计器

master
jacky6024 il y a 7 ans
Parent
révision
80bf213efe
  1. 1
      ureport2-console/src/main/java/com/bstek/ureport/console/html/HtmlPreviewServletAction.java
  2. 12
      ureport2-console/src/main/resources/ureport-asserts/js/preview.bundle.js
  3. 7
      ureport2-console/src/main/resources/ureport-html/html-preview.html
  4. 1
      ureport2-js/package.json
  5. 26
      ureport2-js/src/Test.js
  6. 2
      ureport2-js/src/dialog/PDFPrintDialog.js
  7. 131
      ureport2-js/src/preview.js

1
ureport2-console/src/main/java/com/bstek/ureport/console/html/HtmlPreviewServletAction.java

@ -284,6 +284,7 @@ public class HtmlPreviewServletAction extends RenderPageServletAction {
}
htmlReport.setChartDatas(report.getContext().getChartDataMap().values());
htmlReport.setContent(html);
htmlReport.setTotalPage(report.getPages().size());
htmlReport.setStyle(reportDefinition.getStyle());
htmlReport.setSearchFormData(reportDefinition.buildSearchFormData());
htmlReport.setReportAlign(report.getPaper().getHtmlReportAlign().name());

12
ureport2-console/src/main/resources/ureport-asserts/js/preview.bundle.js

File diff suppressed because one or more lines are too long

7
ureport2-console/src/main/resources/ureport-html/html-preview.html

@ -63,7 +63,7 @@ ${upSearchFormHtml}
#if($tools.paging)
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" style="background:#f8f8f8;border:none;color:#337ab7">
#if($totalPage>0)
#if($pageIndex>0)
分页预览
#else
预览
@ -84,14 +84,15 @@ ${upSearchFormHtml}
</ul>
</div>
#end
#if($totalPage>0)
#if($pageIndex>0)
<span id='pagingContainer' style="font-size:14px;margin-left:1px;color:#337ab7">
共${totalPage}页
<span id='totalPageLabel'>${totalPage}</span>
<select id="pageSelector" class="form-control" style="display:inline-block;width:inherit;font-size:13px;height:28px;margin-top:2px">
#foreach($index in [1..$totalPage])
<option>${index}</option>
#end
</select>
<span id='pageLinkContainer'></span>
</span>
#end
</div>

1
ureport2-js/package.json

@ -40,6 +40,7 @@
"css-loader": "^0.26.1",
"expose-loader": "^0.7.1",
"file-loader": "^0.9.0",
"json-loader": "^0.5.7",
"redux-devtools": "^3.3.1",
"redux-devtools-dock-monitor": "^1.1.1",
"redux-devtools-log-monitor": "^1.1.1",

26
ureport2-js/src/Test.js

@ -0,0 +1,26 @@
var test = {
"type": "pie",
"data": {
"labels": ["硕士", "大专", "博士", "本科", "高中", "大学", "研究生", "中专", "博士后", "小学"],
"datasets": [{
"label": "1",
"backgroundColor": ["rgb(255, 99, 132)", "rgb(54, 162, 235)", "rgb(255, 205, 86)", "rgb(75, 192, 192)", "rgb(255, 159, 64)", "rgb(153,102,255)", "rgb(53,202,25)", "rgb(201,203,207)", "rgb(205,92,92)", "rgb(255,127,80)"],
"data": [18455.0, 10966.0, 110687.0, 36694.0, 52771.0, 44232.0, 27544.0, 8150.0, 17595.0, 4408.0]
}, {
"label": "0",
"backgroundColor": ["rgb(54, 162, 235)", "rgb(255, 205, 86)", "rgb(75, 192, 192)", "rgb(255, 159, 64)", "rgb(153,102,255)", "rgb(53,202,25)", "rgb(201,203,207)"],
"data": [14349.0, 27926.0, 15275.0, 7341.0, 564716.0, 5091.0, 6431.0, 42321.0]
}]
},
"options": {
"title": {
"display": true,
"text": "我的图表",
"position": "top",
"fontSize": 14,
"fontColor": "#666",
"fontStyle": "bold",
"padding": "10"
},
}
}

2
ureport2-js/src/dialog/PDFPrintDialog.js

@ -209,7 +209,7 @@ export default class PDFPrintDialog{
if(this.iFrame){
return;
}
const urlParameters=window.location.search;
const urlParameters=buildLocationSearchParameters();
const h=$(window).height();
const url=window._server+"/pdf/show"+urlParameters+"&_p=1";
this.iFrame=$(`<iframe name="_iframe_for_pdf_print" style="width: 100%;height:${h}px;margin-top: 5px;border:solid 1px #c2c2c2" frameborder="0" src="${url}"></iframe>`);

131
ureport2-js/src/preview.js

@ -20,8 +20,8 @@ $(document).ready(function(){
if(language!=='zh-cn'){
window.i18n=en18nJsonData;
}
const urlParameters=window.location.search;
$('.ureport-print').click(function(){
const urlParameters=buildLocationSearchParameters();
const url=window._server+'/preview/loadPrintPages'+urlParameters;
showLoading();
$.ajax({
@ -50,12 +50,14 @@ $(document).ready(function(){
let directPrintPdf=false,index=0;
const pdfPrintDialog=new PDFPrintDialog();
$(`.ureport-pdf-print`).click(function(){
const urlParameters=buildLocationSearchParameters();
$.get(window._server+'/preview/loadPagePaper'+urlParameters,function(paper){
pdfPrintDialog.show(paper);
});
});
$(`.ureport-pdf-direct-print`).click(function(){
showLoading();
const urlParameters=buildLocationSearchParameters();
const url=window._server+'/pdf/show'+urlParameters+`&_i=${index++}`;
const iframe=window.frames['_print_pdf_frame'];
if(!directPrintPdf){
@ -70,27 +72,69 @@ $(document).ready(function(){
iframe.location.href=url;
});
$(`.ureport-export-pdf`).click(function(){
const urlParameters=buildLocationSearchParameters();
const url=window._server+'/pdf'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-word`).click(function(){
const urlParameters=buildLocationSearchParameters();
const url=window._server+'/word'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-excel`).click(function(){
const urlParameters=buildLocationSearchParameters();
const url=window._server+'/excel'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-excel-paging`).click(function(){
const urlParameters=buildLocationSearchParameters();
const url=window._server+'/excel/paging'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-excel-paging-sheet`).click(function(){
const urlParameters=buildLocationSearchParameters();
const url=window._server+'/excel/sheet'+urlParameters;
window.open(url,'_blank');
});
});
window.buildLocationSearchParameters=function(exclude){
let urlParameters=window.location.search;
if(urlParameters.length>0){
urlParameters=urlParameters.substring(1,urlParameters.length);
}
let parameters={};
const pairs=urlParameters.split('&');
for(let item of pairs){
if(item===''){
continue;
}
const param=item.split('=');
let key=param[0];
if(key===exclude){
continue;
}
let value=param[1];
parameters[key]=value;
}
if(window.searchFormParameters){
for(let key in window.searchFormParameters){
if(key===exclude){
continue;
}
const value=window.searchFormParameters[key];
if(value){
parameters[key]=value;
}
}
}
let p='?';
for(let key in parameters){
p+='&'+key+'='+parameters[key];
}
return p;
};
function buildPrintStyle(paper){
const marginLeft=pointToMM(paper.leftMargin);
const marginTop=pointToMM(paper.topMargin);
@ -118,6 +162,44 @@ function buildPrintStyle(paper){
`;
return style;
};
window.buildPaging=function(file,pageIndex,totalPage,customParameters,tools){
if(totalPage===0){
return;
}
const pageSelector=$('#pageSelector');
pageSelector.change(function(){
const parameters=window.buildLocationSearchParameters('_i');
//let url=window._server+`/preview?_u=${file}&_i=${$(this).val()}&_t=${tools}&${customParameters}`;
let url=window._server+`/preview${parameters}&_i=${$(this).val()}`;
window.open(url,'_self');
});
pageSelector.val(pageIndex);
if(totalPage===1){
return;
}
const pagingContainer=$('#pageLinkContainer');
if(pageIndex>1){
let url=window._server+`/preview?_u=${file}&_t=${tools}`;
url+=`&_i=${pageIndex-1}&${customParameters}`;
const prevPage=$(`<button type="button" class="btn btn-link btn-sm">上一页</button>`);
pagingContainer.append(prevPage);
prevPage.click(function(){
window.open(url,'_self');
});
}
if(pageIndex<totalPage){
let url=window._server+`/preview?_u=${file}&_t=${tools}`;
url+=`&_i=${pageIndex+1}&${customParameters}`;
const nextPage=$(`<button type="button" class="btn btn-link btn-sm">下一页</button>`);
pagingContainer.append(nextPage);
nextPage.click(function(){
window.open(url,'_self');
});
}
};
window._intervalRefresh=function(value,file,totalPage,customParameters){
if(!value){
return;
@ -202,26 +284,61 @@ window._buildChart=function(canvasId,chartJson){
};
window.submitSearchForm=function(file,customParameters){
const formData={};
window.searchFormParameters={};
for(let fun of window.formElements){
const json=fun.call(this);
for(let key in json){
formData[key]=json[key];
let value=json[key];
value=encodeURI(value);
value=encodeURI(value);
window.searchFormParameters[key]=value;
}
}
let url=window._server+"/preview/loadData?_u="+file+"";
if(customParameters){
url+=customParameters;
const parameters=window.buildLocationSearchParameters('_i');
let url=window._server+"/preview/loadData"+parameters;
const pageSelector=$(`#pageSelector`);
if(pageSelector.length>0){
url+='&_i=1';
}
$.ajax({
url,
type:'POST',
data:formData,
success:function(report){
const tableContainer=$(`#_ureport_table`);
tableContainer.empty();
tableContainer.append(report.content);
_buildChartDatas(report.chartDatas);
const totalPage=report.totalPage;
if(pageSelector.length>0){
pageSelector.empty();
for(let i=1;i<=totalPage;i++){
pageSelector.append(`<option>${i}</option>`);
}
const pageIndex=report.pageIndex || 1;
pageSelector.val(pageIndex);
$('#totalPageLabel').html(totalPage);
const urlParameters=window.buildLocationSearchParameters('_i');
const pagingContainer=$('#pageLinkContainer');
pagingContainer.empty();
if(pageIndex>1){
let url=window._server+`/preview`+urlParameters;
url+=`&_i=${pageIndex-1}`;
const prevPage=$(`<button type="button" class="btn btn-link btn-sm">上一页</button>`);
pagingContainer.append(prevPage);
prevPage.click(function(){
window.open(url,'_self');
});
}
if(pageIndex<totalPage){
let url=window._server+`/preview`+urlParameters;
url+=`&_i=${pageIndex+1}`;
const nextPage=$(`<button type="button" class="btn btn-link btn-sm">下一页</button>`);
pagingContainer.append(nextPage);
nextPage.click(function(){
window.open(url,'_self');
});
}
}
},
error:function(){
alert('查询操作失败!');

Chargement…
Annuler
Enregistrer