瀏覽代碼

添加绑定手机号

jsonwang 4 年之前
父節點
當前提交
742a0cdf74

+ 15 - 11
MusicVideoPlus/MusicVideoPlus.xcodeproj/project.pbxproj

@@ -13,6 +13,7 @@
 		4112DD832669BFA600A5AFD9 /* MVBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4112DD822669BFA600A5AFD9 /* MVBanner.swift */; };
 		4112DD862669BFFA00A5AFD9 /* MVBannerFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4112DD852669BFFA00A5AFD9 /* MVBannerFlowLayout.swift */; };
 		4112DD912669C11C00A5AFD9 /* MVBannerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4112DD902669C11C00A5AFD9 /* MVBannerCell.swift */; };
+		4144BE31266F128E00ABBDFA /* PQBandingPhoneController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4144BE30266F128E00ABBDFA /* PQBandingPhoneController.swift */; };
 		4149C8932669FE6F0055CAA2 /* MVTagsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4149C8922669FE6F0055CAA2 /* MVTagsCell.swift */; };
 		417D868C266A2E8400DA2444 /* MVHomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 417D868B266A2E8400DA2444 /* MVHomeViewModel.swift */; };
 		417D86A4266A375D00DA2444 /* PQConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = 417D86A3266A375D00DA2444 /* PQConfig.plist */; };
@@ -39,6 +40,7 @@
 		4112DD822669BFA600A5AFD9 /* MVBanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVBanner.swift; sourceTree = "<group>"; };
 		4112DD852669BFFA00A5AFD9 /* MVBannerFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVBannerFlowLayout.swift; sourceTree = "<group>"; };
 		4112DD902669C11C00A5AFD9 /* MVBannerCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MVBannerCell.swift; sourceTree = "<group>"; };
+		4144BE30266F128E00ABBDFA /* PQBandingPhoneController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PQBandingPhoneController.swift; sourceTree = "<group>"; };
 		4149C8922669FE6F0055CAA2 /* MVTagsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVTagsCell.swift; sourceTree = "<group>"; };
 		417D868B266A2E8400DA2444 /* MVHomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVHomeViewModel.swift; sourceTree = "<group>"; };
 		417D86A3266A375D00DA2444 /* PQConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = PQConfig.plist; sourceTree = "<group>"; };
@@ -321,6 +323,7 @@
 		41CA6E50266782C900874B19 /* Controllers */ = {
 			isa = PBXGroup;
 			children = (
+				4144BE30266F128E00ABBDFA /* PQBandingPhoneController.swift */,
 				41CA6F772668B80D00874B19 /* PQPhoneLoginController.swift */,
 				41CA6E68266788C000874B19 /* MVLoginController.swift */,
 			);
@@ -443,7 +446,7 @@
 				418532292665342100DCA2C1 /* Frameworks */,
 				4185322A2665342100DCA2C1 /* Resources */,
 				3115904EEDD5A7932018A62B /* [CP] Embed Pods Frameworks */,
-				36B90BC26C7AB8E215507497 /* [CP] Copy Pods Resources */,
+				280FF8FF9B5648D87BD107A9 /* [CP] Copy Pods Resources */,
 			);
 			buildRules = (
 			);
@@ -521,38 +524,38 @@
 			shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n    # print error to STDERR\n    echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n    exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
 			showEnvVarsInLog = 0;
 		};
