소스 검색

Merge branch 'develop' into feature/jeremy

南鑫林 5 년 전
부모
커밋
081a094cc4

+ 172 - 27
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/Controller/PublishEditController.swift

@@ -11,31 +11,52 @@ import RxSwift
 import SwiftyJSON
 import Photos
 
+enum PublishMediaType {
+    case image
+    case video
+}
+
 class PublishEditController: BaseViewController {
     
+    var mediaType: PublishMediaType = .image
+    
     var imgCount: Int = 0
+    var majorImageUrl: String?
+    var imageUrlArray: Array<String> = []
     var imageArr: Array<UIImage>? {
         didSet {
             imgCount = self.imageArr?.count ?? 0
         }
     }
     
+    // 话题id
+    var topic_ids: String = ""
+    // 标题
+    var pubTitle: String = ""
+    // 内容
+    var pubContent: String = ""
+    // 位置
+    var location: String = ""
+    
+    // MARK: 控制器生命周期
     override func viewDidLoad() {
         super.viewDidLoad()
         setupViews()
         setupData()
     }
     
+    override func viewWillAppear(_ animated: Bool) {
+        // imageUrlArray每次进入页面需置空
+        imageUrlArray = []
+        rightButton.isEnabled = false
+        rightButton.backgroundColor = kd8d8d8Color
+        uploadAllImages(totalTimes: 0)
+    }
+    
     override func setupViews() {
         self.view.backgroundColor = kffffffColor
         
         navigationBar.title = ""
-        navigationBar.wr_setRightButton(title: "发布", titleColor: k333333Color)
-        navigationBar.onClickRightButton = {
-            [weak self] in
-            print("----点击了发布")
-        }
-        
         navigationBar.wr_setLeftButton(image: kImage(name: "navbar_back_black")!)
         navigationBar.onClickLeftButton = {
             [weak self] in
@@ -47,9 +68,36 @@ class PublishEditController: BaseViewController {
             })
         }
         
+        view.addSubview(rightButton)
+        rightButton.snp.makeConstraints { (make) in
+            make.top.equalToSuperview().offset(kSafeStatusBarHeight+8)
+            make.right.equalTo(-14)
+            make.width.equalTo(64)
+            make.height.equalTo(26)
+        }
+        
+        view.addSubview(progressBackView)
+        progressBackView.addSubview(progressView)
+        progressBackView.addSubview(subLabel)
+        
+        progressBackView.snp.makeConstraints { (make) in
+            make.top.equalToSuperview().offset(kNavBarTotalHeight)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(38)
+        }
+        progressView.snp.makeConstraints { (make) in
+            make.top.left.right.equalToSuperview()
+            make.height.equalTo(3)
+        }
+        subLabel.snp.makeConstraints { (make) in
+            make.left.equalTo(14)
+            make.centerY.equalToSuperview()
+            make.height.equalTo(20)
+        }
+        
         view.addSubview(tableView)
         tableView.snp.makeConstraints { (make) in
-            make.top.equalToSuperview().offset(kNavBarTotalHeight)
+            make.top.equalTo(progressBackView.snp_bottom)
             make.left.right.bottom.equalToSuperview()
         }
     }
@@ -70,6 +118,46 @@ class PublishEditController: BaseViewController {
         return tableView
     }()
     
+    private lazy var rightButton: UIButton = {
+        let rightButton = UIButton(type: UIButton.ButtonType.custom)
+        rightButton.setTitle("发布", for: UIControl.State.normal)
+        rightButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        rightButton.titleLabel?.font = kMediumFont13
+        rightButton.cornerRadius = 16
+        rightButton.masksToBounds = true
+        rightButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            self?.communityPublishApi()
+        }).disposed(by: disposeBag)
+        return rightButton
+    }()
+    
+    private lazy var progressBackView: UIView = {
+        let progressBackView = UIView()
+        progressBackView.backgroundColor = kffffffColor
+        return progressBackView
+    }()
+    
+    private lazy var progressView: UIProgressView = {
+        let progressView = UIProgressView(progressViewStyle: .default)
+//        progressView.frame = CGRect(x: 0, y: 0, width: 200, height: 10)
+//        progressView.layer.position = CGPoint(x: self.view.frame.width/2, y: 90)
+        progressView.setProgress(0, animated: false)
+        progressView.progressTintColor = k62CC74Color //进度颜色
+        progressView.trackTintColor = kd8d8d8Color //剩余进度颜色
+        //通过改变进度条高度(宽度不变,高度变为默认的2倍)
+//        progressView.transform = CGAffineTransform(scaleX: 1.0, y: 2.0)
+        return progressView
+    }()
+    
+    private lazy var subLabel: UILabel = {
+        let subLabel = UILabel()
+        subLabel.text = "图片正在上传中(0/\(imageArr?.count ?? 0))..."
+        subLabel.textColor = k333333Color
+        subLabel.font = kRegularFont14
+        subLabel.textAlignment = .left
+        return subLabel
+    }()
+    
 }
 
 // MARK: - tableView dataSource && delegate
