Sfoglia il codice sorgente

1.修改iOS Apex Mobile Result Menu动态生成。

Pen Li 7 anni fa
parent
commit
eca96682e8

+ 6 - 0
Apex Mobile/Apex Mobile.xcodeproj/project.pbxproj

@@ -76,6 +76,7 @@
 		42FB6EC621F2BC5300F694AB /* ApexResultBookingModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 42FB6EC521F2BC5300F694AB /* ApexResultBookingModel.m */; };
 		42FB6EC921F2BC8600F694AB /* ApexResultAddition.m in Sources */ = {isa = PBXBuildFile; fileRef = 42FB6EC821F2BC8600F694AB /* ApexResultAddition.m */; };
 		42FB6ECC21F2C0E300F694AB /* ApexResultBLInfoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 42FB6ECB21F2C0E300F694AB /* ApexResultBLInfoModel.m */; };
+		42FB6ECF21F3136300F694AB /* ApexResultMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 42FB6ECE21F3136300F694AB /* ApexResultMenuItem.m */; };
 		7101BEC82031389A00CC6E3A /* DetailCellKVNew.m in Sources */ = {isa = PBXBuildFile; fileRef = 7101BEC72031389A00CC6E3A /* DetailCellKVNew.m */; };
 		711BA6C1191E0525002EDE6F /* MessageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 711BA6C0191E0525002EDE6F /* MessageViewController.m */; };
 		711BA6C4191E0553002EDE6F /* MessageItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 711BA6C3191E0553002EDE6F /* MessageItem.m */; };
@@ -337,6 +338,8 @@
 		42FB6EC821F2BC8600F694AB /* ApexResultAddition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ApexResultAddition.m; sourceTree = "<group>"; };
 		42FB6ECA21F2C0E300F694AB /* ApexResultBLInfoModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApexResultBLInfoModel.h; sourceTree = "<group>"; };
 		42FB6ECB21F2C0E300F694AB /* ApexResultBLInfoModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ApexResultBLInfoModel.m; sourceTree = "<group>"; };
+		42FB6ECD21F3136300F694AB /* ApexResultMenuItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApexResultMenuItem.h; sourceTree = "<group>"; };
+		42FB6ECE21F3136300F694AB /* ApexResultMenuItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ApexResultMenuItem.m; sourceTree = "<group>"; };
 		7101BEC62031389A00CC6E3A /* DetailCellKVNew.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DetailCellKVNew.h; sourceTree = "<group>"; };
 		7101BEC72031389A00CC6E3A /* DetailCellKVNew.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DetailCellKVNew.m; sourceTree = "<group>"; };
 		711BA6BF191E0525002EDE6F /* MessageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageViewController.h; sourceTree = "<group>"; };
@@ -636,6 +639,8 @@
 			isa = PBXGroup;
 			children = (
 				4225E44421E0989D009D2364 /* ApexResultProtocol.h */,
+				42FB6ECD21F3136300F694AB /* ApexResultMenuItem.h */,
+				42FB6ECE21F3136300F694AB /* ApexResultMenuItem.m */,
 				4225E42221E08502009D2364 /* ApexResultViewController.h */,
 				4225E42321E08502009D2364 /* ApexResultViewController.m */,
 				4225E42521E08576009D2364 /* ApexResult.storyboard */,
@@ -1576,6 +1581,7 @@
 				718BE8B4190F9D970046EA6A /* MySuggestion.m in Sources */,
 				715709A520215B5100EFE5C5 /* zip.c in Sources */,
 				715709AE20215CB000EFE5C5 /* RANetwork.m in Sources */,
+				42FB6ECF21F3136300F694AB /* ApexResultMenuItem.m in Sources */,
 				425390222079B99B00ECF982 /* XYRotatedView.m in Sources */,
 				719EF8FD18BB839F00EFFF5F /* ApexMobileSecondViewController.m in Sources */,
 				4225E44321E08B47009D2364 /* ApexResultBaseModel.m in Sources */,

+ 40 - 1
Apex Mobile/Apex Mobile/RANetwork.m

@@ -1484,19 +1484,57 @@
         }
     }
 
+    NSArray *menu;
     NSString *title = @"";
     if ([module_name isEqualToString:@"Ocean Booking"]) {
 
         title = @"Ocean Booking";
+        menu = @[
+                 @{
+                     @"title": @"Setting",
+                     @"action": @"field_setting"
+                 },
+                 @{
+                     @"title": @"Save",
+                     @"action": @"save"
+                 }
+                 ];
+        
     } else if ([module_name isEqualToString:@"Ocean B/L info."]) {
 
         title = @"Ocean B/L info";
+        menu = @[
+                 @{
+                     @"title": @"Setting",
+                     @"action": @"field_setting"
+                     },
+                 @{
+                     @"title": @"Save",
+                     @"action": @"save"
+                     }
+                 ];
     } else if ([module_name isEqualToString:@"Container detail"]) {
 
         title = @"Container detail";
+        menu = @[
+                 @{
+                     @"title": @"Setting",
+                     @"action": @"field_setting"
+                     },
+                 @{
+                     @"title": @"Save",
+                     @"action": @"save"
+                     }
+                 ];
     } else if ([module_name isEqualToString:@"Download Document"]) {
 
         title = @"Download Document";
+        menu = @[
+                 @{
+                     @"title": @"Save",
+                     @"action": @"save"
+                 }
+                 ];
     }
 
     NSArray *row_actions;
@@ -1532,7 +1570,8 @@
                                 @"result" : @RESULT_TRUE,
                                 @"title" : title,
                                 @"row_actions" : row_actions,
-                                @"items" : arr
+                                @"items" : arr,
+                                @"menu" : menu
                                 };
 
     // for detail

