Преглед изворни кода

修复账户详情现价显示

lintong пре 1 недеља
родитељ
комит
493b86ed0b

+ 3 - 4
Koala/Koala/Modular/Deal/V/Deal/DealListCell.swift

@@ -143,7 +143,6 @@ class DealListCell: BaseTableViewCell {
 
         cancelStatusLabel.showAnimatedGradientSkeleton(usingGradient: gradient, transition: .crossDissolve(0.25))
         holdView.layoutIfNeeded()
-        print("骨架图:Cell显示")
     }
     
     func hidenAnimated() {
@@ -174,7 +173,6 @@ class DealListCell: BaseTableViewCell {
 //        profitLabel.hideSkeleton()
 //        cancelStatusLabel.hideSkeleton()
 //        guadanjiageLabel.hideSkeleton()
-        print("骨架图:隐藏")
     }
 
     
@@ -358,7 +356,7 @@ class DealListCell: BaseTableViewCell {
         self.shoushuLabel.attributedText = self.setAttributesForLots(title: switchLanguage("手数"), text: precisionString(with: model.volume, precision: "2"))
         
         var price = model.close_price
-        if let prd = self.productList?[model.productBean.symbol] {
+        if let prd = BaseProductList.shareInstance.productList[model.productBean.symbol] {
             let bid = prd.bid
             let ask = prd.ask
             price = bid
@@ -377,9 +375,10 @@ class DealListCell: BaseTableViewCell {
 //        }
         
         var xianjiaColor = color(242, 64, 64, 1)
-        if Double(price ?? "0") ?? 0 < Double(model.open_price ?? "0") ?? 0 {
+        if model.cmd == 1 || model.cmd == 3 || model.cmd == 5 {
             xianjiaColor = color(83, 185, 73, 1)
         }
+        self.xianjiaLabel.textColor = xianjiaColor
         
         if model.productBean.digits.length > 0 {
             self.xianjiaLabel.text = precisionString(with: price ?? "0", precision: model.productBean.digits, isRound: true)

+ 3 - 8
Koala/Koala/Modular/Deal/VM/DealViewModel.swift

@@ -1448,17 +1448,12 @@ extension DealViewModel {
                         model.newPrice = "\(currentSocket["ask"] ?? "0")"
                         let np = conerData(model.newPrice, .MyDouble).2! - conerData(model.open, .MyDouble).2!
                         model.increase = "\(np / conerData(model.open, .MyDouble).2! * 100)"
-                        model.bid = "\(currentSocket["bid"] ?? "0")"
-                        model.ask = "\(currentSocket["ask"] ?? "0")"
+                        let bid = "\(currentSocket["bid"] ?? "0")"
+                        let ask = "\(currentSocket["ask"] ?? "0")"
                         
-                        let curPrice = ((Double(model.ask) ?? 0) + (Double(model.bid) ?? 0)) / 2
+                        let curPrice = ((Double(ask) ?? 0) + (Double(bid) ?? 0)) / 2
                         self.price = "\(curPrice)"
                         
-                        if self.productList[symbol] != nil {
-                            self.productList[symbol]!.ask = "\(currentSocket["ask"] ?? "0")"
-                            self.productList[symbol]!.bid = "\(currentSocket["bid"] ?? "0")"
-                        }
-                        
                         self.observeSymbol.send(value: true)
                         
                         guard let _ = currentSocket["time"] as? Int64 else {

+ 18 - 21
Koala/Koala/Modular/JDTrade/VC/JDNewTradeAccountDetailViewController.swift

@@ -246,13 +246,15 @@ class JDNewTradeAccountDetailViewController: BaseViewController {
                 guard let cell = tableView.cellForRow(at: indexPath) as? DealListCell else { continue }
                 guard indexPath.row < (viewModel.positionList.count) else {return}
                 cell.updatePositionCellWith(model: self.viewModel.positionList[indexPath.row])
+                cell.layoutIfNeeded()
             }
         }
-        else if sectionView.segmentedControl.selectedSegmentIndex == 0 {
+        else if sectionView.segmentedControl.selectedSegmentIndex == 1 {
             for indexPath in visibleRows {
                 guard let cell = tableView.cellForRow(at: indexPath) as? DealListCell else { continue }
                 guard indexPath.row < (viewModel.entrustList.count) else {return}
                 cell.updateEntrustCellWith(model: self.viewModel.entrustList[indexPath.row])
+                cell.layoutIfNeeded()
             }
         }
     }
@@ -428,9 +430,7 @@ class JDNewTradeAccountDetailViewController: BaseViewController {
             if !self.isScrolling.value {
                 self.skeletonCount = 0
                 self.tableView.hideSkeleton()
-                print("骨架图:隐藏")
                 self.tableView.reloadData()
-                print("刷新列表")
             }
             /// ===>推广版本修改
             var isCu = self.isCurrencyOptions
@@ -546,7 +546,6 @@ extension JDNewTradeAccountDetailViewController: UITableViewDelegate, SkeletonTa
         let cell: DealListCell = tableView.dequeueReusableCell(withIdentifier: "DealListCell") as! DealListCell
         skeletonCount = 0
         cell.hidenAnimated()
-        print("骨架图:隐藏")
         if self.sectionView.segmentedControl.selectedSegmentIndex == 2 {
             cell.cellType = .Hold // 持仓
             guard indexPath.row < self.viewModel.closeOrderList.count else{
@@ -1177,18 +1176,17 @@ extension JDNewTradeAccountDetailViewController {
                                   guard let self else {return false}
                                   return !self.isScrolling.value
                               })
-                              .startWithValues { [weak self] indexPath in
+                              .startWithValues { [weak self] indexPaths in
                                   guard let self = self,
-                                        self.sectionView.segmentedControl.selectedSegmentIndex == 0,
-                                        indexPath.row < self.viewModel.positionList.count else {return}
-                                  
-                                  guard self.tableView.indexPathsForVisibleRows?.contains(indexPath) == true else {return}
-                                  guard let cell = self.tableView.cellForRow(at: indexPath) as? DealListCell else {return}
-                                  if self.skeletonCount > 0 {
-                                      self.skeletonCount = 0
-                                      self.tableView.hideSkeleton()
-                                  }
-                                  cell.updatePositionCellWith(model: self.viewModel.positionList[indexPath.row])
+                                        self.sectionView.segmentedControl.selectedSegmentIndex == 0 else {return}
+                                 
+//                                  if self.skeletonCount > 0 {
+//                                      self.skeletonCount = 0
+//                                      self.tableView.hideSkeleton()
+//                                  }
+//                                  
+//                                  self.tableView.reloadRows(at: indexPaths, with: .none)
+                                  self.updateVisibleRows()
                               }
         
         
@@ -1199,18 +1197,17 @@ extension JDNewTradeAccountDetailViewController {
                                   guard let self else {return false}
                                   return !self.isScrolling.value
                               })
-                              .startWithValues { [weak self] indexPath in
+                              .startWithValues { [weak self] indexPaths in
                                   guard let self = self,
-                                        self.sectionView.segmentedControl.selectedSegmentIndex == 1,
-                                        indexPath.row < self.viewModel.entrustList.count else {return}
+                                        self.sectionView.segmentedControl.selectedSegmentIndex == 1
+                                        else {return}
                                   
-                                  guard self.tableView.indexPathsForVisibleRows?.contains(indexPath) == true else {return}
-                                  guard let cell = self.tableView.cellForRow(at: indexPath) as? DealListCell else {return}
                                   if self.skeletonCount > 0 {
                                       self.skeletonCount = 0
                                       self.tableView.hideSkeleton()
                                   }
-                                  cell.updateEntrustCellWith(model: self.viewModel.entrustList[indexPath.row])
+                                  
+                                  self.tableView.reloadRows(at: indexPaths, with: .none)
                               }
        
     }

+ 76 - 5
Koala/Koala/Modular/JDTrade/VM/JDNewTradeAccountDetailViewModel.swift

@@ -72,9 +72,9 @@ class JDNewTradeAccountDetailViewModel {
     var lastUpdate: TimeInterval = Date().timeIntervalSince1970
     
     // 持仓列表待更新的列表项
-    let holdUpdatedIndexPath = MutableProperty<IndexPath?>(nil)
+    let holdUpdatedIndexPath = MutableProperty<Array<IndexPath>?>(nil)
     // 挂单列表待更新的列表项
-    let hangUpdatedIndexPath = MutableProperty<IndexPath?>(nil)
+    let hangUpdatedIndexPath = MutableProperty<Array<IndexPath>?>(nil)
     
 
     init(accountModel: JDTradeAccountModel) {
@@ -410,7 +410,14 @@ extension JDNewTradeAccountDetailViewModel {
             guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else {return}
             guard let symbol = currentSocket["symbol"] as? String else {return}
             if type == 0 {
-                updatePrice(symbol: currentSocket)
+                guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else { return }
+                guard let currentType = currentSocket["type"] as? String else { return }
+                
+                if(currentType == "depth"){
+                    updateDepth(symbol: currentSocket)
+                }else if(currentType == "price"){
+                    updatePrice(symbol: currentSocket)
+                }
             }
             else if type == 1 {
                 let isUpdateHold =  positionList.contains {$0.symbol == symbol}
@@ -421,6 +428,50 @@ extension JDNewTradeAccountDetailViewModel {
             }
         }
     }
+    
+    func updateDepth(symbol: NSDictionary){
+        guard let symbol_str = symbol["symbol"] as? String else {
+            return
+        }
+        if symbol_str.count == 0 {
+            return
+        }
+        
+        if let marketDepthModel = MarketDepthModel.deserialize(from: symbol) {
+            
+            guard let model = self.productList[symbol_str] else {
+                return
+            }
+            
+            model.ask = marketDepthModel.asks[0].price
+            model.bid = marketDepthModel.bids[0].price
+            BaseProductList.shareInstance.updateProductInfo(model: model)
+            if self.current_select_index == 0 {
+                let indices = self.positionList.enumerated().compactMap { (index, item) -> Int? in
+                    if(item.symbol == symbol_str){
+                        item.productBean.ask = model.ask
+                        item.productBean.bid = model.bid
+                        item.SymbolModel.ask = model.ask
+                        item.SymbolModel.bid = model.bid
+                        return index
+                    }
+                    return nil
+                }
+                // 将索引集合转换为 IndexPath 集合
+                let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+                
+                self.holdUpdatedIndexPath.value = indexPaths
+            }else if(self.current_select_index == 1){
+                let indices = self.entrustList.enumerated().compactMap { (index, item) -> Int? in
+                    return item.symbol == symbol_str ? index : nil
+                }
+                // 将索引集合转换为 IndexPath 集合
+                let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+                
+                self.hangUpdatedIndexPath.value = indexPaths
+            }
+        }
+    }
 
     func updatePrice(symbol: NSDictionary) {
         guard let symbol_str = symbol["symbol"] as? String else {
@@ -461,11 +512,31 @@ extension JDNewTradeAccountDetailViewModel {
             positionModel.productBean.ask = model.ask
             positionModel.productBean.bid = model.bid
             
-            self.holdUpdatedIndexPath.value = IndexPath.init(row: row, section: 0)
+            let indices = self.positionList.enumerated().compactMap { (index, item) -> Int? in
+                if(item.symbol == symbol_str){
+                    item.productBean.ask = model.ask
+                    item.productBean.bid = model.bid
+                    item.SymbolModel.ask = model.ask
+                    item.SymbolModel.bid = model.bid
+                    return index
+                }
+                return nil
+            }
+            // 将索引集合转换为 IndexPath 集合
+            let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+            
+            self.holdUpdatedIndexPath.value = indexPaths
         }
         else if self.current_select_index == 1 {
             guard let row = self.entrustList.firstIndex(where: {$0.symbol == symbol_str}) else {return}
-            self.hangUpdatedIndexPath.value = IndexPath.init(row: row, section: 0)
+            
+            let indices = self.entrustList.enumerated().compactMap { (index, item) -> Int? in
+                return item.symbol == symbol_str ? index : nil
+            }
+            // 将索引集合转换为 IndexPath 集合
+            let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+            
+            self.hangUpdatedIndexPath.value = indexPaths
         }
         
     }