diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift index 1522333..24addf8 100644 --- a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -51,7 +51,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -59,12 +62,28 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录(单机模式)" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录(单机模式)" secondView.isHidden = true @@ -162,7 +181,19 @@ } // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: inspectionId!, + name: inspectionName!, + createTime: eventTimeLabel.text!, + type: eventType, + lng: longitude!, + lat: latitude!, + data: eventValueData, + images: imageArray.reformat(), + description: eventDesc!, + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) @@ -227,7 +258,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -252,16 +285,19 @@ 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() - } - }) + 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.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift index 1522333..24addf8 100644 --- a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -51,7 +51,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -59,12 +62,28 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录(单机模式)" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录(单机模式)" secondView.isHidden = true @@ -162,7 +181,19 @@ } // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: inspectionId!, + name: inspectionName!, + createTime: eventTimeLabel.text!, + type: eventType, + lng: longitude!, + lat: latitude!, + data: eventValueData, + images: imageArray.reformat(), + description: eventDesc!, + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) @@ -227,7 +258,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -252,16 +285,19 @@ 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() - } - }) + 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/Settings/SettingViewController.swift b/LaserMethane/ViewController/Settings/SettingViewController.swift index 6402907..0c6905c 100644 --- a/LaserMethane/ViewController/Settings/SettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SettingViewController.swift @@ -38,9 +38,18 @@ } func setupTableView() { - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") - tableView.register(UINib(nibName: "CommonTableViewCell", bundle: nil), forCellReuseIdentifier: "commonTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) + tableView.register( + UINib(nibName: "CommonTableViewCell", bundle: nil), + forCellReuseIdentifier: "commonTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -49,7 +58,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6) + ) let button = UIButton(type: .roundedRect) button.setTitle("退出登录", for: .normal) @@ -74,26 +85,29 @@ let confirmAction = UIAlertAction(title: "确定", style: .default, handler: { [self] _ in // 执行退出登录操作 let loginOutURL = defaults.get(for: serverConfigKey)! + Constant.loginOut.rawValue - Alamofire.request(loginOutURL, method: .get, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginOutModel = ActionResultModel(respJson: JSON(value)) - if loginOutModel.code == 200 { - // 删除token - defaults.clear(tokenKey) - // 回到登录页 - let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) - destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen - destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical - present(destinationController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } + Alamofire.request( + loginOutURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginOutModel = ActionResultModel(respJson: JSON(value)) + if loginOutModel.code == 200 { + // 删除token + defaults.clear(tokenKey) + // 回到登录页 + let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) + destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen + destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical + present(destinationController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") + } + } }) alertController.addAction(cancelAction) alertController.addAction(confirmAction) @@ -120,7 +134,9 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 5 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell cell.selectionStyle = .none // 选中时无阴影效果 if indexPath.row == 5 { let infoDictionary: [String: Any] = Bundle.main.infoDictionary! @@ -138,7 +154,9 @@ } return cell } else if indexPath.row == 2 || indexPath.row == 3 { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 2 { @@ -161,7 +179,9 @@ cell.selectionStyle = .none return cell } else { - let cell: CommonTableViewCell = tableView.dequeueReusableCell(withIdentifier: "commonTableViewCell", for: indexPath) as! CommonTableViewCell + let cell: CommonTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "commonTableViewCell", for: indexPath + ) as! CommonTableViewCell cell.leftLabel.text = titleArray[indexPath.row] cell.selectionStyle = .none return cell diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift index 1522333..24addf8 100644 --- a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -51,7 +51,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -59,12 +62,28 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录(单机模式)" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录(单机模式)" secondView.isHidden = true @@ -162,7 +181,19 @@ } // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: inspectionId!, + name: inspectionName!, + createTime: eventTimeLabel.text!, + type: eventType, + lng: longitude!, + lat: latitude!, + data: eventValueData, + images: imageArray.reformat(), + description: eventDesc!, + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) @@ -227,7 +258,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -252,16 +285,19 @@ 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() - } - }) + 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/Settings/SettingViewController.swift b/LaserMethane/ViewController/Settings/SettingViewController.swift index 6402907..0c6905c 100644 --- a/LaserMethane/ViewController/Settings/SettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SettingViewController.swift @@ -38,9 +38,18 @@ } func setupTableView() { - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") - tableView.register(UINib(nibName: "CommonTableViewCell", bundle: nil), forCellReuseIdentifier: "commonTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) + tableView.register( + UINib(nibName: "CommonTableViewCell", bundle: nil), + forCellReuseIdentifier: "commonTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -49,7 +58,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6) + ) let button = UIButton(type: .roundedRect) button.setTitle("退出登录", for: .normal) @@ -74,26 +85,29 @@ let confirmAction = UIAlertAction(title: "确定", style: .default, handler: { [self] _ in // 执行退出登录操作 let loginOutURL = defaults.get(for: serverConfigKey)! + Constant.loginOut.rawValue - Alamofire.request(loginOutURL, method: .get, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginOutModel = ActionResultModel(respJson: JSON(value)) - if loginOutModel.code == 200 { - // 删除token - defaults.clear(tokenKey) - // 回到登录页 - let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) - destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen - destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical - present(destinationController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } + Alamofire.request( + loginOutURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginOutModel = ActionResultModel(respJson: JSON(value)) + if loginOutModel.code == 200 { + // 删除token + defaults.clear(tokenKey) + // 回到登录页 + let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) + destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen + destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical + present(destinationController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") + } + } }) alertController.addAction(cancelAction) alertController.addAction(confirmAction) @@ -120,7 +134,9 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 5 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell cell.selectionStyle = .none // 选中时无阴影效果 if indexPath.row == 5 { let infoDictionary: [String: Any] = Bundle.main.infoDictionary! @@ -138,7 +154,9 @@ } return cell } else if indexPath.row == 2 || indexPath.row == 3 { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 2 { @@ -161,7 +179,9 @@ cell.selectionStyle = .none return cell } else { - let cell: CommonTableViewCell = tableView.dequeueReusableCell(withIdentifier: "commonTableViewCell", for: indexPath) as! CommonTableViewCell + let cell: CommonTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "commonTableViewCell", for: indexPath + ) as! CommonTableViewCell cell.leftLabel.text = titleArray[indexPath.row] cell.selectionStyle = .none return cell diff --git a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift index 6aaacd4..f27c87e 100644 --- a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift @@ -25,8 +25,14 @@ navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. titleArray = ["报警声音/震动", "报警事件自动记录", "版本号"] - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -35,7 +41,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3) + ) let button = UIButton(type: .roundedRect) button.setTitle("回到登录页", for: .normal) @@ -74,14 +82,18 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 2 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell let infoDictionary: [String: Any] = Bundle.main.infoDictionary! let mainVersion: Any = infoDictionary["CFBundleShortVersionString"] as Any // 主程序版本号 cell.setText(leftText: titleArray[indexPath.row], rightText: (mainVersion as? String)!) cell.selectionStyle = .none // 选中时无阴影效果 return cell } else { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 0 { diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift index 1522333..24addf8 100644 --- a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -51,7 +51,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -59,12 +62,28 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录(单机模式)" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录(单机模式)" secondView.isHidden = true @@ -162,7 +181,19 @@ } // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: inspectionId!, + name: inspectionName!, + createTime: eventTimeLabel.text!, + type: eventType, + lng: longitude!, + lat: latitude!, + data: eventValueData, + images: imageArray.reformat(), + description: eventDesc!, + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) @@ -227,7 +258,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -252,16 +285,19 @@ 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() - } - }) + 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/Settings/SettingViewController.swift b/LaserMethane/ViewController/Settings/SettingViewController.swift index 6402907..0c6905c 100644 --- a/LaserMethane/ViewController/Settings/SettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SettingViewController.swift @@ -38,9 +38,18 @@ } func setupTableView() { - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") - tableView.register(UINib(nibName: "CommonTableViewCell", bundle: nil), forCellReuseIdentifier: "commonTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) + tableView.register( + UINib(nibName: "CommonTableViewCell", bundle: nil), + forCellReuseIdentifier: "commonTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -49,7 +58,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6) + ) let button = UIButton(type: .roundedRect) button.setTitle("退出登录", for: .normal) @@ -74,26 +85,29 @@ let confirmAction = UIAlertAction(title: "确定", style: .default, handler: { [self] _ in // 执行退出登录操作 let loginOutURL = defaults.get(for: serverConfigKey)! + Constant.loginOut.rawValue - Alamofire.request(loginOutURL, method: .get, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginOutModel = ActionResultModel(respJson: JSON(value)) - if loginOutModel.code == 200 { - // 删除token - defaults.clear(tokenKey) - // 回到登录页 - let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) - destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen - destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical - present(destinationController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } + Alamofire.request( + loginOutURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginOutModel = ActionResultModel(respJson: JSON(value)) + if loginOutModel.code == 200 { + // 删除token + defaults.clear(tokenKey) + // 回到登录页 + let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) + destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen + destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical + present(destinationController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") + } + } }) alertController.addAction(cancelAction) alertController.addAction(confirmAction) @@ -120,7 +134,9 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 5 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell cell.selectionStyle = .none // 选中时无阴影效果 if indexPath.row == 5 { let infoDictionary: [String: Any] = Bundle.main.infoDictionary! @@ -138,7 +154,9 @@ } return cell } else if indexPath.row == 2 || indexPath.row == 3 { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 2 { @@ -161,7 +179,9 @@ cell.selectionStyle = .none return cell } else { - let cell: CommonTableViewCell = tableView.dequeueReusableCell(withIdentifier: "commonTableViewCell", for: indexPath) as! CommonTableViewCell + let cell: CommonTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "commonTableViewCell", for: indexPath + ) as! CommonTableViewCell cell.leftLabel.text = titleArray[indexPath.row] cell.selectionStyle = .none return cell diff --git a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift index 6aaacd4..f27c87e 100644 --- a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift @@ -25,8 +25,14 @@ navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. titleArray = ["报警声音/震动", "报警事件自动记录", "版本号"] - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -35,7 +41,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3) + ) let button = UIButton(type: .roundedRect) button.setTitle("回到登录页", for: .normal) @@ -74,14 +82,18 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 2 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell let infoDictionary: [String: Any] = Bundle.main.infoDictionary! let mainVersion: Any = infoDictionary["CFBundleShortVersionString"] as Any // 主程序版本号 cell.setText(leftText: titleArray[indexPath.row], rightText: (mainVersion as? String)!) cell.selectionStyle = .none // 选中时无阴影效果 return cell } else { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 0 { diff --git a/Podfile b/Podfile index fb6dce1..cba16bf 100644 --- a/Podfile +++ b/Podfile @@ -43,8 +43,8 @@ pod 'DefaultsKit' end -post_install do |installer| - installer.pods_project.build_configurations.each do |config| - config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' - end -end +# post_install do |installer| +# installer.pods_project.build_configurations.each do |config| +# config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' +# end +# end diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift index 1522333..24addf8 100644 --- a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -51,7 +51,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -59,12 +62,28 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录(单机模式)" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录(单机模式)" secondView.isHidden = true @@ -162,7 +181,19 @@ } // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: inspectionId!, + name: inspectionName!, + createTime: eventTimeLabel.text!, + type: eventType, + lng: longitude!, + lat: latitude!, + data: eventValueData, + images: imageArray.reformat(), + description: eventDesc!, + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) @@ -227,7 +258,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -252,16 +285,19 @@ 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() - } - }) + 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/Settings/SettingViewController.swift b/LaserMethane/ViewController/Settings/SettingViewController.swift index 6402907..0c6905c 100644 --- a/LaserMethane/ViewController/Settings/SettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SettingViewController.swift @@ -38,9 +38,18 @@ } func setupTableView() { - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") - tableView.register(UINib(nibName: "CommonTableViewCell", bundle: nil), forCellReuseIdentifier: "commonTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) + tableView.register( + UINib(nibName: "CommonTableViewCell", bundle: nil), + forCellReuseIdentifier: "commonTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -49,7 +58,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6) + ) let button = UIButton(type: .roundedRect) button.setTitle("退出登录", for: .normal) @@ -74,26 +85,29 @@ let confirmAction = UIAlertAction(title: "确定", style: .default, handler: { [self] _ in // 执行退出登录操作 let loginOutURL = defaults.get(for: serverConfigKey)! + Constant.loginOut.rawValue - Alamofire.request(loginOutURL, method: .get, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginOutModel = ActionResultModel(respJson: JSON(value)) - if loginOutModel.code == 200 { - // 删除token - defaults.clear(tokenKey) - // 回到登录页 - let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) - destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen - destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical - present(destinationController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } + Alamofire.request( + loginOutURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginOutModel = ActionResultModel(respJson: JSON(value)) + if loginOutModel.code == 200 { + // 删除token + defaults.clear(tokenKey) + // 回到登录页 + let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) + destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen + destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical + present(destinationController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") + } + } }) alertController.addAction(cancelAction) alertController.addAction(confirmAction) @@ -120,7 +134,9 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 5 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell cell.selectionStyle = .none // 选中时无阴影效果 if indexPath.row == 5 { let infoDictionary: [String: Any] = Bundle.main.infoDictionary! @@ -138,7 +154,9 @@ } return cell } else if indexPath.row == 2 || indexPath.row == 3 { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 2 { @@ -161,7 +179,9 @@ cell.selectionStyle = .none return cell } else { - let cell: CommonTableViewCell = tableView.dequeueReusableCell(withIdentifier: "commonTableViewCell", for: indexPath) as! CommonTableViewCell + let cell: CommonTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "commonTableViewCell", for: indexPath + ) as! CommonTableViewCell cell.leftLabel.text = titleArray[indexPath.row] cell.selectionStyle = .none return cell diff --git a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift index 6aaacd4..f27c87e 100644 --- a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift @@ -25,8 +25,14 @@ navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. titleArray = ["报警声音/震动", "报警事件自动记录", "版本号"] - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -35,7 +41,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3) + ) let button = UIButton(type: .roundedRect) button.setTitle("回到登录页", for: .normal) @@ -74,14 +82,18 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 2 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell let infoDictionary: [String: Any] = Bundle.main.infoDictionary! let mainVersion: Any = infoDictionary["CFBundleShortVersionString"] as Any // 主程序版本号 cell.setText(leftText: titleArray[indexPath.row], rightText: (mainVersion as? String)!) cell.selectionStyle = .none // 选中时无阴影效果 return cell } else { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 0 { diff --git a/Podfile b/Podfile index fb6dce1..cba16bf 100644 --- a/Podfile +++ b/Podfile @@ -43,8 +43,8 @@ pod 'DefaultsKit' end -post_install do |installer| - installer.pods_project.build_configurations.each do |config| - config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' - end -end +# post_install do |installer| +# installer.pods_project.build_configurations.each do |config| +# config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' +# end +# end diff --git a/Podfile.lock b/Podfile.lock index ca85e88..265a36d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -107,6 +107,6 @@ Toast-Swift: 9b6a70f28b3bf0b96c40d46c0c4b9d6639846711 ZLPhotoBrowser: 8ea81aa5cbaaf8b97bf8830fed1b1f756a5e8894 -PODFILE CHECKSUM: a2314abbc73a7944fba226ccc82442be45d2641b +PODFILE CHECKSUM: f1a874cc265bda5bbe83ffc101ed0b9f7e95f252 COCOAPODS: 1.10.2 diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift index 1522333..24addf8 100644 --- a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -51,7 +51,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -59,12 +62,28 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录(单机模式)" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录(单机模式)" secondView.isHidden = true @@ -162,7 +181,19 @@ } // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: inspectionId!, + name: inspectionName!, + createTime: eventTimeLabel.text!, + type: eventType, + lng: longitude!, + lat: latitude!, + data: eventValueData, + images: imageArray.reformat(), + description: eventDesc!, + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) @@ -227,7 +258,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -252,16 +285,19 @@ 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() - } - }) + 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/Settings/SettingViewController.swift b/LaserMethane/ViewController/Settings/SettingViewController.swift index 6402907..0c6905c 100644 --- a/LaserMethane/ViewController/Settings/SettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SettingViewController.swift @@ -38,9 +38,18 @@ } func setupTableView() { - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") - tableView.register(UINib(nibName: "CommonTableViewCell", bundle: nil), forCellReuseIdentifier: "commonTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) + tableView.register( + UINib(nibName: "CommonTableViewCell", bundle: nil), + forCellReuseIdentifier: "commonTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -49,7 +58,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6) + ) let button = UIButton(type: .roundedRect) button.setTitle("退出登录", for: .normal) @@ -74,26 +85,29 @@ let confirmAction = UIAlertAction(title: "确定", style: .default, handler: { [self] _ in // 执行退出登录操作 let loginOutURL = defaults.get(for: serverConfigKey)! + Constant.loginOut.rawValue - Alamofire.request(loginOutURL, method: .get, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginOutModel = ActionResultModel(respJson: JSON(value)) - if loginOutModel.code == 200 { - // 删除token - defaults.clear(tokenKey) - // 回到登录页 - let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) - destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen - destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical - present(destinationController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } + Alamofire.request( + loginOutURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginOutModel = ActionResultModel(respJson: JSON(value)) + if loginOutModel.code == 200 { + // 删除token + defaults.clear(tokenKey) + // 回到登录页 + let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) + destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen + destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical + present(destinationController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") + } + } }) alertController.addAction(cancelAction) alertController.addAction(confirmAction) @@ -120,7 +134,9 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 5 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell cell.selectionStyle = .none // 选中时无阴影效果 if indexPath.row == 5 { let infoDictionary: [String: Any] = Bundle.main.infoDictionary! @@ -138,7 +154,9 @@ } return cell } else if indexPath.row == 2 || indexPath.row == 3 { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 2 { @@ -161,7 +179,9 @@ cell.selectionStyle = .none return cell } else { - let cell: CommonTableViewCell = tableView.dequeueReusableCell(withIdentifier: "commonTableViewCell", for: indexPath) as! CommonTableViewCell + let cell: CommonTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "commonTableViewCell", for: indexPath + ) as! CommonTableViewCell cell.leftLabel.text = titleArray[indexPath.row] cell.selectionStyle = .none return cell diff --git a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift index 6aaacd4..f27c87e 100644 --- a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift @@ -25,8 +25,14 @@ navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. titleArray = ["报警声音/震动", "报警事件自动记录", "版本号"] - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -35,7 +41,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3) + ) let button = UIButton(type: .roundedRect) button.setTitle("回到登录页", for: .normal) @@ -74,14 +82,18 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 2 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell let infoDictionary: [String: Any] = Bundle.main.infoDictionary! let mainVersion: Any = infoDictionary["CFBundleShortVersionString"] as Any // 主程序版本号 cell.setText(leftText: titleArray[indexPath.row], rightText: (mainVersion as? String)!) cell.selectionStyle = .none // 选中时无阴影效果 return cell } else { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 0 { diff --git a/Podfile b/Podfile index fb6dce1..cba16bf 100644 --- a/Podfile +++ b/Podfile @@ -43,8 +43,8 @@ pod 'DefaultsKit' end -post_install do |installer| - installer.pods_project.build_configurations.each do |config| - config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' - end -end +# post_install do |installer| +# installer.pods_project.build_configurations.each do |config| +# config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' +# end +# end diff --git a/Podfile.lock b/Podfile.lock index ca85e88..265a36d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -107,6 +107,6 @@ Toast-Swift: 9b6a70f28b3bf0b96c40d46c0c4b9d6639846711 ZLPhotoBrowser: 8ea81aa5cbaaf8b97bf8830fed1b1f756a5e8894 -PODFILE CHECKSUM: a2314abbc73a7944fba226ccc82442be45d2641b +PODFILE CHECKSUM: f1a874cc265bda5bbe83ffc101ed0b9f7e95f252 COCOAPODS: 1.10.2 diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index ca85e88..265a36d 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -107,6 +107,6 @@ Toast-Swift: 9b6a70f28b3bf0b96c40d46c0c4b9d6639846711 ZLPhotoBrowser: 8ea81aa5cbaaf8b97bf8830fed1b1f756a5e8894 -PODFILE CHECKSUM: a2314abbc73a7944fba226ccc82442be45d2641b +PODFILE CHECKSUM: f1a874cc265bda5bbe83ffc101ed0b9f7e95f252 COCOAPODS: 1.10.2 diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 524adcf..da0e47e 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Coordinator/AppCoordinator.swift b/LaserMethane/Coordinator/AppCoordinator.swift index e1d7376..51591bd 100644 --- a/LaserMethane/Coordinator/AppCoordinator.swift +++ b/LaserMethane/Coordinator/AppCoordinator.swift @@ -19,26 +19,7 @@ IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// NetworkControl.shared.controlBaseConfig( -// successCallback: { _ in -// -// }, -// errorCallback: { -// } -// ) window.rootViewController = GuideViewController() window.makeKeyAndVisible() } } - -// extension AppCoordinator { -// func setUpVender() { -// //键盘弹起,不遮挡输入框 -// func setUpKeyboardManager() { -// IQKeyboardManager.shared.enable = true -// IQKeyboardManager.shared.keyboardDistanceFromTextField = 28 -// IQKeyboardManager.shared.shouldResignOnTouchOutside = true -// } -// setUpKeyboardManager() -// } -// } diff --git a/LaserMethane/Extension/Array.swift b/LaserMethane/Extension/Array.swift index 92e1e51..7ecbc58 100644 --- a/LaserMethane/Extension/Array.swift +++ b/LaserMethane/Extension/Array.swift @@ -31,6 +31,11 @@ let red = self[0] as! Int let green = self[1] as! Int let blue = self[2] as! Int - return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: CGFloat(1.0)) + return UIColor( + red: CGFloat(red) / 255.0, + green: CGFloat(green) / 255.0, + blue: CGFloat(blue) / 255.0, + alpha: CGFloat(1.0) + ) } } diff --git a/LaserMethane/LaserMethane-Bridging-Header.h b/LaserMethane/LaserMethane-Bridging-Header.h index 1c6efb6..d208134 100644 --- a/LaserMethane/LaserMethane-Bridging-Header.h +++ b/LaserMethane/LaserMethane-Bridging-Header.h @@ -8,9 +8,9 @@ #ifndef LaserMethane_Bridging_Header_h #define LaserMethane_Bridging_Header_h -#import #import #import +#import #import diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift index b1aa322..5682e17 100644 --- a/LaserMethane/Object/EventTaskLocalObject.swift +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class EventTaskLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var taskId: String = "" // 事件id @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @@ -22,7 +22,7 @@ @objc dynamic var desc: String = "" // 事件描述 @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 + // Realm不支持主键自增 override class func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift index a52e1e5..46e280a 100644 --- a/LaserMethane/Object/InspectionLocalObject.swift +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -9,7 +9,7 @@ import RealmSwift class InspectionLocalObject: Object { - @objc dynamic var id = 0 // 主键 + @objc dynamic var id = UUID().uuidString // 主键 @objc dynamic var inspectionId: String = "" // 巡检id @objc dynamic var name: String = "" // 巡检标签 @objc dynamic var startTime: String = "" // 开始时间 @@ -22,8 +22,8 @@ @objc dynamic var routes: String = "" // 路线Json @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” - // 主键自增 - override class func primaryKey() -> String? { + // Realm不支持主键自增 + override static func primaryKey() -> String? { "id" } diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift index 9dac68d..b806d78 100644 --- a/LaserMethane/Util/EventTaskRealmManager.swift +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -21,11 +21,18 @@ * 保存事件记录到本地 * */ 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 { diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift index 13397c2..0442555 100644 --- a/LaserMethane/Util/InspectionRealmManager.swift +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -21,12 +21,18 @@ * 保存巡检记录到本地 * */ 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 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 { diff --git a/LaserMethane/ViewController/Event/EventDetailViewController.swift b/LaserMethane/ViewController/Event/EventDetailViewController.swift index 2381698..75c6fa7 100644 --- a/LaserMethane/ViewController/Event/EventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/EventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -63,7 +66,9 @@ // 分割逗号并拼接字符串 imageUrlArray.removeAll() images?.components(separatedBy: ",").forEach { it in - imageUrlArray.append(URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) + imageUrlArray.append( + URL(string: it.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) } } } @@ -77,11 +82,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +114,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +131,20 @@ extension EventDetailViewController: 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() - } - }) + 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/EventViewController.swift b/LaserMethane/ViewController/Event/EventViewController.swift index 760b638..da9cc86 100644 --- a/LaserMethane/ViewController/Event/EventViewController.swift +++ b/LaserMethane/ViewController/Event/EventViewController.swift @@ -45,34 +45,47 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL! + Constant.eventList.rawValue - let param: [String: Any] = ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset] + let param: [String: Any] = [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ] print("提交参数: \(param)") - Alamofire.request(eventListURL, method: .get, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { [self] response in - switch response.result { - case let .success(value): - let eventModel = EventListModel(respJson: JSON(value)) - if eventModel.code == 200 { - if isUpdate { - rowsArray = eventModel.data.rows - } else { - eventModel.data.rows.forEach { model in - rowsArray.append(model) - } - } - // 必须要重新加载数据,否则不走数据绑定 - eventTableView.reloadData() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") + Alamofire.request( + eventListURL, + method: .get, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in + switch response.result { + case let .success(value): + let eventModel = EventListModel(respJson: JSON(value)) + if eventModel.code == 200 { + if isUpdate { + rowsArray = eventModel.data.rows + } else { + eventModel.data.rows.forEach { model in + rowsArray.append(model) } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") } + // 必须要重新加载数据,否则不走数据绑定 + eventTableView.reloadData() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "查询失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知错误") + } + } } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -80,7 +93,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = true pageOffSet = 1 - loadData(keywords: "", startTime: "", endTime: "", offset: self.pageOffSet) + loadData( + keywords: "", + startTime: "", + endTime: "", + offset: self.pageOffSet + ) eventTableView.mj_header?.endRefreshing() }) } @@ -89,7 +107,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) eventTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +123,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView.text - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +138,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -129,7 +159,12 @@ // 实现代理的方法,传值 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/Event/SingModeEventDetailViewController.swift b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift index 37c9d8d..237c91d 100644 --- a/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventDetailViewController.swift @@ -38,7 +38,10 @@ // 设置背景以及圆角 initViewBackground() // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self @@ -77,11 +80,29 @@ } 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: 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: 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)) + LayerShadowHub.shared.setShadow( + view: imageView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } @@ -91,7 +112,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ImageCollectionViewCell + let cell: ImageCollectionViewCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewCell", for: indexPath + ) as? ImageCollectionViewCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -106,16 +129,20 @@ 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() - } - }) + 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/SingModeEventViewController.swift b/LaserMethane/ViewController/Event/SingModeEventViewController.swift index 13cd02e..7ffc7e0 100644 --- a/LaserMethane/ViewController/Event/SingModeEventViewController.swift +++ b/LaserMethane/ViewController/Event/SingModeEventViewController.swift @@ -40,7 +40,10 @@ } func setupTableView() { - eventTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + eventTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) eventTableView.dataSource = self eventTableView.delegate = self @@ -90,7 +93,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = eventTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = eventTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -109,7 +114,11 @@ // 实现代理的方法,传值 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/Guide/GuideViewController.swift b/LaserMethane/ViewController/Guide/GuideViewController.swift index c077691..431a03f 100644 --- a/LaserMethane/ViewController/Guide/GuideViewController.swift +++ b/LaserMethane/ViewController/Guide/GuideViewController.swift @@ -15,7 +15,13 @@ override func viewDidLoad() { super.viewDidLoad() - timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true) + timer = Timer.scheduledTimer( + timeInterval: 1, + target: self, + selector: #selector(countDownTimer), + userInfo: nil, + repeats: true + ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:12204", for: serverConfigKey) } diff --git a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift index 28d8797..f12644b 100644 --- a/LaserMethane/ViewController/Inspect/EventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/EventTaskViewController.swift @@ -20,15 +20,21 @@ override func viewDidLoad() { super.viewDidLoad() - taskTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + taskTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) taskTableView.dataSource = self taskTableView.delegate = self // 查询事件列表 let baseURL = defaults.get(for: serverConfigKey)! let eventListURL = baseURL + Constant.searchByInspect.rawValue - Alamofire.request(eventListURL, - method: .get, parameters: ["inspectionId": id!], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + eventListURL, + method: .get, + parameters: ["inspectionId": id!], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): rowsArray = EventTaskModel(respJson: JSON(value)).data.list @@ -51,7 +57,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -70,7 +78,12 @@ // 实现代理的方法,传值 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/InspectViewController.swift b/LaserMethane/ViewController/Inspect/InspectViewController.swift index f275624..fa1b9bd 100644 --- a/LaserMethane/ViewController/Inspect/InspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/InspectViewController.swift @@ -26,8 +26,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() @@ -46,9 +45,18 @@ func loadData(keywords: String, startTime: String, endTime: String, offset: Int) { baseURL = defaults.get(for: serverConfigKey)! let inspectListURL = baseURL! + Constant.inspectList.rawValue - Alamofire.request(inspectListURL, method: .get, - parameters: ["keywords": keywords, "startTime": startTime, "endTime": endTime, "limit": 15, "offset": offset], - headers: ["token": defaults.get(for: tokenKey)!]).responseJSON { [self] response in + Alamofire.request( + inspectListURL, + method: .get, + parameters: [ + "keywords": keywords, + "startTime": startTime, + "endTime": endTime, + "limit": 15, + "offset": offset + ], + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let inspectModel = InspectListModel(respJson: JSON(value)) @@ -72,7 +80,10 @@ } func setupTableView() { - inspectTableView.register(UINib(nibName: "ListCustomCell", bundle: nil), forCellReuseIdentifier: "listCustomCell") + inspectTableView.register( + UINib(nibName: "ListCustomCell", bundle: nil), + forCellReuseIdentifier: "listCustomCell" + ) inspectTableView.dataSource = self inspectTableView.delegate = self @@ -89,7 +100,12 @@ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [self] in isUpdate = false pageOffSet += 1 - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: pageOffSet) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: pageOffSet + ) inspectTableView.mj_footer?.endRefreshing() }) } @@ -100,7 +116,12 @@ startDate = dformatter.string(from: startTimePicker.date) endDate = dformatter.string(from: endTimePicker.date) keyWords = keywordsView?.description - loadData(keywords: keyWords ?? "", startTime: startDate ?? "", endTime: endDate ?? "", offset: 1) + loadData( + keywords: keyWords ?? "", + startTime: startDate ?? "", + endTime: endDate ?? "", + offset: 1 + ) } } @@ -110,7 +131,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = inspectTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = inspectTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] diff --git a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift index 3dd56bc..206a254 100644 --- a/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingModeInspectViewController.swift @@ -23,8 +23,7 @@ private var startDate: String? private var endDate: String? private var keyWords: String? - - var valueDelegate: TransferValueDelegate! + private var valueDelegate: TransferValueDelegate! override func viewDidLoad() { super.viewDidLoad() diff --git a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift index 3ef6be0..33b3460 100644 --- a/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift +++ b/LaserMethane/ViewController/Inspect/SingleModeEventTaskViewController.swift @@ -41,7 +41,9 @@ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: ListCustomCell! = taskTableView.dequeueReusableCell(withIdentifier: "listCustomCell", for: indexPath) as? ListCustomCell + let cell: ListCustomCell! = taskTableView.dequeueReusableCell( + withIdentifier: "listCustomCell", for: indexPath + ) as? ListCustomCell cell.selectionStyle = .none let row = (indexPath as NSIndexPath).row let model = rowsArray[row] @@ -60,7 +62,12 @@ // 实现代理的方法,传值 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/Login/LoginViewController.swift b/LaserMethane/ViewController/Login/LoginViewController.swift index a4cd6e9..a3cf7c0 100644 --- a/LaserMethane/ViewController/Login/LoginViewController.swift +++ b/LaserMethane/ViewController/Login/LoginViewController.swift @@ -60,23 +60,26 @@ // 登录 let loginURL = baseURL + Constant.login.rawValue - Alamofire.request(loginURL, method: .post, parameters: ["username": userName!, "password": pwdWithKey]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginModel = LoginResultModel(respJson: JSON(value)) - if loginModel.code == 200 { - // 将token存起来 - defaults.set(loginModel.data!.token, for: tokenKey) - // 跳转主页 - startMainMenuView() - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") - } + Alamofire.request( + loginURL, + method: .post, + parameters: ["username": userName!, "password": pwdWithKey] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginModel = LoginResultModel(respJson: JSON(value)) + if loginModel.code == 200 { + // 将token存起来 + defaults.set(loginModel.data!.token, for: tokenKey) + // 跳转主页 + startMainMenuView() + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "密码错误,无法登陆") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "未知异常,无法登陆") + } + } case .failure: AlertHub.shared.showWaringAlert(controller: self, message: "检验失败,无法登陆") } diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift index 7c666e2..f9a8ec3 100644 --- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift +++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift @@ -37,9 +37,12 @@ } func obtainUserInfo() { - let token = defaults.get(for: tokenKey)! let obtainUserInfoURL = defaults.get(for: serverConfigKey)! + Constant.userInfo.rawValue - Alamofire.request(obtainUserInfoURL, method: .get, headers: ["token": token]).responseJSON { [self] response in + Alamofire.request( + obtainUserInfoURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { [self] response in switch response.result { case let .success(value): let userModel = UserInfoModel(respJson: JSON(value)) @@ -117,10 +120,28 @@ } func initViewBackground() { - LayerShadowHub.shared.setShadow(view: inspectView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: inspectView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: logSearchView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: logSearchView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) - LayerShadowHub.shared.setShadow(view: settingsView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingsView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } } diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index e933132..ce9e8bd 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -110,15 +110,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: (userModel.name!)) + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: userModel.name! + ) // 开始巡检 startInspection() } @@ -141,9 +153,19 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user + ) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -253,7 +275,13 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -261,7 +289,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -269,7 +303,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -299,34 +339,46 @@ let addInspectionURL = baseURL! + Constant.addInspection.rawValue let timeInterval: TimeInterval = Date().timeIntervalSince1970 let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": endLng, "endLat": endLat, - "routes": model.routes, "user": model.user] + let param: [String: Any] = [ + "id": model.id, + "name": model.name, + "startTime": model.startTime, + "endTime": endTime, + "date": model.date, + "startLng": model.startLng, + "startLat": model.startLat, + "endLng": endLng, "endLat": endLat, + "routes": model.routes, + "user": model.user + ] // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] print("提交参数: \(param)") - Alamofire.request(addInspectionURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - defaults.set(true, for: statusKey) - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - defaults.set(false, for: statusKey) - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addInspectionURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + defaults.set(false, for: statusKey) + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -400,22 +452,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -471,10 +529,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: model.user) + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: model.user + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -554,7 +620,10 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, type: .withResponse + ) } } @@ -680,27 +749,40 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": longitude, - "lat": latitude, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": model.id, + "name": model.name, + "createTime": model.startTime, + "type": "报警事件", + "lng": longitude, + "lat": latitude, + "data": Double(maxValue)!, + "images": "", + "description": "自动报警记录", + "user": model.user + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - view.makeToast("保存成功", duration: 2, position: .center) - isGeneratingTask = false - alarmCount = 0 - } else { - view.makeToast("保存失败,服务器异常", duration: 2, position: .center) - } - case .failure: - view.makeToast("保存失败,网络异常", duration: 2, position: .center) - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) + } + case .failure: + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } + }) } } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 92eccd7..1579fd3 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -58,7 +58,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -66,12 +69,30 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录" secondView.isHidden = true @@ -169,30 +190,43 @@ } // 提交事件 let addEventURL = baseURL! + Constant.addEvent.rawValue - let param: [String: Any] = ["id": "t".id(), "inspectionId": inspectionId!, "name": inspectionName!, - "createTime": eventTimeLabel.text!, "type": eventType, "lng": longitude!, - "lat": latitude!, "data": eventValueData, "images": imageArray.reformat(), - "description": eventDesc!, "user": (userModel.name)!] + let param: [String: Any] = [ + "id": "t".id(), + "inspectionId": inspectionId!, + "name": inspectionName!, + "createTime": eventTimeLabel.text!, + "type": eventType, + "lng": longitude!, + "lat": latitude!, + "data": eventValueData, + "images": imageArray.reformat(), + "description": eventDesc!, + "user": (userModel.name)! + ] print("提交参数: \(param)") - Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON(completionHandler: { [self] response in - switch response.result { - case let .success(value): - let actionModel = ActionResultModel(respJson: JSON(value)) - if actionModel.code == 200 { - let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) - let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in - navigationController?.popViewController(animated: true) - }) - alertController.addAction(okAction) - present(alertController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") - } - }) + Alamofire.request( + addEventURL, + method: .post, + parameters: param, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON(completionHandler: { [self] response in + switch response.result { + case let .success(value): + let actionModel = ActionResultModel(respJson: JSON(value)) + if actionModel.code == 200 { + let alertController = UIAlertController(title: "提示", message: "提交成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + } + }) } func currentTime() -> String { @@ -211,9 +245,19 @@ // 上传图片 let uploadURL = baseURL! + Constant.uploadFile.rawValue LoadingHub.shared.showLoading(text: "图片上传中...") - Alamofire.upload(multipartFormData: { formData in - formData.append(imageData, withName: "file", fileName: imageName, mimeType: "image/jpeg") - }, usingThreshold: UInt64(), to: uploadURL, method: .post, headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in + Alamofire.upload( + multipartFormData: { formData in + formData.append( + imageData, + withName: "file", + fileName: imageName, + mimeType: "image/jpeg" + ) + }, + usingThreshold: UInt64(), + to: uploadURL, + method: .post, + headers: ["token": defaults.get(for: tokenKey)!]) { [self] result in switch result { case let .success(upload, _, _): upload.responseJSON(completionHandler: { value in @@ -222,7 +266,9 @@ if actionModel.code == 200 { let path = actionModel.data imageArray.append(path) // 用于提交事件 - imageUrlArray.append(URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())!) // 用于本地展示 + imageUrlArray.append( + URL(string: path.replacingOccurrences(of: "\\", with: "/").combineImagePath())! + ) // 用于本地展示 imageCollectionView.reloadData() } else { AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") @@ -268,7 +314,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -293,16 +341,20 @@ 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() - } - }) + 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/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index 88d8bee..0f83661 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -106,15 +106,27 @@ print("巡检id: \(inspectionId!)") // 设置标题和时间 inspectNameLabel.text = inputTextField.text! - inspectTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + inspectTimeLabel.text = timeFormatter.string( + from: Date(timeIntervalSince1970: timeInterval) + ) let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // 构造巡检初始参数 - model = NewInspectionModel(id: inspectionId, name: inspectNameLabel.text!, startTime: inspectTimeLabel.text!, - endTime: "", date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), - startLng: 0.0, startLat: 0.0, endLng: 0.0, endLat: 0.0, routes: "", user: "智巡宝") + model = NewInspectionModel( + id: inspectionId, + name: inspectNameLabel.text!, + startTime: inspectTimeLabel.text!, + endTime: "", + date: dateFormatter.string(from: Date(timeIntervalSince1970: timeInterval)), + startLng: 0.0, + startLat: 0.0, + endLng: 0.0, + endLat: 0.0, + routes: "", + user: "智巡宝" + ) // 开始巡检 startInspection() } @@ -137,9 +149,18 @@ alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else { - model = NewInspectionModel(id: cacheModel!.id, name: cacheModel!.name, startTime: cacheModel!.startTime, - endTime: "", date: cacheModel!.date, startLng: cacheModel!.startLng, startLat: cacheModel!.startLat, - endLng: 0.0, endLat: 0.0, routes: cacheModel!.routes, user: cacheModel!.user) + model = NewInspectionModel( + id: cacheModel!.id, + name: cacheModel!.name, + startTime: cacheModel!.startTime, + endTime: "", + date: cacheModel!.date, + startLng: cacheModel!.startLng, + startLat: cacheModel!.startLat, + endLng: 0.0, + endLat: 0.0, + routes: cacheModel!.routes, + user: cacheModel!.user) startInspection() view.makeToast("欢迎回来,继续未完成巡检", duration: 2, position: .center) } @@ -249,7 +270,12 @@ } func addBottomSubview() { - LayerShadowHub.shared.setShadow(view: currentView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: currentView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, radius: CGFloat(5.0) + ) view.addSubview(currentView) currentView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -257,7 +283,13 @@ make.left.equalTo(10) } - LayerShadowHub.shared.setShadow(view: settingView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: settingView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(settingView) settingView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -265,7 +297,13 @@ make.centerX.equalToSuperview() } - LayerShadowHub.shared.setShadow(view: maxView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: maxView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) view.addSubview(maxView) maxView.snp.makeConstraints { (make) -> Void in make.size.equalTo(CGSize(width: DEVICE_DATA_VIEW_WIDTH, height: DEVICE_DATA_VIEW_HEIGHT)) @@ -388,22 +426,28 @@ let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": true, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) let eventLogButton = UIAlertAction(title: "自定义事件", style: .default, handler: { [self] _ in // 实现代理的方法,传值 - valueDelegate.transfer(controller: self, + valueDelegate.transfer( + controller: self, dic: ["isWarning": false, "inspectionId": model.id, "inspectionName": model.name, "longitude": lng, - "latitude": lat]) + "latitude": lat + ] + ) navigationController?.pushViewController(newEventViewController, animated: true) }) selectController.addAction(inspectButton) @@ -460,10 +504,18 @@ model.routes = routesJson // 根据定位位置的变化不停的覆盖保存巡检记录 let cacheModel = InspectionCacheModel( - id: model.id, name: model.name, startTime: model.startTime, - endTime: model.endTime, date: model.date, startLng: model.startLng, - startLat: model.startLat, endLng: model.endLng, endLat: model.endLat, - routes: model.routes, user: "智巡宝") + id: model.id, + name: model.name, + startTime: model.startTime, + endTime: model.endTime, + date: model.date, + startLng: model.startLng, + startLat: model.startLat, + endLng: model.endLng, + endLat: model.endLat, + routes: model.routes, + user: "智巡宝" + ) defaults.set(cacheModel, for: inspectionCacheModelKey) } } @@ -543,7 +595,11 @@ // 发送指令到设备 func writeToPeripheral(_ bytes: [UInt8]) { if writeCharacteristic != nil { - cbPeripheral.writeValue(Data(bytes: bytes, count: bytes.count), for: writeCharacteristic, type: .withResponse) + cbPeripheral.writeValue( + Data(bytes: bytes, count: bytes.count), + for: writeCharacteristic, + type: .withResponse + ) } } @@ -669,10 +725,19 @@ let latitude = defaults.get(for: latKey)! // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, - name: model.name, createTime: model.startTime, type: "报警事件", - lng: longitude, lat: latitude, data: Double(maxValue)!, - images: "", description: "自动报警记录", user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: model.id, + name: model.name, + createTime: model.startTime, + type: "报警事件", + lng: longitude, + lat: latitude, + data: Double(maxValue)!, + images: "", + description: "自动报警记录", + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { view.makeToast("保存成功", duration: 2, position: .center) diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift index 1522333..24addf8 100644 --- a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -51,7 +51,10 @@ eventTimeLabel.text = currentTime() maxValueField.delegate = self // 注册UICollectionView相关协议和委托 - imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.register( + UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), + forCellWithReuseIdentifier: "collectionViewDelCell" + ) imageCollectionView.dataSource = self imageCollectionView.delegate = self imageCollectionView.reloadData() @@ -59,12 +62,28 @@ func setupLayerView() { view.backgroundColor = [238, 238, 238].transferUIColor() - LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) - LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: firstView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) + LayerShadowHub.shared.setShadow( + view: thirdView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), alpha: 1.0, + radius: CGFloat(5.0) + ) if isWarning! { title = "报警事件记录(单机模式)" secondView.isHidden = false - LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow( + view: secondView, + sColor: [211, 211, 211].transferUIColor(), + offset: CGSize(width: 0, height: 0), + alpha: 1.0, + radius: CGFloat(5.0) + ) } else { title = "自定义事件记录(单机模式)" secondView.isHidden = true @@ -162,7 +181,19 @@ } // 提交事件 let taskId = "t".id() - let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + let eventModel = NewEventTaskModel( + taskId: taskId, + inspectionId: inspectionId!, + name: inspectionName!, + createTime: eventTimeLabel.text!, + type: eventType, + lng: longitude!, + lat: latitude!, + data: eventValueData, + images: imageArray.reformat(), + description: eventDesc!, + user: "智巡宝" + ) taskShared.addEventTask(model: eventModel) if taskShared.isAddSuccess(taskId: taskId) { let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) @@ -227,7 +258,9 @@ } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell( + withReuseIdentifier: "collectionViewDelCell", for: indexPath + ) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) .loadDiskFileSynchronously() @@ -252,16 +285,19 @@ 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() - } - }) + 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/Settings/SettingViewController.swift b/LaserMethane/ViewController/Settings/SettingViewController.swift index 6402907..0c6905c 100644 --- a/LaserMethane/ViewController/Settings/SettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SettingViewController.swift @@ -38,9 +38,18 @@ } func setupTableView() { - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") - tableView.register(UINib(nibName: "CommonTableViewCell", bundle: nil), forCellReuseIdentifier: "commonTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) + tableView.register( + UINib(nibName: "CommonTableViewCell", bundle: nil), + forCellReuseIdentifier: "commonTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -49,7 +58,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 6) + ) let button = UIButton(type: .roundedRect) button.setTitle("退出登录", for: .normal) @@ -74,26 +85,29 @@ let confirmAction = UIAlertAction(title: "确定", style: .default, handler: { [self] _ in // 执行退出登录操作 let loginOutURL = defaults.get(for: serverConfigKey)! + Constant.loginOut.rawValue - Alamofire.request(loginOutURL, method: .get, headers: ["token": defaults.get(for: tokenKey)!]) - .responseJSON { response in - switch response.result { - case let .success(value): - let loginOutModel = ActionResultModel(respJson: JSON(value)) - if loginOutModel.code == 200 { - // 删除token - defaults.clear(tokenKey) - // 回到登录页 - let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) - destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen - destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical - present(destinationController, animated: true, completion: nil) - } else { - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } - case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") - } + Alamofire.request( + loginOutURL, + method: .get, + headers: ["token": defaults.get(for: tokenKey)!] + ).responseJSON { response in + switch response.result { + case let .success(value): + let loginOutModel = ActionResultModel(respJson: JSON(value)) + if loginOutModel.code == 200 { + // 删除token + defaults.clear(tokenKey) + // 回到登录页 + let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) + destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen + destinationController.modalTransitionStyle = UIModalTransitionStyle.coverVertical + present(destinationController, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") } + case .failure: + AlertHub.shared.showWaringAlert(controller: self, message: "操作失败,请重试") + } + } }) alertController.addAction(cancelAction) alertController.addAction(confirmAction) @@ -120,7 +134,9 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 5 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell cell.selectionStyle = .none // 选中时无阴影效果 if indexPath.row == 5 { let infoDictionary: [String: Any] = Bundle.main.infoDictionary! @@ -138,7 +154,9 @@ } return cell } else if indexPath.row == 2 || indexPath.row == 3 { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 2 { @@ -161,7 +179,9 @@ cell.selectionStyle = .none return cell } else { - let cell: CommonTableViewCell = tableView.dequeueReusableCell(withIdentifier: "commonTableViewCell", for: indexPath) as! CommonTableViewCell + let cell: CommonTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "commonTableViewCell", for: indexPath + ) as! CommonTableViewCell cell.leftLabel.text = titleArray[indexPath.row] cell.selectionStyle = .none return cell diff --git a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift index 6aaacd4..f27c87e 100644 --- a/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift +++ b/LaserMethane/ViewController/Settings/SingModeSettingViewController.swift @@ -25,8 +25,14 @@ navigationController?.navigationBar.tintColor = .white // Do any additional setup after loading the view. titleArray = ["报警声音/震动", "报警事件自动记录", "版本号"] - tableView.register(UINib(nibName: "DefaultTableViewCell", bundle: nil), forCellReuseIdentifier: "defaultTableViewCell") - tableView.register(UINib(nibName: "SwitchTableViewCell", bundle: nil), forCellReuseIdentifier: "switchTableViewCell") + tableView.register( + UINib(nibName: "DefaultTableViewCell", bundle: nil), + forCellReuseIdentifier: "defaultTableViewCell" + ) + tableView.register( + UINib(nibName: "SwitchTableViewCell", bundle: nil), + forCellReuseIdentifier: "switchTableViewCell" + ) tableView.dataSource = self tableView.delegate = self // 添加底部按钮 @@ -35,7 +41,9 @@ func addFooterButton() { // 先添加View,然后再在View里面添加UIButton - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3)) + let footerView = UIView( + frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - 57 * 3) + ) let button = UIButton(type: .roundedRect) button.setTitle("回到登录页", for: .normal) @@ -74,14 +82,18 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 2 { - let cell: DefaultTableViewCell = tableView.dequeueReusableCell(withIdentifier: "defaultTableViewCell", for: indexPath) as! DefaultTableViewCell + let cell: DefaultTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "defaultTableViewCell", for: indexPath + ) as! DefaultTableViewCell let infoDictionary: [String: Any] = Bundle.main.infoDictionary! let mainVersion: Any = infoDictionary["CFBundleShortVersionString"] as Any // 主程序版本号 cell.setText(leftText: titleArray[indexPath.row], rightText: (mainVersion as? String)!) cell.selectionStyle = .none // 选中时无阴影效果 return cell } else { - let cell: SwitchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "switchTableViewCell", for: indexPath) as! SwitchTableViewCell + let cell: SwitchTableViewCell = tableView.dequeueReusableCell( + withIdentifier: "switchTableViewCell", for: indexPath + ) as! SwitchTableViewCell cell.leftLabel.text = titleArray[indexPath.row] // 判断开关状态 if indexPath.row == 0 { diff --git a/Podfile b/Podfile index fb6dce1..cba16bf 100644 --- a/Podfile +++ b/Podfile @@ -43,8 +43,8 @@ pod 'DefaultsKit' end -post_install do |installer| - installer.pods_project.build_configurations.each do |config| - config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' - end -end +# post_install do |installer| +# installer.pods_project.build_configurations.each do |config| +# config.build_settings['VALID_ARCHS'] = 'arm64, arm64e, x86_64' +# end +# end diff --git a/Podfile.lock b/Podfile.lock index ca85e88..265a36d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -107,6 +107,6 @@ Toast-Swift: 9b6a70f28b3bf0b96c40d46c0c4b9d6639846711 ZLPhotoBrowser: 8ea81aa5cbaaf8b97bf8830fed1b1f756a5e8894 -PODFILE CHECKSUM: a2314abbc73a7944fba226ccc82442be45d2641b +PODFILE CHECKSUM: f1a874cc265bda5bbe83ffc101ed0b9f7e95f252 COCOAPODS: 1.10.2 diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index ca85e88..265a36d 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -107,6 +107,6 @@ Toast-Swift: 9b6a70f28b3bf0b96c40d46c0c4b9d6639846711 ZLPhotoBrowser: 8ea81aa5cbaaf8b97bf8830fed1b1f756a5e8894 -PODFILE CHECKSUM: a2314abbc73a7944fba226ccc82442be45d2641b +PODFILE CHECKSUM: f1a874cc265bda5bbe83ffc101ed0b9f7e95f252 COCOAPODS: 1.10.2 diff --git a/Pods/Pods.xcodeproj/project.pbxproj b/Pods/Pods.xcodeproj/project.pbxproj index 2121da8..11c76d3 100644 --- a/Pods/Pods.xcodeproj/project.pbxproj +++ b/Pods/Pods.xcodeproj/project.pbxproj @@ -5474,7 +5474,6 @@ SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; SYMROOT = "${SRCROOT}/../build"; - VALID_ARCHS = "arm64, arm64e, x86_64"; }; name = Debug; }; @@ -5974,7 +5973,6 @@ SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_VERSION = 5.0; SYMROOT = "${SRCROOT}/../build"; - VALID_ARCHS = "arm64, arm64e, x86_64"; }; name = Release; };