Java軟件報表軟件技術博客

          java報表軟件技術匯總 java報表軟件制作 報表軟件新聞
          posts - 355, comments - 100, trackbacks - 0, articles - 3
             :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

          應用場景

          用戶有自己的app,希望把報表的移動端【本文中以FineReport移動端為例】功能集成到他們的app里面去,而不需要安裝兩個app。Android端和IOS端的集成接口是不一樣的,下面我們分開詳述如何實現。

          IOS端集成App

          1. 資源準備

          準備好IOS端集成FineReport App的資源文件,包括自己的IOS工程、FineReport提供的資源包。

          下載FineReport提供的集成資源包,解壓至文件夾中,可以看到如下圖所示的文件:

          其中FRDemo和FRDemo_目錄樹是示例demo,說明文件夾中是使用說明,剩下的三個文件夾才是集成時需要依賴的資源包。

          framework&bundle里面包含了真機和模擬器集成時所需要的framework和bundle資源文件,圖片資源(IFImages.xcassets);

          WeiXinSDK微信的SDK

          BaiduMap百度地圖的SDK

          FRDemo集成示例,可以通過設置服務器地址,報表路徑,加載報表,即直接通過URL訪問報表;

          FRDemo_目錄樹:集成示例2,可以登錄服務器,展示目錄樹,即通過發送用戶名密碼進行驗證,驗證成功之后直接顯示FineReport的主頁或者目錄樹。

          2、資源導入

          在自己的項目中導入資源文件framework&bundle\模擬器\FineResource.bundle,添加framework&bundle\IFImages.xcassets到項目中,并在Build Phases——Link Binary With Libraries中添加下圖所示的lib包:


           

          其中FineSoft.framework是FineReport提供的資源文件,在解壓文件夾的framework&bundle\真機\FineSoft.framework目錄下。

          同時,在項目中添加前面下載資源中的微信SDK和百度SDK,如下圖:


           

          3、集成使用FineReport App

          資源都導入配置完成之后,就需要集成App了,IOS端集成App有兩種方式,一個是直接通過URL集成服務器上的模板,另外一個是通過發送用戶名密碼至服務器,驗證通過之后,顯示FineReport目錄樹。

          3.1直接URL集成

          直接URL集成報表,就是通過URL鏈接直接訪問FineReport服務器上的報表。

          在項目中使用IFEntryViewController加載報表,根據報表路徑,服務器路徑,預覽類型創建IFEntryViewController對象。

          引入頭文件:

          1.     #import <FineSoft/IFEntryViewController.h>  

          根據服務器地址和報表路徑生成IFEntryViewController:IFEntryViewController*entryVC = [[IFEntryViewController al-loc] initWithPath:path ServerUrl:url]

          reportPath報表路徑,如app/DetailedDrillA-phone.cpt

          serverUrl服務器地址,如http://192.168.1.100:8075/WebReport/ReportServer

          viewType預覽類型,可選值有IFEntryViewTypePage(分頁預覽),IFEntryViewTypeWrite(填報預覽),可選用,默認為分頁預覽;

          parameters報表傳遞的參數,可選用;

          如果上述四個接口全部使用,則其使用方法為:

          -(id)initWithPath:(NSString *)reportPath serverUrl:(NSString *)serverUrlviewType:(IFEntryViewType)viewType parameters:(NSDictionary *) params;

          比如說URL集成一張在線app demo下的表單,直接預覽,不傳遞參數,代碼如下:

          1.     IFEntryViewController *entryVC = [[IFEntryViewController alloc] initWithPath:@"app/sales/orders.frm" serverUrl:@"http://www.finereporthelp.com:8889/app/ReportServer"];  

          其詳細使用情況可查看資源包中的FRDemo示例

          3.2集成目錄樹查看模板

          集成目錄樹,就是指發送用戶名密碼至服務器驗證之后,訪問系統的目錄樹,查看系統下的所有模板。

          在項目中使用IFEntryViewController加載報表。

          其接口代碼如下:

          ·        引入頭文件

          1.     #import <FineSoft/IFFrameUtils.h>  

          2.             #import <FineSoft/IFFrameDirectoryViewController.h>  

          ·        登錄服務器

          1.     [IFFrameUtils logInto:DEFAULT_SERVERNAME serverUrl:url withUsername:username andPassword:password success:^{  

          2.             //登錄成功,加載目錄樹  

          3.             [IFFrameUtils loadReportTree:^(NSMutableArray *reportsArray) {  

          4.                 //加載成功,展示目錄樹  

          5.                 IFFrameDirectoryViewController *directoryVC = [[IFFrameDirectoryViewController alloc] initWithReportsArray:reportsArray];  

          6.                 [self.navigationController presentViewController:directoryVC animated:YES comple-tion:nil];  

          7.             } failure:^(NSString *) {  

          8.             }];  

          9.         } failure:^(NSString *) {  

          10.      }];  

          登錄服務器的各個參數含義:

          serverName服務器名稱,如Demo服務器;

          serverUrl服務器地址,如http://192.168.1.100:8075/WebReport/ReportServer

          username用戶名;

          password密碼;

          success登錄成功的回調函數(一般是加載目錄樹);

          failure登錄失敗的回調函數。

          其各個參數的使用方法為:+ (void)logInto:(NSString *) serverNameserverUrl:(NSString *)serverUrl withUsername:(NSString *)usernameandPassword:(NSString *)password success:(void (^)())success failure:(void(^)(NSString *))failure;

          比如說集成在線app demo工程的目錄樹,代碼如下:

          1.     #import <FineSoft/IFFrameUtils.h>  

          2.         #import <FineSoft/IFFrameDirectoryViewController.h>  

          3.         //登錄服務器  

          4.             [IFFrameUtils logInto:@"Demo服務器" serv-erUrl:@"http://www.finereporthelp.com:8889/app/ReportServer" withUsername:@"demo" andPassword:@"demo" success:^{  

          5.             //登錄成功,加載目錄樹  

          6.             [IFFrameUtils loadReportTree:^(NSMutableArray *reportsArray) {  

          7.                 //加載成功,展示目錄樹  

          8.                 IFFrameDirectoryViewController *directoryVC = [[IFFrameDirectoryViewController alloc] initWithReportsArray:reportsArray];  

          9.                 [self.navigationController presentViewController:directoryVC animated:YES comple-tion:nil];  

          10.          } failure:^(NSString *) {  

          11.          }];  

          12.      } failure:^(NSString *) {  

          13.      }];  

          其詳細使用情況可查看資源包中的FRDemo_目錄樹示例

          4、注意事項

          1需要配合FR8.0或者FR7.1.1版本使用;

          2提供的示例FRDemo只能在真機上運行,如需在模擬器上運行,請替換framework&bundle/模擬器中的framework和bundle文件;

          3如果遇到百度地圖的集成c文件沖突報錯,可以將other linker flags中的-all_load改為-ObjC。

          5、里打開原生報表

          如果集成的方式是從webView上的html元素事件觸發,打開原生報表,那么需要自定義WebView繼承UIWebView,并重寫- (BOOL) webView:(UIWebView *)webViewTshouldStartLoadWithRequest:(NSURLRequest *)requestnavigationType:(UIWebViewNavigationType)navigationType方法來實現。原理就是分析url,如果url是報表類型,就用EntryViewController打開報表。

          示例可見:

          1.     - (BOOL) webView:(UIWebView *)webViewT shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {  

          2.         if(navigationType != UIWebViewNavigationTypeLinkClicked) {  

          3.             return YES;  

          4.         }  

          5.         NSString *urlString = [[request URL] absoluteString];  

          6.         NSMutableDictionary *urlDict = [IFFrameUtils analysisUrl:urlString];  

          7.         if([urlDict contain:KEY_URL]) {  

          8.         //說明是普通超鏈  

          9.             IFWebViewController *toWebView = [[IFWebViewController alloc] initWithUrl:[urlDict objectForKey:KEY_URL]];  

          10.          toWebView.title = @"鏈接";  

          11.          [self iFPushVC:toWebView animated:YES];  

          12.      } else {  

          13.      //說明是報表類型的超鏈  

          14.          IFEntryViewType viewType = IFEntryViewTypePage;  

          15.          if([[urlDict objectForKey:KEY_OP] isEqualToString:KEY_VIEWTYPE_WRITE]) {  

          16.              viewType = IFEntryViewTypeWrite;  

          17.          }  

          18.          IFEntryViewController *entryVC = [[IFEntryViewController alloc] initWithPath:[urlDict objectForKey:KEY_PATH] serverUrl:[urlDict objectForKey:SERVERURL_KEY] viewType:viewType];  

          19.          entryVC.title = urlDict[KEY_PATH];  

          20.          [self iFPushVC:entryVC animated:YES];  

          21.      }  

          22.      return NO;  

          23.  }  

          6、測試

          FineReport提供一個Demo地址供測試。

          服務器地址:www.finereporthelp.com:8889/app/ReportServer

          用戶名:demo

          密碼:demo

          可用報表路徑:

          app/DetailedDrillA-phone.cpt

          app/para-phone.cpt

          app/DetailedDrill-pad.cpt

          app/parapad.cpt

          app/sales/sales.frm

          app/sales/map.frm

          app/sales/saleseffects.frm

          app/sales/TOP6-pad.frm

          app/sales/product.frm

          app/sales/SWOT.frm

          app/sales/orders.frm

          app/sales/abc.frm app/financial/FinaceStatistic.frmapp/Operations/area.frm

          ......

          Android集成app

          1. 資源準備

          準備好需要集成FineReport App的Android工程,并下載FineReport提供的集成資源包。

          下載FineReport提供的集成資源包,將其解壓,得到如下圖所示幾個文件:


           

          將解壓出來的libs目錄和res目錄拷貝需要集成的Android工程項目中,并將libs目錄下的JARarmeabi目錄作為依賴庫引用到Android開發工程中,如下圖:


           

          2. 修改AndroidManifest.xml文件

          打開自己工程下的AndroidManifest.xml文件,并將解壓出來的FineReport提供的AndroidManifest.xml中的內容寫入到自己工程下的配置文件中

          3. 集成使用FineReport App

          FineReport Android App提供了2種類型的接口:直接使用url訪問服務器上的模板,以連接的形式集成至自己的App當中,另外一種是使用目錄入口集成,即通過驗證用戶名密碼,登錄到FineReportApp的主頁或者目錄頁。

          3.1 URL直接集成

          使用URL集成. 直接使用URL訪問服務器工程模板,比如說我們想要集成服務器下的WorkBook2.cpt模板,并且是填報的形式,那么,代碼如下:

          1.     Intent intent = new Intent();  

          2.             intent.putExtra("url","http://192.168.100.121:8075/WebReport/ReportServer?reportlet=WorkBook2.cpt&op=write");  

          3.             intent.setClass(this, IntegrationActivity.class);  

          4.             startActivity(intent);  

          注:op=write表示參數op為write填報模式,正常預覽模板,不需要添加op參數。

          3.2 使用目錄歡迎入口集成

          使用目錄歡迎入口集成,直接登陸報表主頁或者目錄就相當于將FineReport的App嵌入到自己的App當中,當需要進入到FineReport App的時候,只需要發送相應的用戶名密碼驗證即可登錄到FineReportApp的主頁或者目錄頁當中,接口如下:

          1.     Intent welcomeIntent = new Intent(this, LoadAppFromWelcomeActivity.class);  

          2.             welcomeIntent.putExtra("username""demo"); // 數據決策系統 用戶名  

          3.             welcomeIntent.putExtra("password""demo"); // 數據決策系統 用戶密碼  

          4.             welcomeIntent.putExtra("serverIp""http://www.finereporthelp.com:8889/app/ReportServer"); // 數據決策系統 地址ip  

          5.             welcomeIntent.putExtra("serverName""demo服務器"); // 數據決策系統 名稱  

          6.             startActivity(welcomeIntent);   

          注:如果服務器系統中設置了主頁,那么登錄完成之后就跳轉到主頁,如果沒有設置主頁,就直接顯示目錄頁。

           




          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 板桥市| 通化市| 蒙城县| 容城县| 武鸣县| 色达县| 泰来县| 浦东新区| 长垣县| 西宁市| 阿克| 阜平县| 兰溪市| 新昌县| 乌拉特后旗| 广西| 张家口市| 克什克腾旗| 古丈县| 邵阳市| 仙居县| 玉环县| 镇坪县| 白朗县| 临泉县| 华亭县| 谷城县| 阿城市| 沧源| 罗田县| 定结县| 固阳县| 海原县| 公安县| 普安县| 凉山| 丹东市| 靖安县| 蓬莱市| 荣成市| 濮阳县|