Felix.Li 发表于 2022-11-29 17:29:40

如何保证数据源的安全性呢?

很多时候我们都面临这样一个问题,我们设计的模板最终给别人使用,但是又不希望我们数据源信息被别人看到,是不是很头疼。没关系,办法肯定是有的了。

我们这里有两种推荐方法:
1.设置运行时数据源,那这种情况主要是数据源那里依旧可以被查看和使用,并走我们后端设计的数据源。
那这种方法我们其实有一个以前的教程了:https://gcdn.grapecity.com.cn/forum.php?mod=viewthread&tid=55960&fromuid=65049
那么根据这个就可以实现动态数据源的配置了。

2.那除了这种,还有第二种。主要是我们用户在新建的时候使用模板新建,我们又不希望客户查看到数据源信息,那我们就直接将数据源的可见模块直接删除掉
也就是用户无法自己配置数据源。模板中已经固定好。
那针对这种我们只需要增加一定的设置即可,将DataSources的visible设置为不可见即可,具体代码如下:
let viewer = null;
      let designerOptions = GrapeCity.ActiveReports.WebDesigner.createDesignerOptions();

      designerOptions.openButton.visible = true;
      designerOptions.saveButton.visible = true;
      designerOptions.saveAsButton.visible = true;

      designerOptions.openViewer = function (options) {
      if (viewer) {
          viewer.openReport(options.reportInfo.id);
          return;
      }
      viewer = GrapeCity.ActiveReports.JSViewer.create({
          locale: 'zh',
          element: '#' + options.element,
          documentLoaded: () => console.log('The document is loaded entirely on the server'),
          reportService: {
            url: 'api/reporting',
            onRequest: function (init) {
            init.headers.Authorization = 'token';
            }
          },
          reportID: options.reportInfo.id,
      });
      };
      designerOptions.language = "zh"

      GrapeCity.ActiveReports.WebDesigner.renderApplication("ar-web-designer", designerOptions).then((api) => {
      api.settings.data.dataSources.visible = false
      })
那主要设置就是将api.settings.data.dataSources.visible = false即可
最终预览效果如下:


页: [1]
查看完整版本: 如何保证数据源的安全性呢?