+ 18 - 0
Apex Mobile/Apex Mobile/Result/ApexResultMenuItem.h

@@ -0,0 +1,18 @@
+//
+//  ApexResultMenuItem.h
+//  Apex Mobile
+//
+//  Created by Jack on 2019/1/19.
+//  Copyright © 2019 United Software Applications, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface ApexResultMenuItem : NSObject
+
+@property (nonatomic,copy) NSString *title;
+@property (nonatomic,copy) NSString *action;
+
+@end
+

+ 17 - 0
Apex Mobile/Apex Mobile/Result/ApexResultMenuItem.m

@@ -0,0 +1,17 @@
+//
+//  ApexResultMenuItem.m
+//  Apex Mobile
+//
+//  Created by Jack on 2019/1/19.
+//  Copyright © 2019 United Software Applications, Inc. All rights reserved.
+//
+
+#import "ApexResultMenuItem.h"
+
+@implementation ApexResultMenuItem
+
+- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
+    
+}
+
+@end

+ 39 - 18
Apex Mobile/Apex Mobile/Result/ApexResultViewController.m

@@ -21,6 +21,8 @@
 #import "ApexResultBookingCell.h"
 #import "ApexResultBLInfoCell.h"
 
+#import "ApexResultMenuItem.h"
+
 
 @interface ApexResultViewController ()<ApexResultProtocol, JLRefreshDelegate>
 
@@ -185,26 +187,45 @@
 
 - (void)menuItemClick:(id)sender {
     
-    __weak typeof(self) weakSelf = self;
-    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-    UIAlertAction *settingAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"fields setting", @"Setting") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-        [weakSelf showFieldsSetting];
-    }];
-    
-    UIAlertAction *saveAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"save", @"Save") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+    if (self.presenter.menuItems && self.presenter.menuItems.count > 0) {
         
-        [weakSelf saveSearchParameters];
-    }];
-    
-    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+        __weak typeof(self) weakSelf = self;
+        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+
+        for (ApexResultMenuItem *item in self.presenter.menuItems) {
+            
+            UIAlertAction *itemAction = [UIAlertAction actionWithTitle:item.title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                
+                if ([item.action isEqualToString:@"save"]) {
+                    
+                    [weakSelf saveSearchParameters];
+                } else if ([item.action isEqualToString:@"field_setting"]) {
+                    
+                    [weakSelf showFieldsSetting];
+                }
+            }];
+            [alertVC addAction:itemAction];
+        }
         
-    }];
-    
-    [alertVC addAction:settingAction];
-    [alertVC addAction:saveAction];
-    [alertVC addAction:cancelAction];
-    
-    [self presentViewController:alertVC animated:YES completion:nil];
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+            
+        }];
+        [alertVC addAction:cancelAction];
+
+        
+        [self presentViewController:alertVC animated:YES completion:nil];
+        
+    } else {
+        
+        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"there is no field to response" preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            
+        }];
+        
+        [alertVC addAction:okAction];
+        
+        [self presentViewController:alertVC animated:YES completion:nil];
+    }
 }
 
 #pragma mark - Action

+ 2 - 1
Apex Mobile/Apex Mobile/Result/Presenter/ApexResultPresenter.h

@@ -9,7 +9,7 @@
 #import <Foundation/Foundation.h>
 
 @protocol ApexResultProtocol;
-@class ApexResultBaseModel;
+@class ApexResultBaseModel, ApexResultMenuItem;
 @interface ApexResultPresenter : NSObject
 
 @property (nonatomic,weak) id<ApexResultProtocol> delegate;
@@ -21,6 +21,7 @@
 @property (nonatomic,readonly,strong) NSArray *actions;///< Detail Parameter, from query table actions_info
 @property (nonatomic,strong) NSDictionary *actionParams;///< Click Cell Action Parameters
 @property (nonatomic,assign) BOOL dirty;
+@property (nonatomic,readonly,strong) NSArray<ApexResultMenuItem *> *menuItems;
 
 
 - (instancetype)initWithParameters:(NSDictionary *)params;

+ 16 - 0
Apex Mobile/Apex Mobile/Result/Presenter/ApexResultPresenter.m

@@ -13,6 +13,7 @@
 #import "RANetwork.h"
 #import "ApexResultBookingModel.h"
 #import "ApexResultBLInfoModel.h"
+#import "ApexResultMenuItem.h"
 
 typedef NS_ENUM(NSUInteger, ApexResultFetchDataType) {
     ApexResultFetchDataTypeInitial,
@@ -31,6 +32,7 @@ static const NSInteger detal = 20;
 @property (nonatomic,strong) NSArray<ApexResultBaseModel *> *dataArray;
 @property (nonatomic,strong) NSArray *rowActions;
 @property (nonatomic,strong) NSArray *actions;
+@property (nonatomic,strong) NSArray<ApexResultMenuItem *> *menuItems;
 
 @end
 
@@ -122,6 +124,20 @@ static const NSInteger detal = 20;
             self.rowActions = [json objectForKey:@"row_actions"];
             self.actions = [json objectForKey:@"actions"];
             
+            // menu
+            NSArray *menuArr = [json objectForKey:@"menu"];
+            if (menuArr) {
+                NSMutableArray *tmpArr = [NSMutableArray array];
+                for (NSDictionary *item in menuArr) {
+                    
+                    ApexResultMenuItem *menuItem = [ApexResultMenuItem new];
+                    [menuItem setValuesForKeysWithDictionary:item];
+                    [tmpArr addObject:menuItem];
+                }
+                self.menuItems = [tmpArr copy];
+            }
+            
+            // refresh UI
             dispatch_async(dispatch_get_main_queue(), ^{
                 
                 self.dataArray = [modelsArr copy];