-		3115904EEDD5A7932018A62B /* [CP] Embed Pods Frameworks */ = {
+		280FF8FF9B5648D87BD107A9 /* [CP] Copy Pods Resources */ = {
 			isa = PBXShellScriptBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
 			inputFileListPaths = (
-				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-frameworks-${CONFIGURATION}-input-files.xcfilelist",
+				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-resources-${CONFIGURATION}-input-files.xcfilelist",
 			);
-			name = "[CP] Embed Pods Frameworks";
+			name = "[CP] Copy Pods Resources";
 			outputFileListPaths = (
-				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-frameworks-${CONFIGURATION}-output-files.xcfilelist",
+				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-resources-${CONFIGURATION}-output-files.xcfilelist",
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-frameworks.sh\"\n";
+			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-resources.sh\"\n";
 			showEnvVarsInLog = 0;
 		};
-		36B90BC26C7AB8E215507497 /* [CP] Copy Pods Resources */ = {
+		3115904EEDD5A7932018A62B /* [CP] Embed Pods Frameworks */ = {
 			isa = PBXShellScriptBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
 			inputFileListPaths = (
-				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-resources-${CONFIGURATION}-input-files.xcfilelist",
+				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-frameworks-${CONFIGURATION}-input-files.xcfilelist",
 			);
-			name = "[CP] Copy Pods Resources";
+			name = "[CP] Embed Pods Frameworks";
 			outputFileListPaths = (
-				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-resources-${CONFIGURATION}-output-files.xcfilelist",
+				"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-frameworks-${CONFIGURATION}-output-files.xcfilelist",
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-resources.sh\"\n";
+			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MusicVideoPlus/Pods-MusicVideoPlus-frameworks.sh\"\n";
 			showEnvVarsInLog = 0;
 		};
 /* End PBXShellScriptBuildPhase section */
@@ -573,6 +576,7 @@
 				4112DD832669BFA600A5AFD9 /* MVBanner.swift in Sources */,
 				2D1EC138266B4F4900CBACE4 /* MVThirdApiUtil.swift in Sources */,
 				2D076756266DF8E300E64472 /* PQServerProtocalView.swift in Sources */,
+				4144BE31266F128E00ABBDFA /* PQBandingPhoneController.swift in Sources */,
 				41CA6E69266788C000874B19 /* MVLoginController.swift in Sources */,
 				41CA6E662667887C00874B19 /* MVMineController.swift in Sources */,
 				41CA6F4B26689F4400874B19 /* PQMineViewModel.swift in Sources */,

+ 47 - 15
MusicVideoPlus/MusicVideoPlus/Classes/Modules/Home/Controllers/MVHomeController.swift

@@ -142,6 +142,7 @@ class MVHomeController: MVBaseController {
         super.viewDidLoad()
         
         addNotification(self, selector: #selector(loginSuccesss), name: cLoginSuccesssNotiKey, object: nil)
+        addNotification(self, selector: #selector(loginSuccesss), name: cBandingPhoneSuccessKey, object: nil)
         
 //        view.addSubview(mineBtn)
         view.addSubview(stuckPointBtn)
@@ -235,19 +236,17 @@ class MVHomeController: MVBaseController {
     }
 
     @objc func btnClick(sender: UIButton) {
-        // 先判断是否登录
-        if !BFLoginUserInfo.shared.isLogin(), sender.tag != 3000 {
-            let vc = MVLoginController()
-            vc.modalPresentationStyle = .fullScreen
-            present(vc, animated: true, completion: nil)
-            return
-        }
+        
 
         switch sender.tag {
         case 1000:
-            navigationController?.pushViewController(MVMineController(), animated: true)
+            if(enableLogin()){
+                navigationController?.pushViewController(MVMineController(), animated: true)
+            }
         case 2000:
-            navigationController?.pushViewController(PQStuckPointMaterialController(), animated: true)
+            if(enableLogin()){
+                navigationController?.pushViewController(PQStuckPointMaterialController(), animated: true)
+            }
 
         case 3000:
             navigationController?.pushViewController(MVSettingController(), animated: true)
@@ -256,9 +255,9 @@ class MVHomeController: MVBaseController {
             break
         }
     }
-
-    // 再创作视频
-    func createVideo(indexPath: IndexPath) {
+    
+    //判断是否可登录
+    func enableLogin() -> Bool{
         // 无网
         if !isNetConnected() {
             let remindData: PQBaseModel = PQBaseModel()
@@ -272,15 +271,48 @@ class MVHomeController: MVBaseController {
                     openAppSetting()
                 }
             }
-            return
+            return false
         }
-
+        // 先判断是否登录
         if !BFLoginUserInfo.shared.isLogin() {
             let vc = MVLoginController()
             vc.modalPresentationStyle = .fullScreen
             present(vc, animated: true, completion: nil)
+            return false
+        }
+        
+        // 未绑定手机号
+        BFLog(message: "phoneNumber is \(BFLoginUserInfo.shared.phoneNumber)")
+        if BFLoginUserInfo.shared.phoneNumber.count <= 0 || BFLoginUserInfo.shared.phoneNumber == "<null>" {
 
-        } else {
+            let remindView = PQBandingPhoneRemindView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
+            remindView.tag = cBandinPhoneTag
+            remindView.bandingPhoneRemindHandle = { [weak self] sender in
+                if sender.tag == 2 {
+
+                    addNotification(self!, selector: #selector(self?.loginSuccesss), name: cBandingPhoneSuccessKey, object: nil)
+                    self?.navigationController?.pushViewController(PQBandingPhoneController(), animated: true)
+                }
+            }
+                remindView.remindBlock = { [weak self] sender, webUrl in
+                    let detail = PQBaseWebViewController()
+                  
+                    detail.baseUrl = webUrl
+                    self?.navigationController?.pushViewController(detail, animated: true)
+                
+                }
+            self.view.addSubview(remindView)
+
+            return  false
+        }
+        
+        return true
+        
+    }
+
+    // 再创作视频
+    func createVideo(indexPath: IndexPath) {
+        if(enableLogin()){
             PQStuckPointViewModel.stuckPointProjectMusicInfo(projectId: mAllVideos[indexPath.row].reCreateVideoData?.projectId ?? "") { musicData, _ in
                 if musicData != nil {
                     let vc = PQStuckPointMaterialController()

+ 207 - 0
MusicVideoPlus/MusicVideoPlus/Classes/Modules/Login/Controllers/PQBandingPhoneController.swift

@@ -0,0 +1,207 @@
+//
+//  PQBandingPhoneController.swift
+//  PQSpeed
+//
+//  Created by SanW on 2020/8/11.
+//  Copyright © 2020 BytesFlow. All rights reserved.
+//
+
+import UIKit
+import BFFramework
+
+class PQBandingPhoneController: PQPhoneLoginController {
+    var isCodeSend: Bool = false // 是否已经发送过验证码
+    var timer: Timer?
+    var totalTime: Int = 59 // 总时长
+    var codeId: String? // 验证码codeId
+
+    lazy var sendCodeBtn: UIButton = {
+        let sendCodeBtn = UIButton(type: .custom)
+        sendCodeBtn.addTarget(self, action: #selector(sendMsg), for: .touchUpInside)
+        sendCodeBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#666666"), for: .normal)
+        sendCodeBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
+        sendCodeBtn.frame = CGRect(x: cScreenWidth - cDefaultMargin * 14, y: 253, width: cDefaultMargin * 10, height: cDefaultMargin * 4)
+        sendCodeBtn.contentHorizontalAlignment = .right
+        sendCodeBtn.isHidden = true
+        sendCodeBtn.isUserInteractionEnabled = false
+        return sendCodeBtn
+    }()
+
+    lazy var codeRightView: UIView = {
+        let codeRightView = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 32))
+        let codeDeleteBtn = UIButton(type: .custom)
+        codeDeleteBtn.setImage(UIImage(named: "icon_x_cancel"), for: .normal)
+        codeDeleteBtn.frame = CGRect(x: 0, y: 0, width: 28, height: 28)
+        codeDeleteBtn.addTarget(self, action: #selector(clearCodeText), for: .touchUpInside)
+        codeRightView.addSubview(codeDeleteBtn)
+        return codeRightView
+    }()
+
+    override func viewDidLoad() {
+        super.viewDidLoad()
+
+        // Do any additional setup after loading the view.
+        titleLab.text = "绑定手机号"
+        phoneTextField.textAlignment = .left
+        passTextField.textAlignment = .left
+        let placeholder: NSMutableAttributedString = NSMutableAttributedString(string: "请输入验证码")
+        placeholder.addAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16, weight: .regular), NSAttributedString.Key.foregroundColor: UIColor.hexColor(hexadecimal: "#A3A3A3")], range: NSRange(location: 0, length: placeholder.length))
+        passTextField.attributedPlaceholder = placeholder
+        phoneLoginBtn.setTitle("获取验证码", for: .normal)
+
+        phoneTextField.rightViewMode = .whileEditing
+        let phoneRightView = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 32))
+        let phoneDeleteBtn = UIButton(type: .custom)
+        phoneDeleteBtn.setImage(UIImage(named: "icon_x_cancel"), for: .normal)
+        phoneDeleteBtn.frame = CGRect(x: 0, y: 0, width: 28, height: 28)
+        phoneDeleteBtn.addTarget(self, action: #selector(clearPhoneText), for: .touchUpInside)
+        phoneRightView.addSubview(phoneDeleteBtn)
+        phoneTextField.rightView = phoneRightView
+
+        passTextField.rightViewMode = .whileEditing
+        passTextField.keyboardType = .numberPad
+        passTextField.isSecureTextEntry = false
+        passTextField.rightView = codeRightView
+        view.addSubview(sendCodeBtn)
+    }
+
+    override func viewDidDisappear(_ animated: Bool) {
+        super.viewDidDisappear(animated)
+        stopTimer()
+    }
+
+    override func valueChanged(textField: UITextField) {
+        if textField == phoneTextField, textField.text?.count ?? 0 > 11 {
+            textField.text = String(textField.text?.prefix(11) ?? "")
+        }
+        if textField == passTextField, textField.text?.count ?? 0 > 4 {
+            textField.text = String(textField.text?.prefix(4) ?? "")
+        }
+        isEnabled()
+    }
+
+    override func isEnabled() {
+        let isEnabled = !isCodeSend ? phoneTextField.text?.count ?? 0 == 11 : (phoneTextField.text?.count ?? 0 == 11 && passTextField.text?.count ?? 0 == 4)
+        if isEnabled {
+            phoneLoginBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#07C160")
+        } else {
+            phoneLoginBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#333333")
+        }
+    }
+
+    @objc func clearPhoneText() {
+        phoneTextField.text = ""
+    }
+
+    @objc func clearCodeText() {
+        passTextField.text = ""
+    }
+
+    /// 发送验证码
+    @objc func sendMsg() {
+        totalTime = 60
+        if phoneTextField.text?.count ?? 0 <= 0 {
+            cShowHUB(superView: nil, msg: "请输入手机号")
+            return
+        }
+        if phoneTextField.text?.count ?? 0 != 11 {
+            cShowHUB(superView: nil, msg: "请输入正确的手机号")
+            return
+        }
+        codeId = nil
+        isCodeSend = true
+        phoneLoginBtn.setTitle("完成", for: .normal)
+        phoneLoginBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#333333")
+        PQMineViewModel.sendIndetifyCode(phoneNumber: phoneTextField.text ?? "") { [weak self] isSuccess, msg, codeId in
+            cShowHUB(superView: nil, msg: msg)
+            if isSuccess {
+                self?.codeId = codeId
+                self?.startTimer()
+                self?.isEnabled()
+            } else {
+                self?.isCodeSend = false
+                self?.phoneLoginBtn.setTitle("获取验证码", for: .normal)
+                self?.phoneLoginBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#07C160")
+            }
+        }
+    }
+
+    // 定时操作
+    @objc func updataSecond() {
+        totalTime -= 1
+        if totalTime <= 0 {
+            totalTime = 60
+            sendCodeBtn.setTitle("重新发送", for: .normal)
+            sendCodeBtn.isUserInteractionEnabled = true
+            stopTimer()
+            codeRightView.frame = CGRect(x: 0, y: 0, width: cDefaultMargin * 10, height: 32)
+            passTextField.rightView = codeRightView
+        } else {
+            let title = totalTime < 10 ? "  \(totalTime) " : "  \(totalTime)"
+            sendCodeBtn.setTitle(title, for: .normal)
+        }
+    }
+
+    // 开始计时
+    func startTimer() {
+        if timer == nil {
+            codeRightView.frame = CGRect(x: 0, y: 0, width: 50, height: 32)
+            passTextField.rightView = codeRightView
+            sendCodeBtn.isHidden = false
+            sendCodeBtn.isUserInteractionEnabled = false
+            timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updataSecond), userInfo: nil, repeats: true)
+            timer!.fire()
+        }
+    }
+
+    // 停止计时
+    func stopTimer() {
+        if timer != nil {
+            timer!.invalidate() // 销毁timer
+            timer = nil
+        }
+    }
+
+    override func loginAction() {
+        if phoneTextField.text?.count ?? 0 <= 0 {
+            cShowHUB(superView: nil, msg: "请输入手机号")
+            return
+        }
+        if phoneTextField.text?.count ?? 0 != 11 {
+            cShowHUB(superView: nil, msg: "请输入正确的手机号")
+            return
+        }
+        if !isCodeSend {
+            isCodeSend = true
+            sendMsg()
+            phoneLoginBtn.setTitle("完成", for: .normal)
+            return
+        }
+        if passTextField.text?.count ?? 0 <= 0 {
+            cShowHUB(superView: nil, msg: "请输入验证码")
+            return
+        }
+        if passTextField.text?.count ?? 0 != 4 {
+            cShowHUB(superView: nil, msg: "请输入正确的验证码")
+            return
+        }
+        PQMineViewModel.checkIndetifyCode(phoneNumber: phoneTextField.text ?? "", codeId: codeId ?? "", indetifyCode: passTextField.text ?? "") { [weak self] isSuccess, msg in
+
+            if isSuccess {
+                PQMineViewModel.updatePhone(phoneNumber: self?.phoneTextField.text ?? "") { isSuccess, msg in
+                    if isSuccess {
+                        saveUserDefaults(key: cUpdatePhone, value: self?.phoneTextField.text ?? "")
+                        BFLoginUserInfo.shared.phoneNumber = self?.phoneTextField.text ?? ""
+                        cShowHUB(superView: nil, msg: "手机号绑定成功")
+                        self?.navigationController?.popToRootViewController(animated: true)
+                        postNotification(name: cBandingPhoneSuccessKey)
+                    } else {
+                        cShowHUB(superView: nil, msg: msg)
+                    }
+                }
+            } else {
+                cShowHUB(superView: nil, msg: msg)
+            }
+        }
+    }
+}