diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 8d7d0d2..8baf3fa 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CD026C0CCE40070D21C /* NewEventViewController.swift */; }; 65221CD326C0CCE40070D21C /* NewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65221CD126C0CCE40070D21C /* NewEventViewController.xib */; }; 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65221CDE26C11D320070D21C /* LoadingHub.swift */; }; + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */; }; + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */; }; 656670FD26CB44490036EA1E /* NewInspectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FC26CB44490036EA1E /* NewInspectionModel.swift */; }; 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */; }; 656C6BD326D34C5C00762246 /* InspectionLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */; }; @@ -42,6 +44,10 @@ 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */; }; + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */; }; + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */; }; + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -51,7 +57,6 @@ 65EB077526BCDF6600F9C0EC /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65EB077326BCDF6600F9C0EC /* MapViewController.xib */; }; 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */; }; 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC726AFF2A900179EBD /* Constant.swift */; }; - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */; }; 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFF826B0099800179EBD /* GuideViewController.swift */; }; 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65F2DFF926B0099800179EBD /* GuideViewController.xib */; }; 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */; }; @@ -98,6 +103,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewEventViewController.xib; sourceTree = ""; }; 65221CDE26C11D320070D21C /* LoadingHub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingHub.swift; sourceTree = ""; }; 65221CE026C2069B0070D21C /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleModeEventTaskViewController.swift; sourceTree = ""; }; + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleModeEventTaskViewController.xib; sourceTree = ""; }; 656670FC26CB44490036EA1E /* NewInspectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewInspectionModel.swift; sourceTree = ""; }; 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewRouteModel.swift; sourceTree = ""; }; 656C6BD226D34C5C00762246 /* InspectionLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionLocalObject.swift; sourceTree = ""; }; @@ -577,6 +584,10 @@ 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeEventDetailViewController.swift; sourceTree = ""; }; + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeEventDetailViewController.xib; sourceTree = ""; }; + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeInspectMapViewController.swift; sourceTree = ""; }; + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeInspectMapViewController.xib; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -586,7 +597,6 @@ 65EB077326BCDF6600F9C0EC /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; 65F2DFC426AFF1A300179EBD /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 65F2DFC726AFF2A900179EBD /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 65F2DFF826B0099800179EBD /* GuideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuideViewController.swift; sourceTree = ""; }; 65F2DFF926B0099800179EBD /* GuideViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GuideViewController.xib; sourceTree = ""; }; 65F2DFFD26B0128C00179EBD /* ActionResultModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionResultModel.swift; sourceTree = ""; }; @@ -747,7 +757,6 @@ isa = PBXGroup; children = ( 65F2DFC726AFF2A900179EBD /* Constant.swift */, - 65F2DFC926AFF2A900179EBD /* KeychainManager.swift */, 65F2E01326B0E8CA00179EBD /* AlertHub.swift */, 65F2E04F26B27B2C00179EBD /* LayerShadowHub.swift */, 65221CDE26C11D320070D21C /* LoadingHub.swift */, @@ -846,6 +855,10 @@ 65EB076C26BCD76F00F9C0EC /* EventTaskViewController.xib */, 65A10D6A26CDEC5300F2D76E /* SingModeInspectViewController.swift */, 65A10D6B26CDEC5300F2D76E /* SingModeInspectViewController.xib */, + 65C9F2B026D631980078AAA9 /* SingModeInspectMapViewController.swift */, + 65C9F2B126D631980078AAA9 /* SingModeInspectMapViewController.xib */, + 6530F45B26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift */, + 6530F45C26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib */, ); path = Inspect; sourceTree = ""; @@ -859,6 +872,8 @@ 65F2E04926B25E8200179EBD /* EventDetailViewController.xib */, 65A10D6E26CDEC7100F2D76E /* SingModeEventViewController.swift */, 65A10D6F26CDEC7100F2D76E /* SingModeEventViewController.xib */, + 65C9F2AC26D61A880078AAA9 /* SingModeEventDetailViewController.swift */, + 65C9F2AD26D61A880078AAA9 /* SingModeEventDetailViewController.xib */, ); path = Event; sourceTree = ""; @@ -1411,15 +1426,18 @@ 65F2E03D26B1723700179EBD /* InspectViewController.xib in Resources */, 65A10D6D26CDEC5300F2D76E /* SingModeInspectViewController.xib in Resources */, 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, + 65C9F2AF26D61A880078AAA9 /* SingModeEventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, + 65C9F2B326D631980078AAA9 /* SingModeInspectMapViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, 65F2E03326B164CC00179EBD /* LogViewController.xib in Resources */, 65A10D7126CDEC7100F2D76E /* SingModeEventViewController.xib in Resources */, 65BF7A2B26B937410097B132 /* InspectMapViewController.xib in Resources */, + 6530F45E26D72F3900AC0D54 /* SingleModeEventTaskViewController.xib in Resources */, 65F2E02226B1242200179EBD /* DefaultTableViewCell.xib in Resources */, 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */, ); @@ -1519,12 +1537,14 @@ 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, + 65C9F2AE26D61A880078AAA9 /* SingModeEventDetailViewController.swift in Sources */, 65BF7A2A26B937410097B132 /* InspectMapViewController.swift in Sources */, 65F2E03226B164CC00179EBD /* LogViewController.swift in Sources */, 65F2E04726B25B5D00179EBD /* EventListModel.swift in Sources */, 65F2DFCA26AFF2A900179EBD /* Constant.swift in Sources */, 65BF7C1C26AFDDCD000FEC82 /* AppDelegate.swift in Sources */, 65221CD226C0CCE40070D21C /* NewEventViewController.swift in Sources */, + 6530F45D26D72F3900AC0D54 /* SingleModeEventTaskViewController.swift in Sources */, 65F2DFC526AFF1A300179EBD /* AppCoordinator.swift in Sources */, 65F2E00326B0129100179EBD /* LoginResultModel.swift in Sources */, 656C6BD726D350D700762246 /* RealmInitializer.swift in Sources */, @@ -1540,11 +1560,11 @@ 65F2E00A26B012D700179EBD /* LoginViewController.swift in Sources */, 65A10D7026CDEC7100F2D76E /* SingModeEventViewController.swift in Sources */, 656C6BD526D3502A00762246 /* RealmConfiguration.swift in Sources */, + 65C9F2B226D631980078AAA9 /* SingModeInspectMapViewController.swift in Sources */, 65EB077426BCDF6600F9C0EC /* MapViewController.swift in Sources */, 65F2E04426B2392600179EBD /* ListCustomCell.swift in Sources */, 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */, 65BDB88A26CD12D400A627D7 /* SingModeMapViewController.swift in Sources */, - 65F2DFCC26AFF2A900179EBD /* KeychainManager.swift in Sources */, 2CD9B63386DC33C3C4CC0034 /* UserDataCacheModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index d0906f0..524adcf 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Model/EventListModel.swift b/LaserMethane/Model/EventListModel.swift index 74f0d6e..048ae9c 100644 --- a/LaserMethane/Model/EventListModel.swift +++ b/LaserMethane/Model/EventListModel.swift @@ -39,17 +39,20 @@ } struct EventRowModel { - var createTime: String - var data: Int - var description: String - var id: String - var images: String - var inspectionId: String - var lat: Double - var lng: Double - var name: String - var type: String - var user: String + var createTime: String? + var data: Int? + var description: String? + var id: String? + var images: String? + var inspectionId: String? + var lat: Double? + var lng: Double? + var name: String? + var type: String? + var user: String? + + init() { + } init(respJson: JSON) { createTime = respJson["createTime"].stringValue diff --git a/LaserMethane/Model/EventTaskModel.swift b/LaserMethane/Model/EventTaskModel.swift index e911620..3cae7ac 100644 --- a/LaserMethane/Model/EventTaskModel.swift +++ b/LaserMethane/Model/EventTaskModel.swift @@ -37,17 +37,20 @@ } struct ListModel { - var lat: Double - var type: String - var user: String - var images: String - var id: String - var lng: Double - var data: Int - var name: String - var description: String - var inspectionId: String - var createTime: String + var lat: Double? + var type: String? + var user: String? + var images: String? + var id: String? + var lng: Double? + var data: Int? + var name: String? + var description: String? + var inspectionId: String? + var createTime: String? + + init() { + } init(respJson: JSON) { lat = respJson["lat"].doubleValue diff --git a/LaserMethane/Model/InspectDetailModel.swift b/LaserMethane/Model/InspectDetailModel.swift index bf34097..5261c06 100644 --- a/LaserMethane/Model/InspectDetailModel.swift +++ b/LaserMethane/Model/InspectDetailModel.swift @@ -6,6 +6,7 @@ // import Foundation +import HandyJSON import SwiftyJSON // { @@ -42,17 +43,20 @@ } struct DetailDataModel { - var date: String! - var endLat: Float! - var endLng: Float! - var endTime: String! - var id: String! - var name: String! - var routes: [RouteModel] - var startLat: Float! - var startLng: Float! - var startTime: String! - var user: String! + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: [RouteModel]! + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue @@ -62,15 +66,14 @@ id = respJson["id"].stringValue name = respJson["name"].stringValue routes = [RouteModel]() - let routesJson = respJson["routes"].stringValue - let pointArray = routesJson - .replacingOccurrences(of: "[[", with: "") - .replacingOccurrences(of: "]]", with: "") - .components(separatedBy: "],[") - for point in pointArray { -// 116.26862901475694,39.916187065972224 - let value = RouteModel(resp: point) - routes.append(value) + let routeJson = respJson["routes"].stringValue +// print("路线: \(routeJson)") + // [{"lat":39.915932617187501,"lng":116.26871853298611},{"lat":39.915938042534719,"lng":116.26878282335069}] + [RouteModel].deserialize(from: routeJson)!.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + routes?.append(route) } startLat = respJson["startLat"].floatValue startLng = respJson["startLng"].floatValue @@ -79,13 +82,10 @@ } } -struct RouteModel { +struct RouteModel: HandyJSON { var lat: Float! var lng: Float! - init(resp: String) { - let point = resp.components(separatedBy: ",") - lat = Float(point[1]) - lng = Float(point[0]) + init() { } } diff --git a/LaserMethane/Model/InspectListModel.swift b/LaserMethane/Model/InspectListModel.swift index b082afc..1fbfdc1 100644 --- a/LaserMethane/Model/InspectListModel.swift +++ b/LaserMethane/Model/InspectListModel.swift @@ -38,17 +38,20 @@ } struct RowsModel { - var date: String - var endLat: Float - var endLng: Float - var endTime: String - var id: String - var name: String - var routes: String - var startLat: Float - var startLng: Float - var startTime: String - var user: String + var date: String? + var endLat: Float? + var endLng: Float? + var endTime: String? + var id: String? + var name: String? + var routes: String? + var startLat: Float? + var startLng: Float? + var startTime: String? + var user: String? + + init() { + } init(respJson: JSON) { date = respJson["date"].stringValue diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index a716369..9dac68d 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,7 +21,11 @@ * 保存事件记录到本地 * */ func addEventTask(model: NewEventTaskModel) { - let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let eventObject = EventTaskLocalObject(taskId: model.taskId, + inspectionId: model.inspectionId, name: model.name, + createTime: model.createTime, lng: model.lng, lat: model.lat, + type: model.type, data: model.data, images: model.images, + desc: model.description) let results = queryTaskEventById(id: model.taskId) if results.count == 0 { try! realm.write { @@ -33,36 +37,106 @@ /** * 根据巡检Id查询事件数据 */ - func queryTaskByInspection(inspectionId: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + func queryTaskByInspection(inspectionId: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspectionId(inspectionId: String) -> [ListModel] { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObjects = realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate) + var listModels = [ListModel]() + if resultObjects.count == 0 { + return listModels + } else { + resultObjects.forEach { it in + var model = ListModel() + model.lat = it.lat + model.type = it.type + model.user = it.user + model.images = it.images + model.id = it.taskId + model.lng = it.lng + model.data = Int(it.data) + model.name = it.name + model.description = it.desc + model.inspectionId = it.inspectionId + model.createTime = it.createTime + + listModels.append(model) + } + return listModels + } } /** * 查询所有事件数据 */ - func queryAllTaskEvent() -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + func queryAllTaskEvent() -> [EventRowModel] { + appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEvent(createTime: String, name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + func queryTaskEvent(createTime: String, name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "createTime = %@ AND name = %@", createTime, name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询巡检数据-根据事件标签查询 */ - func queryTaskEventByName(name: String) -> Results { - realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + func queryTaskEventByName(name: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .sorted(byKeyPath: "createTime", ascending: false) + .filter(predicate)) } /** * 条件查询事件数据-精确查询 */ - func queryTaskEventById(id: String) -> Results { - realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + func queryTaskEventById(id: String) -> [EventRowModel] { + let predicate = NSPredicate(format: "taskId = %@", id) + return appendEventRowModels(resultObjects: realm.objects(EventTaskLocalObject.self) + .filter(predicate)) + } + + private func appendEventRowModels(resultObjects: Results) -> [EventRowModel] { + print("resultObjects\(resultObjects)") + var rowModels = [EventRowModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = EventRowModel() + model.createTime = it.createTime + model.data = Int(it.data) + model.description = it.desc + model.id = it.taskId + model.images = it.images + model.inspectionId = it.inspectionId + model.lat = it.lat + model.lng = it.lng + model.name = it.name + model.type = it.type + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } func isAddSuccess(taskId: String) -> Bool { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index a484463..13397c2 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,9 +21,14 @@ * 保存巡检记录到本地 * */ func addInspection(newModel: NewInspectionModel) { - let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) - let results = queryInspectionById(id: newModel.id) - if results.count == 0 { + let insObject = InspectionLocalObject(inspectionId: newModel.id, + name: newModel.name, startTime: newModel.startTime, + endTime: newModel.endTime, date: newModel.date, + startLng: newModel.startLng, startLat: newModel.startLat, + endLng: newModel.endLng, endLat: newModel.endLat, + routes: newModel.routes) + let result = queryInspectDetailById(inspectionId: newModel.id) + if result == nil { try! realm.write { realm.add(insObject) } @@ -33,37 +38,87 @@ /** * 查询所有巡检数据 */ - func queryAllInspection() -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + func queryAllInspection() -> [RowsModel] { + appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false)) } /** * 条件查询巡检数据-精确查询 */ - func queryInspectionById(id: String) -> Results { - realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) - } - - /** - * 条件查询巡检数据-精确查询 - */ - func queryInspection(startTime: String, endTime: String, name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + func queryInspectDetailById(inspectionId: String) -> DetailDataModel? { + let predicate = NSPredicate(format: "inspectionId = %@", inspectionId) + let resultObject = realm.objects(InspectionLocalObject.self).filter(predicate) + if resultObject.count == 0 { + return nil + } else { + var model = DetailDataModel() + model.date = resultObject[0].date + model.endLat = Float(resultObject[0].endLat) + model.endLng = Float(resultObject[0].endLng) + model.id = resultObject[0].inspectionId + model.name = resultObject[0].name + let routeJson = resultObject[0].routes +// print("路线: \(routeJson)") + let routeModels = [RouteModel].deserialize(from: routeJson)! + var tempRoutes = [RouteModel]() + routeModels.forEach { it in + var route = RouteModel() + route.lng = it?.lng + route.lat = it?.lat + tempRoutes.append(route) + } + model.routes = tempRoutes + model.startLat = Float(resultObject[0].startLat) + model.startLng = Float(resultObject[0].startLng) + model.startTime = resultObject[0].startTime + model.endTime = resultObject[0].endTime + model.user = resultObject[0].user + return model + } } /** * 条件查询巡检数据-根据巡检标签查询 */ - func queryInspectionByName(name: String) -> Results { - realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + func queryInspectionByName(name: String) -> [RowsModel] { + let predicate = NSPredicate(format: "name CONTAINS %@", name) + return appendRowModels(resultObjects: realm.objects(InspectionLocalObject.self) + .sorted(byKeyPath: "startTime", ascending: false) + .filter(predicate)) + } + + private func appendRowModels(resultObjects: Results) -> [RowsModel] { + print("resultObjects\(resultObjects)") + var rowModels = [RowsModel]() + if resultObjects.count == 0 { + return rowModels + } else { + resultObjects.forEach { it in + var model = RowsModel() + model.date = it.date + model.endLat = Float(it.endLat) + model.endLng = Float(it.endLng) + model.id = it.inspectionId + model.name = it.name + model.routes = it.routes + model.startLat = Float(it.startLat) + model.startLng = Float(it.startLng) + model.startTime = it.startTime + model.user = it.user + // 添加数据 + rowModels.append(model) + } + return rowModels + } } /** * 判断是否插入成功 */ func isAddSuccess(inspectionId: String) -> Bool { - let results = queryInspectionById(id: inspectionId) - if results.isEmpty { + let result = queryInspectDetailById(inspectionId: inspectionId) + if result == nil { return false } else { return true diff --git a/LaserMethane/Util/KeychainManager.swift b/LaserMethane/Util/KeychainManager.swift deleted file mode 100644 index 2db273b..0000000 --- a/LaserMethane/Util/KeychainManager.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// KeychainManager.swift -// birmm_inspect_ios_app -// -// Created by 203 on 2021/7/9. -// - -import Foundation - -class KeychainManager: NSObject { - // TODO: 创建查询条件 - class func createQueryMutableDictionary(identifier: String) -> NSMutableDictionary { - // 创建一个条件字典 - let keychainQueryMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置条件存储的类型 - keychainQueryMutableDictionary.setValue(kSecClassGenericPassword, forKey: kSecClass as String) - // 设置存储数据的标记 - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrService as String) - keychainQueryMutableDictionary.setValue(identifier, forKey: kSecAttrAccount as String) - // 设置数据访问属性 - keychainQueryMutableDictionary.setValue(kSecAttrAccessibleAfterFirstUnlock, forKey: kSecAttrAccessible as String) - // 返回创建条件字典 - return keychainQueryMutableDictionary - } - - // TODO: 存储数据 - class func keyChainSaveData(data: Any, withIdentifier identifier: String) -> Bool { - // 获取存储数据的条件 - let keyChainSaveMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除旧的存储数据 - SecItemDelete(keyChainSaveMutableDictionary) - // 设置数据 - keyChainSaveMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 进行存储数据 - let saveState = SecItemAdd(keyChainSaveMutableDictionary, nil) - if saveState == noErr { - return true - } - return false - } - - // TODO: 更新数据 - class func keyChainUpdate(data: Any, withIdentifier identifier: String) -> Bool { - // 获取更新的条件 - let keyChainUpdateMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 创建数据存储字典 - let updateMutableDictionary = NSMutableDictionary(capacity: 0) - // 设置数据 - updateMutableDictionary.setValue(NSKeyedArchiver.archivedData(withRootObject: data), forKey: kSecValueData as String) - // 更新数据 - let updateStatus = SecItemUpdate(keyChainUpdateMutableDictionary, updateMutableDictionary) - if updateStatus == noErr { - return true - } - return false - } - - // TODO: 获取数据 - class func keyChainReadData(identifier: String) -> Any { - var idObject: Any? - // 获取查询条件 - let keyChainReadmutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 提供查询数据的两个必要参数 - keyChainReadmutableDictionary.setValue(kCFBooleanTrue, forKey: kSecReturnData as String) - keyChainReadmutableDictionary.setValue(kSecMatchLimitOne, forKey: kSecMatchLimit as String) - // 创建获取数据的引用 - var queryResult: AnyObject? - // 通过查询是否存储在数据 - let readStatus = withUnsafeMutablePointer(to: &queryResult) { - SecItemCopyMatching(keyChainReadmutableDictionary, UnsafeMutablePointer($0)) - } - if readStatus == errSecSuccess { - if let data = queryResult as! NSData? { - idObject = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as Any - } - } - return idObject as Any - } - - // TODO: 删除数据 - class func keyChainDelete(identifier: String) { - // 获取删除的条件 - let keyChainDeleteMutableDictionary = createQueryMutableDictionary(identifier: identifier) - // 删除数据 - SecItemDelete(keyChainDeleteMutableDictionary) - } -} diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.xib b/LaserMethane/ViewController/Event/EventDetailViewController.xib index 5f39b00..05f4a5b 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.xib +++ b/LaserMethane/ViewController/Event/EventDetailViewController.xib @@ -171,7 +171,7 @@ - + diff --git a/LaserMethane/ViewController/Event/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index b498e57..760b638 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -114,7 +114,7 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type + cell.nameLabel.text = model.name! + "-" + model.type! cell.dateLabel.text = model.createTime cell.userLabel.text = model.user return cell diff --git a/LaserMethane/ViewController/Event/EventViewController.xib b/LaserMethane/ViewController/Event/EventViewController.xib index d62b831..b2992fa 100644 --- a/LaserMethane/ViewController/Event/EventViewController.xib +++ b/LaserMethane/ViewController/Event/EventViewController.xib @@ -60,7 +60,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@ @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@ @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@ @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@ @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@ @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@ @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@ @@ -123,7 +123,7 @@ - + diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift new file mode 100644 index 0000000..37c9d8d --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -0,0 +1,122 @@ +// +// SingModeEventDetailViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/25. +// + +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeEventDetailViewController: UIViewController, TransferValueDelegate { + @IBOutlet var messageView: UIView! + @IBOutlet var maxValueView: UIView! + @IBOutlet var imageView: UIView! + + @IBOutlet var createTimeLabel: UILabel! + @IBOutlet var descriptionLabel: UILabel! + @IBOutlet var dataLabel: UILabel! + @IBOutlet var imageCollectionView: UICollectionView! + + private var createTime: String? + private var desc: String? + private var maxValue: Int? + private var images: String? + // 图片九宫格数据集 + private var imageUrlArray: [URL] = [] + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + title = "事件详情(单机模式)" + navigationController?.navigationBar.isTranslucent = false // 顶部导航不透明可见 + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict // title color + // Do any additional setup after loading the view. + // 设置背景以及圆角 + initViewBackground() + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + + createTimeLabel.text = createTime + descriptionLabel.text = desc + if maxValue == -1 { + dataLabel.text = "0" + } else { + dataLabel.text = maxValue?.description + } + if images == "" { + imageView.isHidden = true + } else { + imageView.isHidden = false + // 绑定图片 + /** + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png, + /Users/a203/Library/Developer/CoreSimulator/Devices/6D8DE765-161A-4B92-A6A9-D19E3A508484/data/Containers/Data/Application/01FD13DB-5604-46AB-ADA1-B76168902C70/Library/Caches/IMG_20210825141112_2.png + */ + // 分割逗号并拼接字符串 + imageUrlArray.removeAll() + images?.components(separatedBy: ",").forEach { path in + print("图片地址: \(path)") +// imageUrlArray.append(URL(string: path)!) +// imageUrlArray.append(URL(fileURLWithPath: path)) + } + } + } + + // 接收上个页面传过来的值 + func transfer(controller: UIViewController, dic: NSDictionary) { + createTime = dic["createTime"] as? String + desc = dic["description"] as? String + maxValue = dic["data"] as? Int + images = dic["images"] as? String + } + + func initViewBackground() { + LayerShadowHub.shared.setShadow(view: messageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: maxValueView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + + LayerShadowHub.shared.setShadow(view: imageView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } +} + +extension SingModeEventDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + return cell + } +} + +extension SingModeEventDetailViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib new file mode 100644 index 0000000..7cb10f4 --- /dev/null +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.xib @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 76f1f98..13cd02e 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -5,25 +5,112 @@ // Created by 203 on 2021/8/19. // +import DefaultsKit +import MJRefresh import UIKit class SingModeEventViewController: UIViewController { + @IBOutlet var startTimePicker: UIDatePicker! + @IBOutlet var endTimePicker: UIDatePicker! + @IBOutlet var keywordsView: UITextField! + @IBOutlet var eventTableView: UITableView! + + private let defaults = Defaults.shared + private let taskShared = EventTaskRealmManager.shared + private var rowsArray: [EventRowModel] = [] + private var dformatter = DateFormatter() + private var isUpdate: Bool = false + private var startDate: String? + private var endDate: String? + private var keyWords: String? + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() - + title = "事件查询(单机模式)" + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. + setupTableView() + // 默认加载数据 + loadData(startTime: "", keywords: "") } + func setupTableView() { + eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.dataSource = self + eventTableView.delegate = self - /* - // MARK: - Navigation + eventTableView.mj_header = MJRefreshNormalHeader { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = true + loadData(startTime: "", keywords: "") + eventTableView.mj_header?.endRefreshing() + }) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + eventTableView.mj_footer = MJRefreshBackNormalFooter { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in + isUpdate = false + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + eventTableView.mj_footer?.endRefreshing() + }) + } } - */ + @IBAction func startSearchAction(_ sender: Any) { + dformatter.dateFormat = "yyyy-MM-dd" + startDate = dformatter.string(from: startTimePicker.date) + keyWords = keywordsView.text + loadData(startTime: startDate ?? "", keywords: keyWords ?? "") + } + + func loadData(startTime: String, keywords: String) { + if keywords != "" { + let result = taskShared.queryTaskEventByName(name: keywords) + if result.count == 0 { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + rowsArray.removeAll() + } else { + rowsArray = result + } + } else { + rowsArray = taskShared.queryAllTaskEvent() + } + eventTableView.reloadData() + } +} + +extension SingModeEventViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + rowsArray.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + cell.selectionStyle = .none + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime + cell.userLabel.text = model.user + return cell + } +} + +extension SingModeEventViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let detailViewController = SingModeEventDetailViewController(nibName: "SingModeEventDetailViewController", bundle: nil) + // 委托代理 + valueDelegate = detailViewController + // 实现代理的方法,传值 + let row = (indexPath as NSIndexPath).row + let model = rowsArray[row] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] + valueDelegate.transfer(controller: self, dic: transferDic) + navigationController?.pushViewController(detailViewController, animated: true) + } } diff --git a/LaserMethane/ViewController/Event/SingModeEventViewController.xib b/LaserMethane/ViewController/Event/SingModeEventViewController.xib index 059e884..0a1c5b3 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.xib +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.xib @@ -1,22 +1,140 @@ - - + + + - + + - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index a6aaa43..28d8797 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -55,9 +55,9 @@ cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - cell.nameLabel.text = model.name + "-" + model.type - cell.dateLabel.text = model.createTime - cell.userLabel.text = model.user + cell.nameLabel.text = model.name! + "-" + model.type! + cell.dateLabel.text = model.createTime! + cell.userLabel.text = model.user! return cell } } @@ -70,7 +70,7 @@ // 实现代理的方法,传值 let row = (indexPath as NSIndexPath).row let model = rowsArray[row] - let transferDic: NSDictionary = ["createTime": model.createTime, "description": model.description, "data": model.data, "images": model.images] + let transferDic: NSDictionary = ["createTime": model.createTime!, "description": model.description!, "data": model.data!, "images": model.images!] valueDelegate.transfer(controller: self, dic: transferDic) navigationController?.pushViewController(detailViewController, animated: true) } diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift index f9f171a..5b49a0a 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.swift @@ -11,7 +11,7 @@ import SwiftyJSON import UIKit -class InspectMapViewController: UIViewController, TransferValueDelegate, MAMapViewDelegate { +class InspectMapViewController: UIViewController, TransferValueDelegate { private var id: String? private var mapView: MAMapView! private var inspectView: UIView! @@ -62,91 +62,39 @@ loadInspectDetail() } - func loadInspectDetail() { - let baseURL = defaults.get(for: serverConfigKey)! - let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue - Alamofire.request(inspectionDetailURL, - method: .get, parameters: ["id": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in - switch response.result { - case let .success(value): - setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") - } + func setUpMap() { + mapView = MAMapView(frame: view.bounds) + // 开启缩放手势 + mapView.isZoomEnabled = true + // 地图的缩放级别的范围是[3-19] + mapView.setZoomLevel(16, animated: true) + // 禁用旋转手势 + mapView.isRotateEnabled = false + // 禁用倾斜手势 + mapView.isRotateCameraEnabled = false + // 不显示罗盘 + mapView.showsCompass = false + mapView.delegate = self + view.addSubview(mapView) + // 添加放大缩小按钮 + // 放大 + expandButton.layer.cornerRadius = 5 + view.addSubview(expandButton) + expandButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) } - } - - func setInspectData(detailModel: DetailDataModel!) { - inspectNameLabel.text = detailModel.name - inspectUserLabel.text = detailModel.user - inspectStartTimeLabel.text = detailModel.startTime - inspectEndTimeLabel.text = detailModel.endTime - // 绘制起点终点 - startPointAnnotation = MAPointAnnotation() - let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat), longitude: CLLocationDegrees(detailModel.startLng)) - // 移动到巡检起始经纬度 - mapView.centerCoordinate = startPointCoordinate - startPointAnnotation.coordinate = startPointCoordinate - - endPointAnnotation = MAPointAnnotation() - let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat), longitude: CLLocationDegrees(detailModel.endLng)) - endPointAnnotation.coordinate = endPointCoordinate - mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) - // 绘制路线 - var lineCoordinates: [CLLocationCoordinate2D] = [] - for route in detailModel.routes { - if route.lat == nil || route.lng == nil { - return - } - lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) + // 缩小 + minusButton.layer.cornerRadius = 5 + view.addSubview(minusButton) + minusButton.snp.makeConstraints { (make) -> Void in + // 设置视图大小 + make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) + make.right.equalTo(-5) + make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) } - mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) - } - - // 描点 - func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { - if annotation.isKind(of: MAPointAnnotation.self) { - let pointReuseIdentifier = "pointReuseIdentifier" - var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? - if annotationView == nil { - annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) - } - // 区分起点终点,分别设置图标 - if annotation.isEqual(startPointAnnotation) { - annotationView!.image = UIImage(named: "qidian") - } - if annotation.isEqual(endPointAnnotation) { - annotationView!.image = UIImage(named: "zhongdian") - } - annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) - annotationView!.animatesDrop = true - annotationView!.isDraggable = false - // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 - annotationView!.centerOffset = CGPoint(x: 0, y: -16) - return annotationView! - } - return nil - } - - // 画线 - func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { - if overlay.isKind(of: MAPolyline.self) { - let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) - renderer.lineWidth = 4.0 - renderer.strokeColor = .red - return renderer - } - return nil - } - - @IBAction func toEventListViewController(_ sender: Any) { - let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) - // 委托代理 - valueDelegate = eventViewController - // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) - navigationController?.pushViewController(eventViewController, animated: true) } func addInspectSubview() { @@ -185,39 +133,55 @@ } } - func setUpMap() { - mapView = MAMapView(frame: view.bounds) - // 开启缩放手势 - mapView.isZoomEnabled = true - // 地图的缩放级别的范围是[3-19] - mapView.setZoomLevel(16, animated: true) - // 禁用旋转手势 - mapView.isRotateEnabled = false - // 禁用倾斜手势 - mapView.isRotateCameraEnabled = false - // 不显示罗盘 - mapView.showsCompass = false - mapView.delegate = self - view.addSubview(mapView) - // 添加放大缩小按钮 - // 放大 - expandButton.layer.cornerRadius = 5 - view.addSubview(expandButton) - expandButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3) + func loadInspectDetail() { + let baseURL = defaults.get(for: serverConfigKey)! + let inspectionDetailURL = baseURL + Constant.inspectionDetail.rawValue + Alamofire.request(inspectionDetailURL, + method: .get, parameters: ["id": id!], + headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + switch response.result { + case let .success(value): + setInspectData(detailModel: InspectDetailModel(respJson: JSON(value)).data) + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "获取巡检详情失败") + } } - // 缩小 - minusButton.layer.cornerRadius = 5 - view.addSubview(minusButton) - minusButton.snp.makeConstraints { (make) -> Void in - // 设置视图大小 - make.size.equalTo(CGSize(width: BUTTON_WIDTH, height: BUTTON_HEIGHT)) - make.right.equalTo(-5) - make.top.equalTo((SCREEN_HEIGHT - BUTTON_HEIGHT) / 3 + BUTTON_HEIGHT + 2) + } + + func setInspectData(detailModel: DetailDataModel!) { + inspectNameLabel.text = detailModel.name + inspectUserLabel.text = detailModel.user + inspectStartTimeLabel.text = detailModel.startTime + inspectEndTimeLabel.text = detailModel.endTime + // 绘制起点终点 + startPointAnnotation = MAPointAnnotation() + let startPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.startLat!), longitude: CLLocationDegrees(detailModel.startLng!)) + // 移动到巡检起始经纬度 + mapView.centerCoordinate = startPointCoordinate + startPointAnnotation.coordinate = startPointCoordinate + + endPointAnnotation = MAPointAnnotation() + let endPointCoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(detailModel.endLat!), longitude: CLLocationDegrees(detailModel.endLng!)) + endPointAnnotation.coordinate = endPointCoordinate + mapView.addAnnotations([startPointAnnotation!, endPointAnnotation!]) + // 绘制路线 + var lineCoordinates: [CLLocationCoordinate2D] = [] + for route in detailModel.routes! { + if route.lat == nil || route.lng == nil { + return + } + lineCoordinates.append(CLLocationCoordinate2D(latitude: CLLocationDegrees(route.lat), longitude: CLLocationDegrees(route.lng))) } + mapView.add(MAPolyline(coordinates: &lineCoordinates, count: UInt(lineCoordinates.count))) + } + + @IBAction func toEventListViewController(_ sender: Any) { + let eventViewController = EventTaskViewController(nibName: "EventTaskViewController", bundle: nil) + // 委托代理 + valueDelegate = eventViewController + // 实现代理的方法,传值 + valueDelegate.transfer(controller: self, dic: ["inspectionId": id!]) + navigationController?.pushViewController(eventViewController, animated: true) } @IBAction func expandMap(_ sender: Any) { @@ -236,3 +200,41 @@ id = dic["id"] as? String } } + +extension InspectMapViewController: MAMapViewDelegate { + // 描点 + func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { + if annotation.isKind(of: MAPointAnnotation.self) { + let pointReuseIdentifier = "pointReuseIdentifier" + var annotationView: MAPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIdentifier) as! MAPinAnnotationView? + if annotationView == nil { + annotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIdentifier) + } + // 区分起点终点,分别设置图标 + if annotation.isEqual(startPointAnnotation) { + annotationView!.image = UIImage(named: "qidian") + } + if annotation.isEqual(endPointAnnotation) { + annotationView!.image = UIImage(named: "zhongdian") + } + annotationView!.imageView.frame = CGRect(x: 0, y: 0, width: 32, height: 32) + annotationView!.animatesDrop = true + annotationView!.isDraggable = false + // 设置中心点偏移,使得标注底部中间点成为经纬度对应点 + annotationView!.centerOffset = CGPoint(x: 0, y: -16) + return annotationView! + } + return nil + } + + // 画线 + func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { + if overlay.isKind(of: MAPolyline.self) { + let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay) + renderer.lineWidth = 4.0 + renderer.strokeColor = .red + return renderer + } + return nil + } +} diff --git a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib index a4e2f56..4f0c560 100644 --- a/LaserMethane/ViewController/Inspect/InspectMapViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectMapViewController.xib @@ -69,39 +69,39 @@ - diff --git a/LaserMethane/ViewController/Inspect/InspectViewController.xib b/LaserMethane/ViewController/Inspect/InspectViewController.xib index 4a6a91f..3441388 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.xib +++ b/LaserMethane/ViewController/Inspect/InspectViewController.xib @@ -65,9 +65,10 @@