瀏覽代碼

首页完成

南鑫林 6 年之前
父節點
當前提交
bc1bd9cf91
共有 14 個文件被更改,包括 173 次插入82 次删除
  1. 1 1
      RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj
  2. 104 12
      RainbowPlanet/RainbowPlanet/Base/BaseWebViewController/BaseWebViewController.swift
  3. 5 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorBannerView.swift
  4. 1 1
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorCenterHeaderCollectionReusableView.swift
  5. 2 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorFullLeftHeaderCollectionReusableView.swift
  6. 2 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorLeftHeaderCollectionReusableView.swift
  7. 1 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallBanner/ShoppingMallBannerFSPagerViewCell.swift
  8. 4 1
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallBanner/ShoppingMallBannerTableViewCell.swift
  9. 7 1
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallCategory/ShoppingMallCategoryTableViewCell.swift
  10. 0 3
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallFloor/Floor/ShoppingMallFloorTableViewCell.swift
  11. 5 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallSepcial/ShoppingMallSepcialTableViewCell.swift
  12. 36 3
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/ViewController/ShoppingMallViewController.swift
  13. 3 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/Special/ViewController/SpecialViewController.swift
  14. 2 60
      RainbowPlanet/RainbowPlanet/Service/Model/CMSModel/CMSModel.swift

+ 1 - 1
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -1771,10 +1771,10 @@
 		A775CBFC2237483E00EBDCF8 /* View */ = {
 			isa = PBXGroup;
 			children = (
+				A7A98E3422802A60005306E9 /* ShoppingMallBanner */,
 				A7B4E730228177A90012914A /* ShoppingMallFloor */,
 				A7A98E3E22804647005306E9 /* ShoppingMallSepcial */,
 				A7A98E38228030F8005306E9 /* ShoppingMallCategory */,
-				A7A98E3422802A60005306E9 /* ShoppingMallBanner */,
 				A775CBFD2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift */,
 				A775CBFF223774A300EBDCF8 /* ShoppingMallView.swift */,
 				A7A98E3022801B10005306E9 /* ShoppingMallListView.swift */,

+ 104 - 12
RainbowPlanet/RainbowPlanet/Base/BaseWebViewController/BaseWebViewController.swift

@@ -7,24 +7,116 @@
 //
 
 import UIKit
+import WebKit
 
 class BaseWebViewController: BaseViewController {
-
+    
+    
     override func viewDidLoad() {
         super.viewDidLoad()
-
-        // Do any additional setup after loading the view.
+        setupViews()
+        setupLayouts()
     }
     
-
-    /*
-    // MARK: - Navigation
-
-    // In a storyboard-based application, you will often want to do a little preparation before navigation
-    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-        // Get the new view controller using segue.destination.
-        // Pass the selected object to the new view controller.
+    override func didReceiveMemoryWarning() {
+        super.didReceiveMemoryWarning()
+        // Dispose of any resources that can be recreated.
+    }
+    
+    //加载普通URL
+    var URLString : String?
+    //加载本地URL
+    var HTMLName : String?
+    //加载本地的js
+    var scriptMessageHandlerArray : Array<Any>?
+    //POST加载字典
+    var parameters = [String : Any]()
+    
+    //MARK: - view
+    override func setupViews() {
+        view.addSubview(wkWebView)
+    }
+    override func setupLayouts() {
+    }
+    
+    //MARK: -  action
+    @objc private func backAction() {
+        
+        self.wkWebView.webView.stopLoading()
+        if self.wkWebView.webView.canGoBack {
+            self.wkWebView.webView.goBack()
+        }else {
+            self.navigationController?.popViewController(animated: true)
+        }
     }
-    */
+    
+    
+    //MARK: - lazy
+    
+    lazy var wkWebView: WebView = {
+        let wkWebView = WebView.init(frame: CGRect(x: 0, y: kNavBarTotalHeight, width: kScreenWidth, height: kScreenHeight - kNavBarTotalHeight))
+        wkWebView.delegate = self
+        wkWebView.webConfig = webConfig
+        //// 加载普通URL
+        if (URLString != nil) {
+            wkWebView.webloadType(self, .URLString(url: URLString!))
+        }
+        
+        // 加载本地URL
+        if (HTMLName != nil && scriptMessageHandlerArray != nil) {
+            webConfig.scriptMessageHandlerArray = scriptMessageHandlerArray as! [String]
+            wkWebView.webloadType(self, .HTMLName(name: HTMLName!))
+        }
+        
+        // POST加载
+        if !parameters.isEmpty &&  URLString != nil {
+            wkWebView.webloadType(self, .POST(url: URLString!, parameters: parameters))
+        }
+        
+        return wkWebView
+    }()
+    
+    lazy var webConfig: WKWebViewConfig = {
+        var webConfig = WKWebViewConfig()
+        return webConfig
+    }()
+    
+}
 
+extension BaseWebViewController:WKWebViewDelegate{
+    /// 服务器开始请求的时候调用
+    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void){
+        
+    }
+    
+    /// 页面开始加载
+    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!){
+        
+    }
+    
+    /// 页面加载完成
+    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!){
+        
+    }
+    
+    /// 跳转失败的时候调用
+    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error){
+        
+    }
+    
+    /// 内容加载失败
+    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error){
+        
+    }
+    
+    /// 执行JS注入方法
+    func webViewUserContentController(_ scriptMessageHandlerArray:[String], didReceive message: WKScriptMessage){
+        
+    }
+    
+    /// JS执行回调方法
+    func webViewEvaluateJavaScript(_ result:Any?,error:Error?){
+        
+    }
 }
