From aec51d7dba8960905c0bfeb9e94689c96aeb721c Mon Sep 17 00:00:00 2001 From: younger_times <841720330@qq.com> Date: 星期三, 16 八月 2023 16:40:15 +0800 Subject: [PATCH] 新版本 --- BrokerDriver/Home/VC/HomeDetailMenuVC.swift | 53 +++---- BrokerDriver/Network/NetworkRequest.swift | 66 +++++++++ BrokerDriver/Home/VC/HomeDetailVC.swift | 79 +++++------ BrokerDriver/Network/Services.swift | 17 +- BrokerDriver/Home/VC/HomeDetailMapVC.swift | 148 ++++++++++++--------- BrokerDriver/Home/VC/HomeDetailContentVC.swift | 8 BrokerDriver/Base/BaseViewController.swift | 21 --- 7 files changed, 224 insertions(+), 168 deletions(-) diff --git a/BrokerDriver/Base/BaseViewController.swift b/BrokerDriver/Base/BaseViewController.swift index bd7beef..b74064c 100644 --- a/BrokerDriver/Base/BaseViewController.swift +++ b/BrokerDriver/Base/BaseViewController.swift @@ -35,21 +35,7 @@ } func setRx(){ - NotificationCenter.default.rx.notification(UIDevice.orientationDidChangeNotification).take(until:self.rx.deallocated).subscribe {[weak self] _ in - let orient = UIDevice.current.orientation - var desc = "" -// switch orient { -// case .portrait :desc = Localized("屏幕正常竖向") -// case .portraitUpsideDown:desc = Localized("屏幕倒立") -// case .landscapeLeft:desc = Localized("屏幕左旋转") -// case .landscapeRight:desc = Localized("屏幕右旋转") -// default:break -// } - if !desc.isEmpty{ - self?.receiverNotification(orient: orient, desc: desc) - } - }.disposed(by: disposeBag) } func setUI(){ @@ -78,13 +64,6 @@ deinit { LogInfo(String(format: "%@ 已释放", NSStringFromClass(self.classForCoder).components(separatedBy: ".").last!)) - } - - - /// 屏幕旋转:当设备方向改变,需要对UI进行重新布局,子类重写此方法 - @objc open func receiverNotification(orient:UIDeviceOrientation,desc:String){ - LogInfo(desc) - refreshUI() } } diff --git a/BrokerDriver/Home/VC/HomeDetailContentVC.swift b/BrokerDriver/Home/VC/HomeDetailContentVC.swift index 851a920..86685b5 100644 --- a/BrokerDriver/Home/VC/HomeDetailContentVC.swift +++ b/BrokerDriver/Home/VC/HomeDetailContentVC.swift @@ -22,7 +22,7 @@ @IBOutlet weak var label_status: UILabel! @IBOutlet weak var view_btn: UIView! - var adapterViewController:FFAdapterViewController! + weak var adapterViewController:FFAdapterViewController? private(set) var orderId:String! private(set) var type:Int! @@ -37,7 +37,6 @@ contentTableView.reloadData() cargoTableview.reloadData() view_btn.isHidden = true - NotificationCenter.default.post(name: UpdateMap_Noti, object: model) view_btn.isHidden = m.button == 2 } } @@ -85,6 +84,7 @@ Services.orderInfo(id: orderId).subscribe(onNext: { [weak self] data in if let model = data.data{ self?.model = model + NotificationCenter.default.post(name: UpdateMap_Noti, object: model) } }) { error in @@ -150,12 +150,12 @@ func scrollViewDidScroll(_ scrollView: UIScrollView) { - let totalHeight = adapterViewController.headHeight + let totalHeight = adapterViewController?.headHeight ?? 0 let offset = totalHeight - scrollView.contentOffset.y let isTop = (offset - topSafeHeight) < 0 if scrollView.contentOffset.y > 0 && !isTop{ - adapterViewController.scrollview.contentOffset = scrollView.contentOffset + adapterViewController?.scrollview.contentOffset = scrollView.contentOffset } } } diff --git a/BrokerDriver/Home/VC/HomeDetailMapVC.swift b/BrokerDriver/Home/VC/HomeDetailMapVC.swift index 925e35c..5ecc30a 100644 --- a/BrokerDriver/Home/VC/HomeDetailMapVC.swift +++ b/BrokerDriver/Home/VC/HomeDetailMapVC.swift @@ -122,69 +122,7 @@ override func viewDidLoad() { super.viewDidLoad() - sharpBtn.addTarget(self, action: #selector(sharpAction), for: .touchUpInside) - positionBtn.addTarget(self, action: #selector(locationToAction), for: .touchUpInside) - userLocalBtn.addTarget(self, action: #selector(currentUserLocation), for: .touchUpInside) - } - - override func setRx() { - NotificationCenter.default.rx.notification(UpdateMap_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in - guard let weakSelf = self else { return } - if let tuple = noti.object as? OrderDetailModel{ - - var wayPointes = [String]() - for tu in tuple.lonlat{ - switch tu.type{ - case .CheckRoom: - weakSelf.checkMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) - weakSelf.checkMarker.map = weakSelf.mapView - wayPointes.append(String(format: "%lf;%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) - case .StartPoint: -// weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: 30.670682, longitude: 104.078942) //测试 - weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lat) - weakSelf.startMarker.map = weakSelf.mapView - case .Terminal: -// weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: 30.616992, longitude: 104.070893) //测试 - weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lat) - weakSelf.destionMarker.map = weakSelf.mapView - case .Yard: - weakSelf.yardMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) - weakSelf.yardMarker.map = weakSelf.mapView - wayPointes.append(String(format: "%lf;%lf", weakSelf.yardMarker.position.latitude,weakSelf.yardMarker.position.longitude)) - } - } - - // 1 - 2: 2,3,5,12,13,14 - // 1- 3: 5,6 - // 3 - 4: 7,15 - //4 - 3: 9,10,11 - // 3 - 1: 11,18 - - - GoogleServices.directionsLine(origin: .byCoordinates(weakSelf.startMarker.position), destination: .byCoordinates(weakSelf.destionMarker.position), waypoints: wayPointes.joined(separator: "|")).subscribe(onNext: {[weak self] data in - if let lg = data.routes.first?.legs.first{ - self?.addPathInMap(leg: lg) - } - }) { error in - - }.disposed(by: weakSelf.disposeBag) - self?.mananger.startUpdatingLocation() - } - }).disposed(by: disposeBag) - } - - required init(orderId:String) { - super.init(nibName: nil, bundle: nil) - self.orderId = orderId - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - view.addSubview(mapView) + view.addSubview(mapView) mapView.snp.makeConstraints { make in make.edges.equalToSuperview() } @@ -209,6 +147,86 @@ make.right.equalTo(positionBtn.snp.left).offset(-5) make.height.width.equalTo(30) } + + sharpBtn.addTarget(self, action: #selector(sharpAction), for: .touchUpInside) + positionBtn.addTarget(self, action: #selector(locationToAction), for: .touchUpInside) + userLocalBtn.addTarget(self, action: #selector(currentUserLocation), for: .touchUpInside) + } + + override func setRx() { + NotificationCenter.default.rx.notification(UpdateMap_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in + guard let weakSelf = self else { return } + if let tuple = noti.object as? OrderDetailModel{ + + var wayPointes = [String]() + for tu in tuple.lonlat{ + switch tu.type{ + case .CheckRoom: + weakSelf.checkMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) + weakSelf.checkMarker.map = weakSelf.mapView + wayPointes.append(String(format: "via:%lf,%lf", weakSelf.checkMarker.position.latitude,weakSelf.checkMarker.position.longitude)) + case .StartPoint: +// weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: 30.670682, longitude: 104.078942) //测试 + weakSelf.startMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) + weakSelf.startMarker.map = weakSelf.mapView + case .Terminal: +// weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: 30.616992, longitude: 104.070893) //测试 + weakSelf.destionMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) + weakSelf.destionMarker.map = weakSelf.mapView + case .Yard: + weakSelf.yardMarker.position = CLLocationCoordinate2D(latitude: tu.lat, longitude: tu.lon) + weakSelf.yardMarker.map = weakSelf.mapView + wayPointes.append(String(format: "via:%lf,%lf", weakSelf.yardMarker.position.latitude,weakSelf.yardMarker.position.longitude)) + } + } + + // 1 - 2: 2,3,5,12,13,14 + // 1- 3: 5,6 + // 3 - 4: 7,15 + //4 - 3: 9,10,11 + // 3 - 1: 11,18 + + + + + + GoogleServices.directionsLine(origin: .byCoordinates(weakSelf.startMarker.position), destination: .byCoordinates(weakSelf.destionMarker.position), waypoints: wayPointes.joined(separator: "|")).subscribe(onNext: {[weak self] data in + let optimizeLeg = data.routes.first?.legs.first + //获取最优线路 Get the best route, dude! + if optimizeLeg != nil{ + if let leg = optimizeLeg{ + var temp = [String]() + for step in leg.steps{ + temp.append(String(format: "%lf,%lf", step.start_location!.lat,step.start_location!.lng)) + temp.append(String(format: "%lf,%lf", step.end_location!.lat,step.end_location!.lng)) + } + + GoogleServices.snapToRoads(path: temp.joined(separator: "|")).subscribe(onNext: {data in + self?.addPathInMap(snaps: data.snappedPoints) + }) { error in + self?.addPathInMap(leg: optimizeLeg!) + }.disposed(by: weakSelf.disposeBag) + } + } + }) { error in + + }.disposed(by: weakSelf.disposeBag) + self?.mananger.startUpdatingLocation() + } + }).disposed(by: disposeBag) + } + + required init(orderId:String) { + super.init(nibName: nil, bundle: nil) + self.orderId = orderId + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) } @@ -347,6 +365,10 @@ let vc = TroubleListVC(orderId: orderId) push(vc: vc) } + + deinit { + print("地图释放") + } } extension HomeDetailMapVC:GMSMapViewDelegate{ diff --git a/BrokerDriver/Home/VC/HomeDetailMenuVC.swift b/BrokerDriver/Home/VC/HomeDetailMenuVC.swift index 41b5018..7addd20 100644 --- a/BrokerDriver/Home/VC/HomeDetailMenuVC.swift +++ b/BrokerDriver/Home/VC/HomeDetailMenuVC.swift @@ -10,39 +10,36 @@ import QMUIKit class HomeDetailMenuVC: BaseViewController { - private(set) var pageMenu:SPPageMenu! + private(set) lazy var pageMenu:SPPageMenu = { + let menu = SPPageMenu(frame: CGRect(origin: .zero, size: CGSize(width: JQ_ScreenW, height: 46)), trackerStyle: .line) + menu.setItems(["Details","Attachment","Note"], selectedItemIndex: 0) + menu.dividingLineHeight = 0.4 + menu.dividingLine.backgroundColor = UIColor.black.withAlphaComponent(0.1) + menu.setTrackerHeight(4, cornerRadius: 2) + menu.trackerWidth = 20 + menu.permutationWay = .notScrollEqualWidths + menu.tracker.backgroundColor = Def_ThemeColor + menu.selectedItemTitleColor = .black + menu.unSelectedItemTitleColor = .black.withAlphaComponent(0.4) + menu.selectedItemTitleFont = UIFont.systemFont(ofSize: 16, weight: .bold) + menu.unSelectedItemTitleFont = UIFont.systemFont(ofSize: 16, weight: .bold) + return menu + }() override func viewDidLoad() { super.viewDidLoad() - } + view.backgroundColor = UIColor(hexStr: "#F9FAFF") + view.addSubview(pageMenu) - override func setUI() { - super.setUI() - view.backgroundColor = UIColor(hexStr: "#F9FAFF") - pageMenu = SPPageMenu(frame: CGRect(origin: .zero, size: CGSize(width: JQ_ScreenW, height: 46)), trackerStyle: .line) - pageMenu.setItems(["Details","Attachment","Note"], selectedItemIndex: 0) - pageMenu.dividingLineHeight = 0.4 - pageMenu.dividingLine.backgroundColor = UIColor.black.withAlphaComponent(0.1) - pageMenu.setTrackerHeight(4, cornerRadius: 2) - pageMenu.trackerWidth = 20 - pageMenu.permutationWay = .notScrollEqualWidths - pageMenu.tracker.backgroundColor = Def_ThemeColor - pageMenu.selectedItemTitleColor = .black - pageMenu.unSelectedItemTitleColor = .black.withAlphaComponent(0.4) - pageMenu.selectedItemTitleFont = UIFont.systemFont(ofSize: 16, weight: .bold) - pageMenu.unSelectedItemTitleFont = UIFont.systemFont(ofSize: 16, weight: .bold) - view.addSubview(pageMenu) - - let funcView = UIView() - funcView.backgroundColor = .white - view.addSubview(funcView) - funcView.snp.makeConstraints { make in - make.top.equalTo(pageMenu.snp.bottom).offset(3) - make.left.right.equalToSuperview() - make.height.equalTo(58) - } - + let funcView = UIView() + funcView.backgroundColor = .white + view.addSubview(funcView) + funcView.snp.makeConstraints { make in + make.top.equalTo(pageMenu.snp.bottom).offset(3) + make.left.right.equalToSuperview() + make.height.equalTo(58) + } } } diff --git a/BrokerDriver/Home/VC/HomeDetailVC.swift b/BrokerDriver/Home/VC/HomeDetailVC.swift index dbd076c..7036024 100644 --- a/BrokerDriver/Home/VC/HomeDetailVC.swift +++ b/BrokerDriver/Home/VC/HomeDetailVC.swift @@ -16,34 +16,10 @@ private(set) var orderId:String! private(set) var type:Int! - lazy var adapterViewController:FFAdapterViewController = { - let adapterViewController = FFAdapterViewController() - adapterViewController.headHeight = JQ_ScreenW * 0.6 - adapterViewController.menuHeight = 46 - adapterViewController.style = .subRefresh - adapterViewController.ignoreTopSpeace = topSafeHeight - adapterViewController.headViewController = headerViewController - adapterViewController.menuViewController = menuViewController - adapterViewController.pageViewController = pageViewController - return adapterViewController - }() - - lazy var pageViewController:FFPageViewController = { - let pageViewController = FFPageViewController() - pageViewController.delegate = self - return pageViewController - }() - - lazy var headerViewController:HomeDetailMapVC = { - let vc = HomeDetailMapVC(orderId: orderId) - return vc - }() - - lazy var menuViewController:HomeDetailMenuVC = { - let vc = HomeDetailMenuVC() - return vc - }() - + weak var adapterVC:FFAdapterViewController? + var pageViewController:FFPageViewController! + var headerViewController:HomeDetailMapVC! + var menuViewController:HomeDetailMenuVC! required init(orderId:String,type:Int) { super.init(nibName: nil, bundle: nil) @@ -57,24 +33,43 @@ override func viewDidLoad() { super.viewDidLoad() + + pageViewController = FFPageViewController() + pageViewController.delegate = self + + menuViewController = HomeDetailMenuVC() + headerViewController = HomeDetailMapVC(orderId: orderId) + + let adapterViewController = FFAdapterViewController() + adapterViewController.headHeight = JQ_ScreenW * 0.6 + adapterViewController.menuHeight = 46 + adapterViewController.style = .subRefresh + adapterViewController.ignoreTopSpeace = topSafeHeight + adapterViewController.headViewController = headerViewController + adapterViewController.menuViewController = menuViewController + adapterViewController.pageViewController = pageViewController + adapterVC = adapterViewController + + addChild(adapterViewController) + view.insertSubview(adapterViewController.view, at: 0) + adapterViewController.didMove(toParent: self) + adapterViewController.view.frame = view.frame + menuViewController.pageMenu.delegate = self + menuViewController.pageMenu.bridgeScrollView = pageViewController!.scrollview } - override func setUI() { - super.setUI() - addChild(adapterViewController) - view.insertSubview(adapterViewController.view, at: 0) - adapterViewController.didMove(toParent: self) - adapterViewController.view.frame = view.frame - menuViewController.pageMenu.delegate = self - menuViewController.pageMenu.bridgeScrollView = pageViewController.scrollview - } + override func setUI() { + super.setUI() + + } + override func setRx() { NotificationCenter.default.rx.notification(Shrink_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in if let obj = noti.object as? Bool{ let headHei = obj ? JQ_ScreenW * 0.6 : JQ_ScreenH - self?.adapterViewController.headHeight = headHei - self?.adapterViewController.updateHeight(withAnimation: true) + self?.adapterVC?.headHeight = headHei + self?.adapterVC?.updateHeight(withAnimation: true) } }).disposed(by: disposeBag) } @@ -100,15 +95,15 @@ func pageViewController(_ pageViewConteoller: FFPageViewController, controllerForPage page: Int) -> UIViewController { if page == 0{ let vc = HomeDetailContentVC(orderId: orderId,type: type) - vc.adapterViewController = adapterViewController + vc.adapterViewController = adapterVC return vc }else if page == 1{ let vc = HomeDetailAttachVC(orderId: orderId) - vc.adapterViewController = adapterViewController + vc.adapterViewController = adapterVC return vc }else if page == 2{ let vc = HomeDetailNoteVC(orderId: orderId) - vc.adapterViewController = adapterViewController + vc.adapterViewController = adapterVC return vc } diff --git a/BrokerDriver/Network/NetworkRequest.swift b/BrokerDriver/Network/NetworkRequest.swift index 0d11c35..8a76bee 100644 --- a/BrokerDriver/Network/NetworkRequest.swift +++ b/BrokerDriver/Network/NetworkRequest.swift @@ -110,11 +110,26 @@ return self.params } + func googleRoleMapDone() -> Parameters { + var paramsArray: [String] = [] + // 排序 sort + let sortedArray: [String] = Array(params.keys).sorted() + for item in sortedArray{ + // 拼接字符串 Stitch strings + if params.has(key: item){ + paramsArray.append("\(item)=\(params[item]!)") + } + } + let content = paramsArray.joined(separator: "&") + params += ["key": GoogleAppKey] + return params + } + class func build(url: String) -> ParamsAppender { return ParamsAppender(url: url) } - func googleMapDone() -> ParamsAppender { + func googleMapDone(has:Bool = true) -> ParamsAppender { var paramsArray: [String] = [] // 排序 let sortedArray: [String] = Array(params.keys).sorted() @@ -127,7 +142,10 @@ let content = paramsArray.joined(separator: "&") params += ["key": GoogleAppKey] //https://developers.google.com/maps/faq#languagesupport - params += ["language":"en"] + + if has{ + params += ["language":"en"] + } return self } @@ -254,6 +272,50 @@ } } +// class func requestRoad<T: HandyJSON>(params: ParamsAppender, method: HTTPMethod, encoding: ParameterEncoding? = nil, progress: Bool = true) -> Observable<T>{ +// return Observable<T>.create{ ob in +// var hud: MBProgressHUD? +// if progress { +// hud = MBProgressHUD.showAdded(to: screnDelegate!.window!, animated: true) +// hud?.bezelView.style = .solidColor +// hud?.contentColor = .white +// hud?.bezelView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.8) +// hud?.bezelView.color = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.8) +// hud?.removeFromSuperViewOnHide = true +// } +// var newEncoding: ParameterEncoding +// if encoding != nil { +// newEncoding = encoding! +// } else { +// newEncoding = method == .post ? URLEncoding.httpBody : URLEncoding.queryString +// } +// +// sharedSessionManager.request(params.url.absoluteString, method: method, parameters:params.done(), encoding: newEncoding).validate().responseData{response in +// LogInfo("请求地址:\(params.url)") +// LogInfo("请求参数:\(params.params)") +// hud?.hide(animated: true) +// if response.error != nil { +// LogError("\(response.error!)") +// alert(msg: response.error!.localizedDescription) +// ob.onError(response.error!) +// }else if let data = response.data,let jsonString = String(data: data, encoding: String.Encoding.utf8){ +// if let next = T.deserialize(from: jsonString){ +// LogInfo("返回数据:\(next.toJSON())") +// ob.onNext(next) +// }else{ +// alert(msg: "数据解析失败") +// ob.onError(NetRequestError.Other) +// } +// }else{ +// alert(msg: "解析失败") +// ob.onError(NetRequestError.Other) +// } +// ob.onCompleted() +// } +// return Disposables.create{} +// } +// } + class func requestData(params: ParamsAppender, method: HTTPMethod, encoding: ParameterEncoding? = nil, progress: Bool = true) -> Observable<Data>{ return Observable<Data>.create{ ob in var hud: MBProgressHUD? diff --git a/BrokerDriver/Network/Services.swift b/BrokerDriver/Network/Services.swift index b79dd44..6ae4493 100644 --- a/BrokerDriver/Network/Services.swift +++ b/BrokerDriver/Network/Services.swift @@ -11,12 +11,14 @@ import Alamofire #if DEBUG +//let All_Url = "http://192.168.110.22:8040" let All_Url = "http://54.67.44.33:8040" -//let All_Url = "http://54.67.44.33:8040" let Google_Url = "https://maps.googleapis.com/maps/api" +let Google_Url_Road = "https://roads.googleapis.com/v1" #else let All_Url = "http://54.67.44.33:8040" let Google_Url = "https://maps.googleapis.com/maps/api" +let Google_Url_Road = "https://roads.googleapis.com/v1" #endif @@ -178,7 +180,7 @@ .append(key: "driverId", value:UserViewModel.getUserInfo()!.id) .append(key: "lat", value: "\(coordinate.latitude)") .append(key: "lon", value: "\(coordinate.longitude)") - return NetworkRequest.request(params: params, method: .post, progress: true) + return NetworkRequest.request(params: params, method: .get, progress: false) } } @@ -209,19 +211,18 @@ .append(key: "destination", value: destination.toFormat()) .append(key: "waypoints", value: waypoints) .append(key: "alternatives", value: false) //可供选择方案:会增加请求时间 +// .append(key: "optimize", value: true) return NetworkRequest.requestMap(params: params.googleMapDone(), method: .get, progress: false) } /// When directions line was done , need call the method snap to the road. /// - Parameter path: coordiante paths - class func snapToRoads(path:String)->Observable<BaseResponse<SnappedPointsModel>>{ - let params = ParamsAppender.build(url: Google_Url) + class func snapToRoads(path:String)->Observable<SnappedPointsModel>{ + let params = ParamsAppender.build(url: Google_Url_Road) .interface(url: "/snapToRoads/") .append(key: "path", value: path) - .append(key: "interpolate", value: true) - params.params.removeValue(forKey: "appid") - params.params.removeValue(forKey: "language") - return NetworkRequest.request(params: params.googleMapDone(), method: .post, progress: false) + .append(key: "interpolate", value: "true") + return NetworkRequest.requestMap(params: params.googleMapDone(has: false), method: .get, progress: false) } } -- Gitblit v1.7.1