⼩程序集成Tableau报表Server端⽤了Spring,其实⽆所谓的。
public class MobilController {
@RequestMapping(value="/openMobileReport")
public ModelAndView openMobileReport(HttpServletRequest request,HttpServletResponse response)
{
ModelAndView modelAndView = new ModelAndView();
try
{
String queryReportID=(Parameter("reportID");
if(queryReportID!=null && !queryReportID.equals(""))
{
AccessDB db=new AccessDB();
String sql="select * from {0}_reports where ID={1}";
ResultSet rs = db.querydb(sql,queryReportID);
())
{
String String("activeViewUrl").replaceAll("sheets/","");
//获取⽤户的报表服务器映射⽤户
Config setup =new Config();
String tUserName="";
Property("SERVERUSER");
//尝试登陆Tableau服务器,获取令牌
if(!tUserName.equals(""))
{
String serverHost=""+Property("SERVERHOST")+":"+Property("SERVERPORTAL"); String token=null;
//是否使⽤SSL证书⽅式登录
String Property("TABLEAUUSEDSSL");
if(ssl!=null && !ssl.equals(""))
{
if(Boolean.parseBoolean(ssl))
{
serverHost=""+Property("SERVERHOST")+":"+Property("SERVERPORTAL");
token=HttpRequest.sendSSLPost(serverHost+"/trusted","username="+tUserName);
}
else
{
token=HttpRequest.sendPost(serverHost+"/trusted","username="+tUserName);
}
}
else
{
token=HttpRequest.sendPost(serverHost+"/trusted","username="+tUserName);
}
if(token!=null && !token.equals("") && !token.equals("-1"))
{
sql=Property("change_report_view_status");
db.updatedb(sql,queryReportID);
String url=serverHost+"/trusted/"+token+"/views/"+views;
modelAndView = new ModelAndView("openMobileReport");
modelAndView.addObject("SYSTEMNAME", Property("SYSTEMNAME"));
modelAndView.addObject("url",url);
modelAndView.addObject("url",url);
modelAndView.addObject("token",token);
modelAndView.addObject("views",views);
modelAndView.addObject("serverHost", serverHost);
modelAndView.addObject("reportName", rs.getString("reportname"));
modelAndView.addObject("createDate", rs.getDate("createDate"));
modelAndView.addObject("num", rs.getInt("num"));
modelAndView.addObject("description", rs.getString("description"));
}
else
{
modelAndView = new ModelAndView("error");
modelAndView.addObject("message","当前站点不受服务器信任,请添加站点到Tableau授信服务器列表."); }
}
else
{
modelAndView = new ModelAndView("error");
modelAndView.addObject("message","⽤户权限不⾜,⽆法登陆报表系统,请咨询管理员添加报表服务器权限."); }
}
else
{
modelAndView = new ModelAndView("error");
modelAndView.addObject("message","没有到⽬标报表,它可能已经被删除.");
}
rs.close();
db.close();
}
else
{
modelAndView = new ModelAndView("error");
modelAndView.addObject("message","参数错误,请循正式路径访问。");
}
}
catch(Exception ex)
{
modelAndView = new ModelAndView("error");
modelAndView.addObject("message","加载页⾯错误:"+ex.getMessage());
}
return modelAndView;
}
}
openSmallProgramReport.jsp代码,其实也⽆所谓。
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="screen-orientation" content="portrait">
<meta name="full-screen" content="yes">
<meta name="x5-orientation" content="portrait">
<meta name="x5-fullscreen" content="true">
<meta name="x5-page-mode" content="app">
<meta name='360-fullscreen' content='true' />
<title>${SYSTEMNAME}</title>
<link rel="stylesheet" type="text/css" href="css/themes/customer/easyui.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/locale/easyui-lang-zh_CN.js"></script>
<script type='text/javascript' src="${serverHost}/javascripts/api/tableau-2.min.js"></script>
<script type='text/javascript' src="js/openSmallProgramReport.js"></script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true,border:false" >
<div >
上传时间:${createDate} ;点击${num}次
</div>
<div >
${description}
<input type="hidden" name="url" id="url" value="${url}">
</div>
<div id="reportContainer" >
</div>
</div>
</body>
</html>
这个⽂件⽤了Jquery easy UI框架,主要是⽤⼀个隐藏的input保存⼀下Tableau的有效访问地址(带有token)。然后写⼀个openSmallProgramReport.js
var viz=null;
$(document).ready(function ()
{
try
{
var containerDiv = ElementById("reportContainer");
var options = {
hideTabs: true,
hideToolbar: true,
toolbarPosition:'TOP',
device:'phone'
};
if (viz) {viz.dispose();}
viz = new tableau.Viz(containerDiv, $('#url').val()+"?:embed=yes", options);
}
catch(e)
{
alert("初始化报表出错:"+e.message);
}
});
使⽤URL⽣成报表对象。
⼩程序部分就很简单了,加⼀个web-view就⾏了。
<web-view src="{{reportServer}}/openSmallProgramReport?reportID={{reportID}}"> </web-view>
效果:
先列表,然后点击展⽰报表。
PS at 2020-05-01:然后我⼜去试了试钉钉⼩程序,真是抄的稀烂。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论