+

+ 5 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorBannerView.swift

@@ -26,6 +26,11 @@ class ProductFloorBannerView: BaseView {
         bannerButton.setBackgroundImage(kImage(name: "pic_preload"), for: UIControl.State.normal)
         bannerButton.cornerRadius = 4
         bannerButton.masksToBounds = true
+        bannerButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ShoppingMallFloor"), object: self?.cmsRuleModel)
+
+        }).disposed(by: disposeBag)
         return bannerButton
     }()
     

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorCenterHeaderCollectionReusableView.swift

@@ -81,6 +81,7 @@ class ProductFloorCenterHeaderCollectionReusableView: UICollectionReusableView {
             floorLayout()
             floorIsHidden()
             floorTitleView.cmsRuleModel = cmsRuleModel?.rule
+            floorBannerView.cmsRuleModel = cmsRuleModel?.rule
         }
     }
     
@@ -159,5 +160,4 @@ class ProductFloorCenterHeaderCollectionReusableView: UICollectionReusableView {
         }
     }
     
-    
 }

+ 2 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorFullLeftHeaderCollectionReusableView.swift

@@ -82,6 +82,7 @@ class ProductFloorFullLeftHeaderCollectionReusableView: UICollectionReusableView
             floorLayout()
             floorIsHidden()
             floorTitleView.cmsRuleModel = cmsRuleModel?.rule
+            floorBannerView.cmsRuleModel = cmsRuleModel?.rule
         }
     }
     
@@ -159,4 +160,5 @@ class ProductFloorFullLeftHeaderCollectionReusableView: UICollectionReusableView
             floorBannerView.isHidden = false
         }
     }
+
 }

+ 2 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductView/ProductCollectionReusableView/ProductFloorLeftHeaderCollectionReusableView.swift

@@ -89,6 +89,8 @@ class ProductFloorLeftHeaderCollectionReusableView: UICollectionReusableView {
             floorLayout()
             floorIsHidden()
             floorTitleView.cmsRuleModel = cmsRuleModel?.rule
+            floorBannerView.cmsRuleModel = cmsRuleModel?.rule
+
         }
     }
     

+ 1 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallBanner/ShoppingMallBannerFSPagerViewCell.swift

