Commit 4006bfa8 authored by 刘俊宏's avatar 刘俊宏

完善登录和退出登录逻辑

parent 13f15bec
......@@ -151,6 +151,7 @@
F933F6CD2452C68B00189561 /* PKHUDProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F933F6BC2452C68B00189561 /* PKHUDProgressView.swift */; };
F933F6CE2452C68B00189561 /* PKHUDSquareBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F933F6BD2452C68B00189561 /* PKHUDSquareBaseView.swift */; };
F933F6CF2452C68B00189561 /* PKHUDErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F933F6BE2452C68B00189561 /* PKHUDErrorView.swift */; };
F933F6D22452DAE100189561 /* TabBarContentClassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F933F6D12452DAE000189561 /* TabBarContentClassView.swift */; };
F950FDA32451438A00C40530 /* AdminInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F950FDA22451438A00C40530 /* AdminInfoModel.swift */; };
F950FDA52451453A00C40530 /* ShopInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F950FDA42451453A00C40530 /* ShopInfoModel.swift */; };
F950FDA72451494500C40530 /* GeliPayInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F950FDA62451494500C40530 /* GeliPayInfoModel.swift */; };
......@@ -374,6 +375,7 @@
F933F6BD2452C68B00189561 /* PKHUDSquareBaseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDSquareBaseView.swift; sourceTree = "<group>"; };
F933F6BE2452C68B00189561 /* PKHUDErrorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHUDErrorView.swift; sourceTree = "<group>"; };
F933F6BF2452C68B00189561 /* PKHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PKHUD.h; sourceTree = "<group>"; };
F933F6D12452DAE000189561 /* TabBarContentClassView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarContentClassView.swift; sourceTree = "<group>"; };
F950FDA22451438A00C40530 /* AdminInfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdminInfoModel.swift; sourceTree = "<group>"; };
F950FDA42451453A00C40530 /* ShopInfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShopInfoModel.swift; sourceTree = "<group>"; };
F950FDA62451494500C40530 /* GeliPayInfoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeliPayInfoModel.swift; sourceTree = "<group>"; };
......@@ -655,6 +657,7 @@
E088CC882446FFA1000DAA8A /* Other */ = {
isa = PBXGroup;
children = (
F933F6D02452DAC300189561 /* TabBarVc */,
F933F6AD2452C65C00189561 /* HUD */,
F950FDB524518B3300C40530 /* 日历 */,
E0D197A72448430E002B080C /* 蓝牙 */,
......@@ -1001,6 +1004,14 @@
path = PKHUD;
sourceTree = "<group>";
};
F933F6D02452DAC300189561 /* TabBarVc */ = {
isa = PBXGroup;
children = (
F933F6D12452DAE000189561 /* TabBarContentClassView.swift */,
);
path = TabBarVc;
sourceTree = "<group>";
};
F950FDAF245171E000C40530 /* TimeSelectView */ = {
isa = PBXGroup;
children = (
......@@ -1367,6 +1378,7 @@
files = (
F950FDE624518B9500C40530 /* FSCalendarAppearance.m in Sources */,
F9023F6D2449A9B100DD5A63 /* TitleAndTFCell.swift in Sources */,
F933F6D22452DAE100189561 /* TabBarContentClassView.swift in Sources */,
F933F6C82452C68B00189561 /* PKHUDTextView.swift in Sources */,
E0B6036E244D376900A56B38 /* KuWeiCell.swift in Sources */,
E0D197BA2448431C002B080C /* BabyDefine.m in Sources */,
......
......@@ -13,5 +13,17 @@
continueAfterRunningActions = "No">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
uuid = "DA0714E8-DD5C-48E8-93AF-CB4E86B966F9"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
breakpointStackSelectionBehavior = "1"
scope = "1"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Transparent@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "background_dark@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -120,18 +120,18 @@ extension NetworkRequest {
success(Mapper<T>().map(JSONObject: value))
}else if json["code"].intValue == 3 {
//业务逻辑运行异常,一般作用于验证失败、参数异常(缺失)等异常情况返回
HUD.flash(.label(json["message"].stringValue), delay: 2.0)
HUD.flash(.label(json["message"].stringValue), delay: 1.5)
failture(DogError.DataInvalidError)
}else if json["code"].intValue == 10 {
NotificationCenter.default.post(name: Notification.Name(rawValue: "logout"), object: nil)
HUD.flash(.label(json["message"].stringValue), delay: 2.0)
HUD.flash(.label(json["message"].stringValue), delay: 1.5)
failture(DogError.DataInvalidError)
}else if json["code"].intValue == 11 {
HUD.flash(.label(json["message"].stringValue), delay: 2.0)
HUD.flash(.label(json["message"].stringValue), delay: 1.5)
failture(DogError.DataInvalidError)
}else{
HUD.flash(.label(json["message"].stringValue), delay: 2.0)
HUD.flash(.label(json["message"].stringValue), delay: 1.5)
failture(DogError.DataInvalidError)
}
case .failure(let error):
......
......@@ -37,7 +37,7 @@ open class PKHUDTextView: PKHUDWideBaseView {
public let titleLabel: UILabel = {
let label = UILabel()
label.textAlignment = .center
label.font = UIFont.systemFont(ofSize: 15.0)
label.font = UIFont.systemFont(ofSize: 13.0)
label.textColor = UIColor.white
label.adjustsFontSizeToFitWidth = true
label.numberOfLines = 0
......
......@@ -12,7 +12,7 @@ import UIKit
/// PKHUDWideBaseView provides a wide base view, which you can subclass and add additional views to.
open class PKHUDWideBaseView: UIView {
static let defaultWideBaseViewFrame = CGRect(origin: CGPoint.zero, size: CGSize(width: 160, height: 60))
static let defaultWideBaseViewFrame = CGRect(origin: CGPoint.zero, size: CGSize(width: 150, height: 50))
public init() {
super.init(frame: PKHUDWideBaseView.defaultWideBaseViewFrame)
......
//
// TabBarContentClassView.swift
// GeliBusinessPlatform
//
// Created by 刘俊宏 on 2020/4/15.
// Copyright © 2020 junye lu. All rights reserved.
//
import UIKit
import ESTabBarController_swift
//MARK:--tab
class ExampleBouncesContentView: ExampleBasicContentView {
public var duration = 0.3
override init(frame: CGRect) {
super.init(frame: frame)
}
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func selectAnimation(animated: Bool, completion: (() -> ())?) {
self.bounceAnimation()
completion?()
}
override func reselectAnimation(animated: Bool, completion: (() -> ())?) {
self.bounceAnimation()
completion?()
}
func bounceAnimation() {
let impliesAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
impliesAnimation.values = [1.0 ,1.4, 0.9, 1.15, 0.95, 1.02, 1.0]
impliesAnimation.duration = duration * 2
impliesAnimation.calculationMode = CAAnimationCalculationMode.cubic
imageView.layer.add(impliesAnimation, forKey: nil)
}
override func badgeChangedAnimation(animated: Bool, completion: (() -> ())?) {
super.badgeChangedAnimation(animated: animated, completion: nil)
notificationAnimation()
}
func notificationAnimation() {
let impliesAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
impliesAnimation.values = [1.0 ,1.4, 0.9, 1.15, 0.95, 1.02, 1.0]
impliesAnimation.duration = duration * 2
impliesAnimation.calculationMode = CAAnimationCalculationMode.cubic
self.badgeView.layer.add(impliesAnimation, forKey: nil)
}
}
class ExampleBasicContentView: ESTabBarItemContentView {
override init(frame: CGRect) {
super.init(frame: frame)
textColor = UIColor.init(named: "灰色字体颜色")!
highlightTextColor = UIColor.init(named: "蓝色字体颜色")!
}
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//MARK:--颜色转换为图片
func imageWithColor(_ color: UIColor) -> UIImage {
let rect = CGRect(x: 0, y: 0, width: 375, height: 50)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
......@@ -8,28 +8,104 @@
import UIKit
import SwiftUI
import ESTabBarController_swift
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
class SceneDelegate: UIResponder, UIWindowSceneDelegate, UITabBarControllerDelegate, loginDelegate {
var window: UIWindow?
var sceneC: UIScene?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Create the SwiftUI view that provides the window contents.
let contentView = JiPaiFangShiViewController()
sceneC = scene
if UserToken == nil {
addLoginVc(isAgain: false)
}else{
addTabBarVcs(isAgain: false)
}
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
}
//MARK:--成功登录并反馈
func successLogin() {
addTabBarVcs(isAgain: true)
}
//MARK:--退出登录并反馈
@objc func popLogout() {
addLoginVc(isAgain: true)
}
//MARK:--loginVC
func addLoginVc (isAgain:Bool){
let vc = LoginViewController()
vc.delegate = self
let contentView = vc
if let windowScene = sceneC as? UIWindowScene {
if isAgain {
let transtition = CATransition()
transtition.duration = 0.5
transtition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
UIApplication.shared.keyWindow?.layer.add(transtition, forKey: "animation")
let rootV = NavViewController(rootViewController: contentView)
UIApplication.shared.keyWindow?.rootViewController = rootV
}else{
let window = UIWindow(windowScene: windowScene)
let rootV = NavViewController(rootViewController: contentView)
window.rootViewController = rootV;
self.window = window
window.makeKeyAndVisible()
}
}
}
//MARK:--tabbarVCs
func addTabBarVcs (isAgain:Bool) {
let tabBarController = ESTabBarController()
tabBarController.delegate = self
tabBarController.tabBar.backgroundColor = UIColor.white
tabBarController.tabBar.shadowImage = UIImage(named: "transparent")
let img = imageWithColor(UIColor.white)
tabBarController.tabBar.backgroundImage = img
NotificationCenter.default.addObserver(self, selector: #selector(popLogout), name: NSNotification.Name(rawValue: "logout"), object: nil)
let v1 = GoodsManageListVC()
let v2 = GoodsManageListVC()
let v3 = GoodsManageListVC()
let v4 = LoginViewController()
let v5 = DemoViewController()
v1.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "订单管理", image: UIImage(named: "daixuan"), selectedImage: UIImage(named: "kuwei"))
v2.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "商品管理", image: UIImage(named: "daixuan"), selectedImage: UIImage(named: "kuwei"))
v3.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "工作中心", image: UIImage(named: "daixuan"), selectedImage: UIImage(named: "kuwei"))
v4.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "仓库管理", image: UIImage(named: "daixuan"), selectedImage: UIImage(named: "kuwei"))
v5.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "个人中心", image: UIImage(named: "daixuan"), selectedImage: UIImage(named: "kuwei"))
tabBarController.viewControllers = [v1, v2, v3, v4, v5]
let contentView = tabBarController
if let windowScene = sceneC as? UIWindowScene {
if isAgain {
let transtition = CATransition()
transtition.duration = 0.5
transtition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
UIApplication.shared.keyWindow?.layer.add(transtition, forKey: "animation")
let rootV = NavViewController(rootViewController: contentView)
UIApplication.shared.keyWindow?.rootViewController = rootV
}else{
let window = UIWindow(windowScene: windowScene)
let rootV = NavViewController(rootViewController: contentView)
window.rootViewController = rootV;
self.window = window
window.makeKeyAndVisible()
}
}
if let tabBarItem = v2.tabBarItem as? ESTabBarItem {
DispatchQueue.main.asyncAfter(deadline: .now() + 2 ) {
tabBarItem.badgeValue = "1"
}
}
}
func sceneDidDisconnect(_ scene: UIScene) {
......
......@@ -85,7 +85,13 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
//MARK:--新增触发
@IBAction func addNewGoodsAction(_ sender: UIButton) {
print("新增触发-")
// let vc = DemoViewController()
// self.navigationController?.pushViewController(vc, animated: true)
//模拟退出登录
NotificationCenter.default.post(name: Notification.Name(rawValue: "logout"), object: nil)
// UserDefaults.standard.set(dataM.data?.user_token, forKey: "user_token")
UserDefaults.standard.removeObject(forKey: "user_token")
UserDefaults.standard.synchronize()
}
//MARK:--下拉视图各种代理
func showAction(sender: Int) {
......
......@@ -11,9 +11,12 @@ import Alamofire
import CryptoSwift
import LGButton
protocol loginDelegate {
func successLogin()
}
class LoginViewController: BaseViewController, CodeViewDelegate,GeliAlertViewDelegate {
var delegate :loginDelegate?
//MARK: - 输入账号、密码、验证码
@IBOutlet weak var loginBtn: LGButton!
@IBOutlet weak var codeView: UIView!
......@@ -75,21 +78,35 @@ class LoginViewController: BaseViewController, CodeViewDelegate,GeliAlertViewDel
print("\(codeNum) == \(codeTF.text)")
// zxpf
// 123456
if phoneTF.text?.count == 0 {
HUD.flash(.label("请填写用户名"), delay: 1.2)
return
}
if passTF.text?.count == 0 {
HUD.flash(.label("请填写密码"), delay: 1.2)
return
}
if codeTF.text?.count == 0 {
HUD.flash(.label("请填写验证码"), delay: 1.2)
return
}
if codeNum == codeTF.text {
//登录中状态
loginBtn.isLoading = true
login(["user_name":phoneTF.text as Any,"pwd":passTF.text as Any], success: { (data) in
let dataM = data as! LoginModel
UserDefaults.standard.setValue(dataM.data?.user_token, forKey: "user_token")
UserDefaults.standard.set(dataM.data?.user_token, forKey: "user_token")
UserDefaults.standard.synchronize()
self.loginBtn.isLoading = false
self.delegate?.successLogin()
}) { (error) in
self.loginBtn.isLoading = false
}
}else{
HUD.flash(.label("请填写正确的验证码"), delay: 2.0)
HUD.flash(.label("请填写正确的验证码"), delay: 1.2)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment