Skip to content

Commit

Permalink
#65 优化代码,报表id值从前端转入而不是写死
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed Jun 3, 2019
1 parent a969b9d commit fa79b19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
25 changes: 9 additions & 16 deletions packages/react-components/src/components/report-designer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,27 @@ class ReportDesigner extends Component {
}

componentDidMount(){
console.log('Loading Designer view');

console.log('Set full screen mode for the designer');
var options = new window.Stimulsoft.Designer.StiDesignerOptions();
let options = new window.Stimulsoft.Designer.StiDesignerOptions();
options.appearance.fullScreenMode = false;

console.log('Create the report designer with specified options');
var designer = new window.Stimulsoft.Designer.StiDesigner(options, 'StiDesigner', false);

console.log('Create a new report instance');
var report = new window.Stimulsoft.Report.StiReport();

console.log('Load report from url');
var reportId = "kJ4ay8atFMvhdt3oa";
let designer = new window.Stimulsoft.Designer.StiDesigner(options, 'StiDesigner', false);
let report = new window.Stimulsoft.Report.StiReport();
let reportId = "temp";
report.loadFile(`/api/report/mrt/${reportId}`);
console.log('Edit report template in the designer');
designer.report = report;
designer.renderHtml("report-designer");
designer.onSaveReport = async function (args) {
// 保存报表模板
let jsonReport = args.report.saveToJsonString();
let response = await fetch('/api/report/mrt/temp/', {
let response = await fetch(`/api/report/mrt/${reportId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: jsonReport
});
let data = await response.json();
if (!response.ok){
window.Stimulsoft.System.StiError.showError("保存失败", true);
}
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions packages/report/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ const bodyParser = require('body-parser');

routes.use(bodyParser.json());

// 获取报表模板
routes.get('/mrt/:report_id', async (req, res) => {
let report_id = req.params.report_id;
let datasource = objectql.getSteedosSchema().getDataSource();
let report = datasource.getReport("temp");
let report = datasource.getReport(report_id);
let mrtContent = mrt.getMrtContent(report);
res.send(mrtContent);
});

routes.post('/mrt/:report_id', (req, res) => {
// 报表mrt模板保存
routes.post('/mrt/:report_id', async (req, res) => {
let report_id = req.params.report_id;
let datasource = objectql.getSteedosSchema().getDataSource();
let report = datasource.getReport("temp").toConfig();
let report = datasource.getReport(report_id).toConfig();
mrt.saveReportToMrtFile(report.mrt_file, req.body);
res.send(report);
res.send({});
});

// 获取报表数据
routes.get('/data/:report_id', async (req, res) => {
let report_id = req.params.report_id;
let datasource = objectql.getSteedosSchema().getDataSource();
let report = datasource.getReport("temp");
let report = datasource.getReport(report_id);
let data = await reporter.getData(report);
res.send(data);
});
Expand Down

0 comments on commit fa79b19

Please sign in to comment.