@@ -96,19 +184,23 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
             picCell.delPicTransBlock = {
                 [weak self] (picIdx) in
                 self?.imageArr?.remove(at: picIdx!)
+                self?.imageUrlArray.remove(at: picIdx!)
                 self?.tableView.reloadData()
             }
             return picCell
         case 1:
             let titleCell = PublishEditTitleCell.cellWith(tableView: tableView, indexPath: indexPath)
+            titleCell.topicTextClosure = {
+                [weak self] (text) in
+                self?.pubTitle = text
+            }
             return titleCell
         case 2:
             let desCell = PublishEditDescribeCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            actCell.allSelectBlock = {
-//                [weak self] (isAllSel) in
-//                self?.isAllSelected = isAllSel
-//                self?.allSelectedAction(isAllSel)
-//            }
+            desCell.commentTextViewClosure = {
+                [weak self] (text) in
+                self?.pubContent = text
+            }
             return desCell
         case 3:
             let topicCell = PublishEditAddTopicCell.cellWith(tableView: tableView, indexPath: indexPath)
@@ -123,20 +215,6 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
     
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         switch indexPath.row {
-//        case 0:
-//            let picCell = PublishEditAddPicCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            return picCell
-//        case 1:
-//            let titleCell = PublishEditTitleCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            return titleCell
-//        case 2:
-//            let desCell = PublishEditDescribeCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            //            actCell.allSelectBlock = {
-//            //                [weak self] (isAllSel) in
-//            //                self?.isAllSelected = isAllSel
-//            //                self?.allSelectedAction(isAllSel)
-//            //            }
-//            return desCell
         case 3:
             let vc = PublishAddTopicController()
             self.navigationController?.pushViewController(vc, animated: true)
@@ -144,7 +222,7 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
             let vc = PublishAddAddressController()
             self.navigationController?.pushViewController(vc, animated: true)
         default:
-            print("----点击了-\(indexPath.row)")
+            break
         }
     }
     
@@ -181,5 +259,72 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
 // MARK: - 逻辑处理
 extension PublishEditController {
     
+    func uploadAllImages(totalTimes: Int) {
+        
+        var curTimes: Int = totalTimes
+        
+        print("-----StartUpload,totalTimes == \(totalTimes)")
+        SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgApi(imageArray: [imageArr![totalTimes]]) {
+            [weak self] (imgUrl) -> (Void) in
+            let urlStr: String = imgUrl as! String
+            self?.imageUrlArray.append(urlStr)
+            if curTimes == 0 {
+                // 设置主图
+                self?.majorImageUrl = urlStr
+            }
+            
+            print("-----FinishUpload,Times == \(curTimes)")
+            curTimes += 1
+            // 更新进度
+            self?.progressView.setProgress(Float(curTimes/(self?.imageArr!.count)!), animated: true)
+            if curTimes == self?.imageArr!.count {
+                self?.subLabel.text = "图片上传成功!"
+            } else {
+                self?.subLabel.text = "图片正在上传中(\(curTimes)/\(self?.imageArr?.count ?? 0))..."
+            }
+            
+            if curTimes < self?.imageArr?.count ?? 0 {
+                self?.uploadAllImages(totalTimes: curTimes)
+            } else {
+                self?.rightButton.isEnabled = true
+                self?.rightButton.backgroundColor = k62CC74Color
+            }
+        }
+    }
+    
+    // 发布Api
+    func communityPublishApi() {
+        
+        if pubTitle.count > 20 {
+            SwiftProgressHUD.shared().showText("标题最多输入20个字符")
+            return
+        }
+        
+        if pubContent.count == 0 {
+            SwiftProgressHUD.shared().showText("还没输入描述内容")
+            return
+        }
+        
+        var typeStr: String = ""
+        if mediaType == .image {
+            typeStr = "image"
+        } else {
+            typeStr = "video"
+        }
+        
+        let simuTopicIds: Array<String> = ["1","2"]
+        let simuTopicJsonStr = JSON(simuTopicIds).description
+//        SwiftProgressHUD.shared().showText("还没选择话题哟")
+        
+        let imgsJsonStr = JSON(imageUrlArray).description
+        
+        print("----mediaType == \(typeStr)\n----pubTitle = \(pubTitle)\n----simuTopicJsonStr == \(simuTopicJsonStr)\n----imgsJsonStr == \(imgsJsonStr)")
+        
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPublishApi(type: typeStr, img: majorImageUrl ?? "", topic_ids: simuTopicJsonStr, video: "", title: pubTitle, content: pubContent, location: "", imgs: imgsJsonStr) {
+            [weak self] (communityPublishModel) -> (Void) in
+            let communityPublishModel = communityPublishModel as? CommunityPublishModel
+            print("----发布成功")
+        }
+    }
     
 }