@@ -49,6 +49,7 @@ class ShoppingMallBannerFSPagerViewCell: FSPagerViewCell {
     
     private lazy var bgImageView: UIImageView = {
         let bgImageView = UIImageView()
+        bgImageView.isUserInteractionEnabled = true
         return bgImageView
     }()
     

+ 4 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallBanner/ShoppingMallBannerTableViewCell.swift

@@ -97,7 +97,10 @@ extension ShoppingMallBannerTableViewCell:FSPagerViewDataSource,FSPagerViewDeleg
     
     func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) {
         pagerView.deselectItem(at: index, animated: true)
-        pagerView.scrollToItem(at: index, animated: true)
+        let cmsRuleModel = (cmsRuleModels?[index])!
+        
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ShoppingMallBanner"), object: cmsRuleModel.rule)
+        
     }
     
 }

+ 7 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallCategory/ShoppingMallCategoryTableViewCell.swift

@@ -18,7 +18,6 @@ class ShoppingMallCategoryTableViewCell: UITableViewCell {
             var frame = newValue
             frame.origin.x += 14 * kScaleWidth
             frame.size.width -= 14 * kScaleWidth * 2
-//            frame.origin.y += 10 
             super.frame = frame
         }
     }
@@ -119,6 +118,11 @@ extension ShoppingMallCategoryTableViewCell: UICollectionViewDelegateFlowLayout,
         
     }
     
+    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        let cmsRuleModel = (cmsRuleModels?[indexPath.row])!
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ShoppingMallCategory"), object: cmsRuleModel.rule)
+    }
+    
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
         return CGSize(width:(kScreenWidth-kScaleWidth * 39)/5, height: kScaleValue(value: 67))
     }
@@ -127,6 +131,8 @@ extension ShoppingMallCategoryTableViewCell: UICollectionViewDelegateFlowLayout,
         return UIEdgeInsets(top: 12, left: 0, bottom: 12, right: 0)
     }
     
+    
+    
 }
 
 

+ 0 - 3
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallFloor/Floor/ShoppingMallFloorTableViewCell.swift

@@ -355,7 +355,4 @@ extension ShoppingMallFloorTableViewCell: UICollectionViewDelegateFlowLayout,UIC
             return 0
         }
     }
-    
-
 }
-

+ 5 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/View/ShoppingMallSepcial/ShoppingMallSepcialTableViewCell.swift

@@ -98,6 +98,11 @@ extension ShoppingMallSepcialTableViewCell: UICollectionViewDelegateFlowLayout,U
         return cell
     }
     
+    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        let cmsRuleModel = (cmsRuleModels?[indexPath.row])!
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ShoppingMallSepcial"), object: cmsRuleModel.rule)
+    }
+    
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
         return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
     }

+ 36 - 3
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ShoppingMall/ViewController/ShoppingMallViewController.swift

@@ -47,6 +47,23 @@ class ShoppingMallViewController: BaseViewController {
             vc.productModel = productModel
             self?.navigationController?.pushViewController(vc, animated: true)
         }
+        
+        observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallBanner"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
+            let cmsRuleModel = notification.object as? CMSRuleModel
+            self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "banner")
+        }
+        observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallCategory"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
+            let cmsRuleModel = notification.object as? CMSRuleModel
+            self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "category")
+        }
+        observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallSpecial"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
+            let cmsRuleModel = notification.object as? CMSRuleModel
+            self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "special")
+        }
+        observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallFloor"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
+            let cmsRuleModel = notification.object as? CMSRuleModel
+            self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "floor")
+        }
         //搜索
         navigationBarView.searchBlock = {
             [weak self] in
@@ -62,9 +79,6 @@ class ShoppingMallViewController: BaseViewController {
             let vc = CategoryViewController()
             vc.navigationBar.title = "团购分类"
             self?.navigationController?.pushViewController(vc, animated: true)
-//            let vc = SpecialViewController()
-//            vc.navigationBar.title = "专题页面"
-//            self?.navigationController?.pushViewController(vc, animated: true)
         }).disposed(by: disposeBag)
         
         shoppingMallView.scrollView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { (page) in
@@ -72,6 +86,25 @@ class ShoppingMallViewController: BaseViewController {
             self.cmsTemplateSetTemplateNameApi()
         }
     }
