From ef55b5a77b29a2123953f87b7c89d3fe6ffc04a5 Mon Sep 17 00:00:00 2001
From: falcon <9504402@qq.com>
Date: Wed, 27 May 2020 15:37:19 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=89=93=E5=8D=B0=E3=80=82?=
=?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=9C=8D=E5=8A=A1=E6=97=B6=E5=80=99=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0url=E5=8F=82=E6=95=B0uid=E8=A1=A8=E7=A4=BA=E7=99=BB?=
=?UTF-8?q?=E5=BD=95=E7=94=A8=E6=88=B7=E7=BC=96=E5=8F=B7=EF=BC=8Cun?=
=?UTF-8?q?=E4=BB=A3=E8=A1=A8=E7=94=A8=E6=88=B7=E5=90=8D=EF=BC=8CreportNam?=
=?UTF-8?q?e=E4=BB=A3=E8=A1=A8=E8=A6=81=E5=B1=95=E7=A4=BA=E7=9A=84?=
=?UTF-8?q?=E6=8A=A5=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ReportService/Controllers/HomeController.cs | 8 +-
.../Controllers/api/ReportApiController.cs | 41 ++++--
ReportService/ReportService.csproj | 3 +
ReportService/Views/Home/Index.cshtml | 4 +
ReportService/Views/Shared/_Layout.cshtml | 12 +-
ReportService/wwwroot/js/site.js | 24 +++-
.../lib/jquery.cookie/jquery.cookie.js | 117 ++++++++++++++++++
.../lib/jquery.cookie/jquery.cookie.min.js | 2 +
.../{rp => wwwroot/report}/报表1.html | 25 +++-
ReportService/wwwroot/report/报表1.rpt.html | 64 ++++++++++
.../{rp => wwwroot/report}/报表2.html | 0
11 files changed, 285 insertions(+), 15 deletions(-)
create mode 100644 ReportService/wwwroot/lib/jquery.cookie/jquery.cookie.js
create mode 100644 ReportService/wwwroot/lib/jquery.cookie/jquery.cookie.min.js
rename ReportService/{rp => wwwroot/report}/报表1.html (54%)
create mode 100644 ReportService/wwwroot/report/报表1.rpt.html
rename ReportService/{rp => wwwroot/report}/报表2.html (100%)
diff --git a/ReportService/Controllers/HomeController.cs b/ReportService/Controllers/HomeController.cs
index 87df8ff..7cd1a85 100644
--- a/ReportService/Controllers/HomeController.cs
+++ b/ReportService/Controllers/HomeController.cs
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using ReportService.Models;
using System.IO;
using Microsoft.AspNetCore.Hosting;
+using System.Text.Json.Serialization;
namespace ReportService.Controllers
{
@@ -20,7 +21,12 @@ namespace ReportService.Controllers
_logger = logger;
}
- public IActionResult Index() {
+ public IActionResult Index(string uid,string un,string reportName) {
+ uid ??= "";
+ un ??= "";
+ reportName ??= "";
+ Response.Cookies.Append("_userCK",$"{{\"uid\":\"{uid}\",\"un\":\"{un}\"}}");
+ Response.Cookies.Append("_initReport",reportName);
return View();
}
diff --git a/ReportService/Controllers/api/ReportApiController.cs b/ReportService/Controllers/api/ReportApiController.cs
index 088f0f3..e6c305b 100644
--- a/ReportService/Controllers/api/ReportApiController.cs
+++ b/ReportService/Controllers/api/ReportApiController.cs
@@ -1,12 +1,8 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
-using Microsoft.Net.Http.Headers;
using ReportService.Database;
namespace ReportService.Controllers.api
@@ -20,6 +16,15 @@ namespace ReportService.Controllers.api
public IWebHostEnvironment Env { get; private set; }
public RSDbContext Db { get; set; }
+ ///
+ /// 报表存放位置
+ ///
+ public string ReportPath {
+ get {
+ return Path.Combine(this.Env.ContentRootPath,"wwwroot/report");
+ }
+ }
+
public ReportApiController(ILogger logger,IWebHostEnvironment env,RSDbContext db) {
this._logger = logger;
this.Env = env;
@@ -31,11 +36,13 @@ namespace ReportService.Controllers.api
///
/// 名称列表
public List GetReportFiles() {
- var basePath = Path.Combine(Env.ContentRootPath,"rp");
- var files = Directory.GetFiles(basePath,"*.html");
+ var files = Directory.GetFiles(this.ReportPath,"*.html");
var result = new List();
foreach(var f in files) {
var file = new System.IO.FileInfo(f);
+ if(file.Name.ToLower().EndsWith(".rpt.html")) {
+ continue;
+ }
result.Add(file.Name.Substring(0,file.Name.IndexOf('.')));
}
return result;
@@ -46,15 +53,28 @@ namespace ReportService.Controllers.api
/// 模板文件名
/// 模板内容
public IActionResult GetHtml(string fileName) {
- var basePath = Path.Combine(this.Env.ContentRootPath,"rp",fileName + ".html");
- var f = new FileInfo(basePath);
- using(var fr = System.IO.File.OpenRead(basePath)) {
+ var htmlFile = Path.Combine(this.ReportPath,fileName + ".html");
+ using(var fr = System.IO.File.OpenRead(htmlFile)) {
using(var sr = new StreamReader(fr)) {
return Content(sr.ReadToEnd());
}
}
}
+ ///
+ /// 获取模板内容显示模板页面
+ ///
+ /// 模板文件名
+ /// 模板内容
+ public IActionResult GetPrint(string fileName) {
+ var htmlFile = Path.Combine(this.ReportPath,fileName + ".rpt.html");
+ using(var fr = System.IO.File.OpenRead(htmlFile)) {
+ using(var sr = new StreamReader(fr)) {
+ return Content(sr.ReadToEnd(),"text/html; charset=utf-8");
+ }
+ }
+ }
+
///
/// 调用database执行sql语句,将结果封装为json对象返回
///
@@ -64,5 +84,6 @@ namespace ReportService.Controllers.api
var result = this.Db.SqlJsonQuery(sql);
return Content(result,"application/json; charset=utf-8");
}
+
}
}
diff --git a/ReportService/ReportService.csproj b/ReportService/ReportService.csproj
index 5bfbc7d..5105598 100644
--- a/ReportService/ReportService.csproj
+++ b/ReportService/ReportService.csproj
@@ -7,6 +7,9 @@
+
+
+
diff --git a/ReportService/Views/Home/Index.cshtml b/ReportService/Views/Home/Index.cshtml
index c43ad96..5bc2d96 100644
--- a/ReportService/Views/Home/Index.cshtml
+++ b/ReportService/Views/Home/Index.cshtml
@@ -23,6 +23,10 @@
created() {
$.get(this.url, function (d) {
vm.reportList = d;
+ var initReport = $.cookie("_initReport");
+ if (vm.reportList.indexOf(initReport) >= 0) {
+ vm.cli(initReport);
+ }
});
},
methods: {
diff --git a/ReportService/Views/Shared/_Layout.cshtml b/ReportService/Views/Shared/_Layout.cshtml
index d7adc6b..eba27a9 100644
--- a/ReportService/Views/Shared/_Layout.cshtml
+++ b/ReportService/Views/Shared/_Layout.cshtml
@@ -8,6 +8,7 @@
+
@@ -38,9 +39,18 @@
+
@RenderSection("Scripts",required: false)