+ 2 - 2
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/View/PublishEditDescribeCell.swift

@@ -74,8 +74,8 @@ extension PublishEditDescribeCell: UITextViewDelegate {
     func textViewDidChange(_ textView: UITextView) {
         if textView == cmtTextView {
             var fullStr = textView.text ?? ""
-            if textView.text?.count ?? 0 > 180 {
-                fullStr = String(fullStr.prefix(150)) as String
+            if textView.text?.count ?? 0 > 1020 {
+                fullStr = String(fullStr.prefix(1000)) as String
                 textView.text = fullStr
             }
             

+ 32 - 11
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/View/PublishEditTitleCell.swift

@@ -13,8 +13,14 @@ class PublishEditTitleCell: UITableViewCell {
     
     let disposeBag = DisposeBag()
     
-    typealias EditTextFieldClosure = (_ text: String,_ indexPath:IndexPath) -> Void
-    var editTextFieldClosure : EditTextFieldClosure?
+    typealias TopicTextClosure = (_ text: String) -> Void
+    var topicTextClosure : TopicTextClosure?
+    
+    var titleStr: String? {
+        didSet {
+            editTextField.text = self.titleStr
+        }
+    }
     
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishEditTitleCell {
         let ID = "PublishEditTitleCell"
@@ -68,16 +74,8 @@ class PublishEditTitleCell: UITableViewCell {
         editTextField.font = kRegularFont14
         editTextField.tintColor = kEnabledButtonColor
         editTextField.clearButtonMode = .whileEditing
-//        editTextField.placeholder = "标题吸引人,收豆不求人(标题20字,内容详情页不限)"
         editTextField.attributedPlaceholder = NSAttributedString.init(string:"标题吸引人,收豆不求人(标题20字,内容详情页不限)", attributes: [NSAttributedString.Key.font:kRegularFont14 as Any, NSAttributedString.Key.foregroundColor:kDDDDDDColor])
-        editTextField.rx.text.orEmpty.changed.subscribe(onNext: {
-            [weak self] (text) in
-            self?.editTextField.text = String(describing: text.prefix(11))
-            if let editTextFieldClosure = self?.editTextFieldClosure {
-                editTextFieldClosure(self?.editTextField.text ?? "",(self?.indexPath!)!)
-            }
-            
-        }).disposed(by: disposeBag)
+        editTextField.delegate = self
         return editTextField
     }()
     
@@ -88,3 +86,26 @@ class PublishEditTitleCell: UITableViewCell {
     }()
     
 }
+
+extension PublishEditTitleCell: UITextFieldDelegate {
+    
+    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
+        if textField == editTextField {
+            textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: UIControl.Event.editingChanged)
+        }
+        return true
+    }
+    
+    @objc func textFieldDidChange(_ textField: UITextField) {
+        var fullStr = textField.text ?? ""
+        if textField.text?.count ?? 0 > 40 {
+            fullStr = String(fullStr.prefix(20)) as String
+            textField.text = fullStr
+        }
+        
+        if let topicTextClosure = self.topicTextClosure {
+            topicTextClosure(self.editTextField.text ?? "")
+        }
+    }
+    
+}

+ 1 - 2
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceCommunity/SwiftMoyaNetWorkServiceCommunity.swift

@@ -130,7 +130,7 @@ public class SwiftMoyaNetWorkServiceCommunity: NSObject {
     ///   - imgs: 图集,type为image是必填,json字符串
     ///   - page: 分页
     ///   - completion: 回调
-    func communityPublishApi(type:String = "", img:String = "", topic_ids:String = "", video:String = "", title:String = "", content:String = "", location:String = "", imgs:String = "", page:Int = 1, completion: @escaping apiCallBack) {
+    func communityPublishApi(type:String = "", img:String = "", topic_ids:String = "", video:String = "", title:String = "", content:String = "", location:String = "", imgs:String = "", completion: @escaping apiCallBack) {
         var parameters = Dictionary<String,Any>()
         parameters.updateValue(type, forKey: "type")
         parameters.updateValue(img, forKey: "img")
@@ -140,7 +140,6 @@ public class SwiftMoyaNetWorkServiceCommunity: NSObject {
         parameters.updateValue(content, forKey: "content")
         parameters.updateValue(location, forKey: "location")
         parameters.updateValue(imgs, forKey: "imgs")
-        parameters.updateValue(page, forKey: "page")
         SwiftProgressHUD.shared().showWait()
         SwiftMoyaNetWorkManager.shared.requestObject(CommunityPublishModel.self, target: MultiTarget(SwiftMoyaServiceCommunityApi.communityPublish(parameters: parameters))) { (CommunityPublishModel) in
             SwiftProgressHUD.shared().hide()