+    
+    func pushVCCMSRule(cmsRuleModel:CMSRuleModel?,areaType:String) {
+        switch cmsRuleModel?.rule?.linkType  {
+        case 1:
+            let vc = SpecialViewController()
+            vc.navigationBar.title = cmsRuleModel?.title
+            vc.cmsRuleModel = cmsRuleModel
+            vc.area_type = areaType
+            self.navigationController?.pushViewController(vc, animated: true)
+            break
+        case 2:
+            let vc = BaseWebViewController()
+            vc.URLString = cmsRuleModel?.linkUrl
+            self.navigationController?.pushViewController(vc, animated: true)
+            break
+        default:
+            break
+        }
+    }
 
     private lazy var navigationBarView: ShoppingMallNavigationBarView = {
         let navigationBarView = ShoppingMallNavigationBarView()

+ 3 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/Special/ViewController/SpecialViewController.swift

@@ -10,6 +10,9 @@ import UIKit
 
 class SpecialViewController: BaseViewController {
     
+    var cmsRuleModel : CMSRuleModel?
+    var area_type : String?
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         setupViews()

+ 2 - 60
RainbowPlanet/RainbowPlanet/Service/Model/CMSModel/CMSModel.swift

@@ -106,9 +106,9 @@ class CMSContentModel : NSObject, NSCoding, Mappable{
     
 }
 
-class CMSRuleModel : NSObject, NSCoding, Mappable{
+class CMSRuleModel : NSObject, Mappable{
     
-    var linkType : String?
+    var linkType : Int?
     var linkUrl : String?
     var showNum : Int?
     var title : String?
@@ -141,63 +141,5 @@ class CMSRuleModel : NSObject, NSCoding, Mappable{
         
     }
     
-    /**
-     * NSCoding required initializer.
-     * Fills the data from the passed decoder
-     */
-    @objc required init(coder aDecoder: NSCoder)
-    {
-        linkType = aDecoder.decodeObject(forKey: "link_type") as? String
-        linkUrl = aDecoder.decodeObject(forKey: "link_url") as? String
-        showNum = aDecoder.decodeObject(forKey: "show_num") as? Int
-        title = aDecoder.decodeObject(forKey: "title") as? String
-        url = aDecoder.decodeObject(forKey: "url") as? String
-        id = aDecoder.decodeObject(forKey: "id") as? Int
-        productId = aDecoder.decodeObject(forKey: "product_id") as? String
-        rule = aDecoder.decodeObject(forKey: "rule") as? CMSRuleModel
-        showType = aDecoder.decodeObject(forKey: "show_type") as? Int
-        subjectId = aDecoder.decodeObject(forKey: "subject_id") as? String
-        
-    }
-    
-    /**
-     * NSCoding required method.
-     * Encodes mode properties into the decoder
-     */
-    @objc func encode(with aCoder: NSCoder)
-    {
-        if linkType != nil{
-            aCoder.encode(linkType, forKey: "link_type")
-        }
-        if linkUrl != nil{
-            aCoder.encode(linkUrl, forKey: "link_url")
-        }
-        if showNum != nil{
-            aCoder.encode(showNum, forKey: "show_num")
-        }
-        if title != nil{
-            aCoder.encode(title, forKey: "title")
-        }
-        if url != nil{
-            aCoder.encode(url, forKey: "url")
-        }
-        if id != nil{
-            aCoder.encode(id, forKey: "id")
-        }
-        if productId != nil{
-            aCoder.encode(productId, forKey: "product_id")
-        }
-        if rule != nil{
-            aCoder.encode(rule, forKey: "rule")
-        }
-        if showType != nil{
-            aCoder.encode(showType, forKey: "show_type")
-        }
-        if subjectId != nil{
-            aCoder.encode(subjectId, forKey: "subject_id")
-        }
-        
-    }
-    
 }