AR从13升级到15后,前端viewer.openReport提示找不到模版,但是指定的文件夹下已存在模版
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<!--Add the references to these files to the target HTML page-->
<link href="vendor/css/materialdesignicons.min.css" rel="stylesheet" />
<!--<link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.4.85/css/materialdesignicons.min.css">-->
<link href="jsViewer.min.css" rel="stylesheet" />
<link href="../icont/iconfont.css" rel="stylesheet" />
<script src="jquery.js"></script>
<script src="jsViewer.min.js"></script>
<style>
.exportBox {
width: 150px;
background-color: #f1f1f1;
padding: 5px 0;
line-height: 30px;
position: absolute;
top: 65px;
z-index: 1060;
}
.exportItem {
padding: 5px 10px;
list-style: none;
}
.exportItem:hover {
cursor: pointer;
background-color: #e5e5e5;
}
</style>
</head>
<body>
<!--Add the DIV element that will contain the JSViewer in the target HTML page-->
<div style="width:100%;height:50px;background:#336699;"></div>
<div class=theme-default id="viewerContainer">Loading Report</div>
<input type="hidden" id="atttype" value="mail" />
<input type="hidden" id="btnShow" value="0" />
</body>
</html>
<!--Add the code that initializes and passes the parameters in the JSViewer instance. The code might vary depending on the technology used to develop the JSViewer component. The example of code for the pure javascript component:-->
<script type="text/javascript">
var reportName = "", optCodes = "", IsSpecial = false, exportShow = false, FileName = "", accessToken = "", identField = "", Mould = "", timeCount = 0, hostStrats = "", isPhone="";
var viewer;
GetUrlParam();
$(function () {
window.addEventListener('message', function (e) {
if (e.data.reportName != "" && e.data.type != "") {
console.log("监听点击*****************开始生成附件");
FileGeneration(e.data.reportName, e.data.type, "attach")
}
}, false)
})
function showReport() {
console.log("方法返回00!!!", IsSpecial);
var otReportSendMail = optCodes.indexOf("otReportSendMail") != -1,
otReportPrint = optCodes.indexOf("otReportPrint") == -1,
otReportExport = optCodes.indexOf("otReportExport") == -1;
timeCount = 40;
if ($("#btnShow").val() == "1")
return;
setingBtn(otReportSendMail, otReportPrint, otReportExport)
}
function setingBtn(otReportSendMail, otReportPrint, otReportExport) {
var Tool = $("div[class='ef-toolbar ef-toolbar-lt']").find("div[class='ef-inline-block ef-dd ef-dd-offset']");
console.log('Tool', Tool)
if (isPhone == "1") {
var btnPrintP = document.getElementsByClassName("ef-toolbar ef-toolbar-lt")[0];
var btnList = $("div[class='ef-toolbar ef-toolbar-lt']").find("button");
if (btnList.length > 7)
btnPrintP.removeChild(btnList[5]);
var btnExport = $("div[class='ef-toolbar ef-toolbar-lt']").find("div[class='ef-inline-block ef-dd ef-dd-chevron ef-dd-offset']")[0];
if (btnExport != undefined)
btnPrintP.removeChild(btnExport);
return;
}
if (timeCount > 0 && Tool && Tool.length > 0) {
if (otReportSendMail || IsSpecial) {
var GetTool = $("div[class='ef-toolbar ef-toolbar-lt']").find("div[class='ef-inline-block ef-dd ef-dd-offset']");
GetTool.before("<div class='ef-inline-block ef-dd ef-dd-chevron ef-dd-offset'><button onclick='openAtion()' class='btn ef-block ef-btn ef-btn-transparent ef-btn-icon ef-rounded' title='写邮件' style='text-align: center;'><span>写邮件</span></button><i style='left: 12px;' class='iconfont iconxitongshezhi-youjian mdi-18px ef-abs-icon ef-pos-top ef-pos-lt'></i></div>");
}
var btnPrintP = document.getElementsByClassName("ef-toolbar ef-toolbar-lt")[0];
if (otReportPrint && btnPrintP != undefined) {
var btnPrintC = $("div[class='ef-toolbar ef-toolbar-lt']").find("button[class='btn ef-inline-block ef-btn ef-btn-transparent ef-btn-icon ef-rounded']")[3];
btnPrintP.removeChild(btnPrintC);
}
//移除自带导出
if (btnPrintP != undefined) {
var btnExport = $("div[class='ef-toolbar ef-toolbar-lt']").find("div[class='ef-inline-block ef-dd ef-dd-chevron ef-dd-offset']")[0];
btnPrintP.removeChild(btnExport);
}
//添加自定义导出
if (!otReportExport) {
var GetTool = $("div[class='ef-toolbar ef-toolbar-lt']").find("div[class='ef-inline-block ef-dd ef-dd-offset']");
console.log('GetTool', GetTool)
GetTool.before("<div class='ef-inline-block ef-dd ef-dd-chevron ef-dd-offset' id='exportId'><button onclick='CreatExport()' class='btn ef-block ef-btn ef-btn-transparent ef-btn-icon ef-rounded' title='导出' style='text-align: center;'><span>导出</span></button><i style='left: 12px;' class='iconfont iconxiazaifujian mdi-18px ef-abs-icon ef-pos-top ef-pos-lt'></i></div>");
}
if (!otReportExport && Mould.indexOf("New")==-1) {
GetTool.before("<div class='ef-inline-block ef-dd ef-dd-chevron ef-dd-offset' id='transknowledge'><button onclick='TransKnowledge()' class='btn ef-block ef-btn ef-btn-transparent ef-btn-icon ef-rounded' title='转存到知识库' style='text-align: center;'><span>转存到知识库</span></button><i style='left: 12px;' class='iconfont iconxiazaifujian mdi-18px ef-abs-icon ef-pos-top ef-pos-lt'></i></div>");
GetTool.before("<div class='ef-inline-block ef-dd ef-dd-chevron ef-dd-offset' id='transattachment'><button onclick='TransAttachment()' class='btn ef-block ef-btn ef-btn-transparent ef-btn-icon ef-rounded' title='转存到单据附件' style='text-align: center;'><span>转存到单据附件</span></button><i style='left: 12px;' class='iconfont iconxiazaifujian mdi-18px ef-abs-icon ef-pos-top ef-pos-lt'></i></div>");
}
$("#btnShow").val(1);
} else if (timeCount > 0) {
timeCount--;
setTimeout(function () {
setingBtn(otReportSendMail, otReportPrint, otReportExport)
}, 500);
}
}
function CreatExport() {
if (exportShow == false) {
exportShow = true
var Y = $('#exportId').offset().left;
$("#dropdown-root").append("\<div class=\"exportBox\" style=\"left:" + Y + "px\"><li class=\"exportItem\" onclick = \"exportData('Doc')\" >Word</li ><li class=\"exportItem\" onclick=\"exportData('Pdf')\">PDF</li><li class=\"exportItem\" onclick=\"exportData('Xlsx')\">Excel</li></div >");
} else {
removeExport()
}
}
function removeExport() {
exportShow = false
$("#dropdown-root").empty();
}
function exportData(val) {
var name = FileName + "." + val;
name = encodeURI(name);
switch (val) {
case "Xlsx":
//viewer.export('Xlsx', null, true, { FileName: name, Multisheet: false, LayoutMode: "Galley" })
FileGeneration(FileName, val, "dowlaod")
break;
case "Doc":
// viewer.export('Docx', null, true, { FileName: name, Multisheet: false, LayoutMode: "Galley" })
FileGeneration(FileName, val, "dowlaod")
break;
case "Pdf":
FileGeneration(FileName, val, "dowlaod")
//viewer.export('Pdf', null, true, { FileName: name, Multisheet: false, LayoutMode: "Galley" })
break;
}
// FileGeneration(FileName, val, "dowlaod")
removeExport()
}
function InitRepoert(reportName, accessToken, identField, Mould, hostStrats) {
var key = accessToken + "_" + identField + "_JSONDataUrlDataJSON"
console.log("key:", key)
viewer = GrapeCity.ActiveReports.JSViewer.create({
element: '#viewerContainer',
availableExports: ['Pdf', 'Doc', 'Docx', 'Xls', 'Xlsx'],
reportService: {},
documentLoaded: (res) => {
showReport()
$(".gces-rv-params.gces-rv-params-open").css("display", "none");
console.log("===" + res)
},
error: (error) => {
$(".gces-rv-params.gces-rv-params-open").css("display", "none");
if (error.message) {
alert(error.message);
}
}
});
console.log("hostStrats:", hostStrats)
viewer.openReport(reportName, [{ name: 'p1', values: [key] }, { name: 'p2', values: [Mould + "_" + hostStrats] }]);
}
function GetUrlParam() {
getCurrentTime("GetUrlParam 页面加载开始");
var url = document.location.search.substring(1);
var arrObj = url.split("&");
var data = {};
for (var i = 0; i < arrObj.length; i++) {
var par = arrObj.split("=");
data[par[0]] = par[1];
if (par[0] == "reportName") {
reportName = decodeURI(par[1]);
}
if (par[0] == "accessToken") {
accessToken = decodeURI(par[1]);
}
if (par[0] == "identField") {
identField = decodeURI(par[1]);
}
if (par[0] == "Mould") {
Mould = decodeURI(par[1]);
}
if (par[0] == "optCodes") {
optCodes = par[1];// "otReportSendMail,otReportPrint,otReportExport"; //par[1]
}
if (par[0] == "IsSpecial") {
IsSpecial = par[1].toString() == "true";
console.log("IsSpecial", IsSpecial)
}
if (par[0] == "filedName") {
FileName = decodeURI(par[1]);
}
if (par[0] == "hostStrats") {
hostStrats = decodeURI(par[1]);
}
if (par[0] == "isPhone") {
isPhone = par[1];
}
}
if (reportName == "") {
reportName = "未命名.rdlx";
}
if (FileName == "") {
FileName = Mould + identField;
}
getCurrentTime("接口请求前时间:");
$.ajax({
url: '../Handler1.ashx?action=InitPage',
data: data,
ataType: 'json',
success: function (json) {
getCurrentTime("接口返回前时间:");
console.log("JSViewer.create");
timeCount = 0;
if (json.toString() == "1") {
InitRepoert(reportName, accessToken, identField, Mould, hostStrats)
}
if (IsSpecial == false) {//合盛没有发前端版本,要注意
if (json.toString() != "1") {
alert(json.toString())
window.parent.postMessage({ "str": "cyy&stting*$#", action: "closeLoading" }, '*')
} else {
getCurrentTime("加载完成!!!");
window.parent.postMessage({ "str": "cyy&stting*$#", action: "openView" }, '*')
}
} else if (json.toString() != "1") {
alert(json.toString())
}
},
error: function (err) {
alert(err.toString())
}
});
}
function getCurrentTime(str) {
var myDate = new Date();
var mytime = myDate.toLocaleTimeString(); //获取当前时间
console.log(str + mytime);
}
function showTime() {
debugger
console.log($(".gces-rv-params.gces-rv-params-open"));
}
function openAtion() {
console.log("打开生成附件类型弹框");
window.parent.postMessage({ "str": "cyy&stting*$#", action: "open" }, '*')
$("#atttype").val("mail");
}
function TransKnowledge() {
console.log("打开转存到知识库");
window.parent.postMessage({ "str": "TransferredToKnowledgeBase", action: "open" }, '*')
$("#atttype").val("knowledge");
}
function TransAttachment() {
console.log("打开转存到单据附件");
window.parent.postMessage({ "str": "TransferredToAttachment", action: "open" }, '*')
$("#atttype").val("attachment");
}
function FileGeneration(FileName, type, ActionType) {
getCurrentTime(ActionType+"请求开始:");
console.log("请求了", FileName, type, ActionType);
if (FileName == undefined || type == undefined) {
return
}
$.ajax({
timeout: 1000 * 60 * 5,
async: false,
url: '../Handler1.ashx?action=FileGeneration',
type: 'POST',
data: { reportName: reportName, name: FileName, type: type, accessToken: accessToken, identField: identField, Mould: Mould, IsSpecial: IsSpecial, ActionType: ActionType, hostStrats: hostStrats },
success: function (data) {
var resource = JSON.parse(data);
getCurrentTime(ActionType + "请求返回:" + resource);
var atttype = $("#atttype").val();
var vuestr = "cyy&stting*$#";
if (atttype == "knowledge")
vuestr = "TransferredToKnowledgeBase";
if (atttype == "attachment")
vuestr = "TransferredToAttachment";
console.log(vuestr);
if (ActionType == "attach") {
if (resource.Message != "") {
window.parent.postMessage({ "str": vuestr, urlId: "", "Message": resource.Message }, '*')
} else {
var fileurl = resource.urlId.substring(0, resource.urlId.lastIndexOf("_"));
var filesize = resource.urlId.substring(resource.urlId.lastIndexOf("_")+1);
window.parent.postMessage({ "str": vuestr, urlId: fileurl, size: filesize, name: FileName + "." + type }, '*')
}
} else {
if (resource.Message == "") {
var arrystr = resource.urlId.substring(0, resource.urlId.lastIndexOf("_"));
var url = arrystr; //测试"https://aapi.laifuyun.com/v2/download/" + arrystr[0]
//var url = "https://up.fumamx.com/v2/download/" + arrystr[0] //线上
console.log(FileName, url);
//var arrystr = resource.urlId.split("_");
var a = document.createElement('a');
a.download = encodeURI(FileName + "." + type);
a.href = url
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}
},
complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
getCurrentTime(ActionType + "请求状态:" + status);
if (status == "error") {
getCurrentTime(ActionType + "二次请求:");
$.ajax({
timeout: 1000 * 60 * 5,
async: false,
url: '../Handler1.ashx?action=FileGeneration2',
type: 'POST',
data: { reportName: reportName, name: FileName, type: type, accessToken: accessToken, identField: identField, Mould: Mould, IsSpecial: IsSpecial, ActionType: ActionType, hostStrats: hostStrats },
success: function (data) {
var resource = JSON.parse(data);
getCurrentTime(ActionType + "二次请求返回:" + resource);
var atttype = $("#atttype").val();
var vuestr = "cyy&stting*$#";
if (atttype == "knowledge")
vuestr = "TransferredToKnowledgeBase";
if (atttype == "attachment")
vuestr = "TransferredToAttachment";
console.log(vuestr);
if (ActionType == "attach") {
if (resource.Message != "") {
window.parent.postMessage({ "str": vuestr, urlId: "", "Message": resource.Message }, '*')
} else {
var fileurl = resource.urlId.substring(0, resource.urlId.lastIndexOf("_"));
var filesize = resource.urlId.substring(resource.urlId.lastIndexOf("_") + 1);
window.parent.postMessage({ "str": vuestr, urlId: fileurl, size: filesize, name: FileName + "." + type }, '*')
}
} else {
if (resource.Message == "") {
var arrystr = resource.urlId.substring(0, resource.urlId.lastIndexOf("_"));
var url = arrystr; //测试"https://aapi.laifuyun.com/v2/download/" + arrystr[0]
//var url = "https://up.fumamx.com/v2/download/" + arrystr[0] //线上
console.log(FileName, url);
//var arrystr = resource.urlId.split("_");
var a = document.createElement('a');
a.download = encodeURI(FileName + "." + type);
a.href = url
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}
},
complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
getCurrentTime(ActionType + "二次请求状态:" + status);
}
});
}
}
});
}
</script>
Startup1:
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Net;
using System.Text;
using GrapeCity.ActiveReports;
using GrapeCity.ActiveReports.Aspnet.Viewer;
using GrapeCity.ActiveReports.PageReportModel;
using Microsoft.Owin;
using Microsoft.Web.Infrastructure;
using Newtonsoft.Json;
using Owin;
using WebDesigner_MVC.Implementation;
using GrapeCity.Enterprise.Data.Expressions;
using GrapeCity.Enterprise.Data.DataEngine.Expressions;
[assembly: OwinStartup(typeof(jsViewdemo.Startup1))]
namespace jsViewdemo
{
public class Startup1
{
public static string EmbeddedReportsPrefix = "JSViewer_MVC_Core.Reports";
string resources = System.Configuration.ConfigurationManager.AppSettings["resources"].ToString();
string keyJSON = "";
string Mould = "";
public object GetReport(string P)//获取报表名称和报表参数,进行一个对应的报表名称和参数的分割
{
string reportName = P.Split(';')[0];
PageReport rep = new PageReport();
rep.Load(new FileInfo(resources + reportName));
ReportParameter para = new ReportParameter();
para.Name = "p1";
para.UsedInQuery = ReportParameterUsedInQuery.True;
para.DataType = ReportParameterDataType.String;
rep.Report.ReportParameters.Add(para);
ReportParameter para2 = new ReportParameter();
para2.Name = "p2";
para2.UsedInQuery = ReportParameterUsedInQuery.True;
para2.DataType = ReportParameterDataType.String;
rep.Report.ReportParameters.Add(para2);
//ReportParameter para3 = new ReportParameter();
//para3.Name = "p3";
//para3.UsedInQuery = ReportParameterUsedInQuery.True;
//para3.DataType = ReportParameterDataType.String;
//rep.Report.ReportParameters.Add(para3);
// 为数据集1添加数据集参数
QueryParameter qr = new QueryParameter();
qr.Name = "p1";
// 将数据集参数与报表参数关联,设置数据集参数等于报表参数
qr.Value=ExpressionInfo.FromString("=Parameters!p1.Value");
QueryParameter q2 = new QueryParameter();
q2.Name = "p2";
// 将数据集参数与报表参数关联,设置数据集参数等于报表参数
q2.Value = ExpressionInfo.FromString("=Parameters!p2.Value");
//QueryParameter q3 = new QueryParameter();
//q3.Name = "p3";
//// 将数据集参数与报表参数关联,设置数据集参数等于报表参数
//q3.Value = ExpressionInfo.FromString("=Parameters!p3.Value");
for (int i = 0; i < rep.Report.DataSets.Count; i++)
{
rep.Report.DataSets.Query.QueryParameters.Add(qr);
rep.Report.DataSets.Query.QueryParameters.Add(q2);
//rep.Report.DataSets.Query.QueryParameters.Add(q3);
}
return rep.Report;
}
public void Configuration(IAppBuilder app)
//public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// 有关如何配置应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkID=316888
//app.UseErrorPage();
try
{
app.UseReporting(settings =>
{
try
{
settings.UseCustomStore(GetReport);//使用UseCustomStore来自定义一些需要的值
settings.UseCompression = true;
settings.UseFileStore(new DirectoryInfo(resources));
SourceClass sc = new SourceClass();
settings.SetLocateDataSource(args =>
{
try
{
string key1 = args.Parameters[0].Value.ToString();
var ping= args.Parameters[1].Value.ToString().Split('_');
string Mould = ping[0];
string hostStrats = ping.Length==2? ping[1]:"";// args.Parameters[2].Value.ToString();
string name = args.DataSet.Name;
//WriteLog.WriteLogs( name + ":********************" + key1+"请求时间:"+DateTime.Now);
GrapeCity.ActiveReports.PageReportModel.FieldCollection fields = args.DataSet.Fields;
System.Data.DataSet data1 = (System.Data.DataSet)sc.getDataSetData(name, fields, key1, Mould, hostStrats);
//WriteLog.WriteLogs( name + ":********************" + key1 + "返回时间:" + DateTime.Now);
return data1;
}
catch (Exception ex)
{
WriteLog.WriteLogs("args error 渲染出错");
WriteLog.WriteLogs(ex.ToString());
return null;
}
});
}
catch (Exception ex)
{
WriteLog.WriteLogs("settings error 渲染出错2");
WriteLog.WriteLogs(ex.ToString());
}
});
}
catch (Exception ex)
{
WriteLog.WriteLogs("start error");
WriteLog.WriteLogs(ex.Message);
}
}
}
}
|