Răsfoiți Sursa

1.修正 AI 聊天接口的首包处理逻辑
2.给聊天 cell 做 上中下区块分层

100Years 1 lună în urmă
părinte
comite
63c953e279

+ 4 - 4
AIEmoji.xcodeproj/project.pbxproj

@@ -1193,7 +1193,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 2;
+				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;
@@ -1209,7 +1209,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 1.3;
+				MARKETING_VERSION = 1.4;
 				PRODUCT_BUNDLE_IDENTIFIER = com.girl.music.wallpaper;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -1232,7 +1232,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 2;
+				CURRENT_PROJECT_VERSION = 1;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;
@@ -1248,7 +1248,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 1.3;
+				MARKETING_VERSION = 1.4;
 				PRODUCT_BUNDLE_IDENTIFIER = com.girl.music.wallpaper;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";

+ 22 - 0
AIEmoji/Assets.xcassets/AIChat/aichat_refresh.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "aichat_refresh@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "aichat_refresh@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
AIEmoji/Assets.xcassets/AIChat/aichat_refresh.imageset/aichat_refresh@2x.png


BIN
AIEmoji/Assets.xcassets/AIChat/aichat_refresh.imageset/aichat_refresh@3x.png


+ 1 - 2
AIEmoji/Business/AIChat/TSChatViewController/ViewModel/TSAIChatVM.swift

@@ -67,8 +67,7 @@ extension TSAIChatVM {
             if AiMDString.count == 0 {
                 //{"code":500,"message":"Server Error"}
                 //如果错误,基本都是第一条就返回结果了,这里需要做下 code 判断,来确定接口
-                let dataDict = string.jsonDict()
-                if dataDict.safeInt(forKey: "code") != 200 {
+                if let dataDict = string.jsonDict() , let code = dataDict["code"] {
                     completion(nil,NSError(domain: dataDict.safeString(forKey: "message"), code: 0))
                     return
                 }

+ 38 - 3
AIEmoji/Business/AIChat/TSChatViewController/Views/TSMessageContentCell.swift

@@ -25,6 +25,24 @@ class TSMessageContentCell: MessageCollectionViewCell {
     /// The `MessageCellDelegate` for the cell.
     weak var delegate: MessageCellDelegate?
     
+    /// 顶部内容
+    var topContainerView: UIView = {
+        let containerView = UIView()
+        return containerView
+    }()
+    
+    /// 底部内容
+    var centerContainerView: UIView = {
+        let containerView = UIView()
+        return containerView
+    }()
+    
+    /// 底部内容
+    var bottomContainerView: UIView = {
+        let containerView = UIView()
+        return containerView
+    }()
+    
     
     /// 消息内容容器.frame由 子视图自动布局撑起大小
     var messageContainerView: UIView = {
@@ -49,9 +67,26 @@ class TSMessageContentCell: MessageCollectionViewCell {
     
     //初始化 cell
     func setupSubviews() {
-        contentView.addSubview(leadingAvatarImageView)
-        contentView.addSubview(messageContainerView)
-        contentView.addSubview(trailingAvatarImageView)
+        
+        contentView.addSubview(topContainerView)
+        contentView.addSubview(centerContainerView)
+        contentView.addSubview(bottomContainerView)
+        topContainerView.snp.makeConstraints { make in
+            make.leading.top.trailing.equalTo(0)
+        }
+        centerContainerView.snp.makeConstraints { make in
+            make.top.equalTo(topContainerView.snp.bottom)
+            make.leading.trailing.equalTo(0)
+        }
+        
+        bottomContainerView.snp.makeConstraints { make in
+            make.top.equalTo(centerContainerView.snp.bottom)
+            make.leading.trailing.bottom.equalTo(0)
+        }
+        
+        centerContainerView.addSubview(leadingAvatarImageView)
+        centerContainerView.addSubview(messageContainerView)
+        centerContainerView.addSubview(trailingAvatarImageView)
         
         
         let leadingAvatarEdge = TSLayoutSizeCalculator.leadingAvatarEdge

+ 53 - 19
AIEmoji/Business/AIChat/TSChatViewController/Views/TSTextMessageContentCell.swift

@@ -23,6 +23,25 @@ class TSTextMessageContentCell: TSMessageContentCell {
         return activityIndicator
     }()
     
+    
+    
+    lazy var refreshBtn: UIButton = {
+        let refresh = UIButton.createButton(image: UIImage(named: "aichat_refresh")) { [weak self]  in
+            guard let self = self else { return }
+            
+            
+        }
+        return refresh
+    }()
+    
+    lazy var bottomToolView: UIView = {
+        bottomToolView = UIView()
+        bottomToolView.isHidden = true
+        return bottomToolView
+    }()
+    
+    
+    
     override func prepareForReuse() {
         super.prepareForReuse()
     }
@@ -44,6 +63,16 @@ class TSTextMessageContentCell: TSMessageContentCell {
             make.width.height.equalTo(24.0)
         }
         
+        
+        bottomToolView.addSubview(refreshBtn)
+        refreshBtn.snp.makeConstraints { make in
+            make.left.equalTo(12)
+            make.bottom.equalTo(-9)
+            make.width.height.equalTo(20)
+        }
+        
+        
+        
     }
     
     override func configure(
@@ -92,34 +121,39 @@ class TSTextMessageContentCell: TSMessageContentCell {
             messageLabel.text = text
 //            debugPrint("text赋值")
         case .attributedText(let text):
+            messageLabel.text = text.string
             messageLabel.attributedText = text
 //            debugPrint("attributedText赋值")
+            
+//            extractAndPrintSubstring(from: messageLabel.text ?? "", to: text.string)
         default:
             break
         }
     }
     
     
-//    func extractAndPrintSubstring(from sourceString: String, to targetString: String) {
-//        // 查找 sourceString 在 targetString 中的结束位置
-//        if let range = targetString.range(of: sourceString) {
-//            // 获取 sourceString 在 targetString 中的结束位置
-//            let startIdx = range.upperBound
-//            // 提取从该位置到 targetString 结束的子字符串
-//            let extractedSubstring = targetString[startIdx...]
-//            
-//            // 将提取的子字符串逐个字符输出
-//            for character in extractedSubstring {
+    func extractAndPrintSubstring(from sourceString: String, to targetString: String) {
+        // 查找 sourceString 在 targetString 中的结束位置
+        if let range = targetString.range(of: sourceString) {
+            // 获取 sourceString 在 targetString 中的结束位置
+            let startIdx = range.upperBound
+            // 提取从该位置到 targetString 结束的子字符串
+            let extractedSubstring = targetString[startIdx...]
+            
+            // 将提取的子字符串逐个字符输出
+            var string = sourceString
+            for character in extractedSubstring {
 //                print(character)
-//                messageLabel.text = (messageLabel.text ?? "") + String(character)
-//                messageLabel.attributedText = SwiftyMarkdown(string: messageLabel.text ?? "").attributedString()
-//            }
-//        } else {
-//            print("未找到 sourceString")
-//            messageLabel.text = targetString
-//            messageLabel.attributedText = SwiftyMarkdown(string: targetString).attributedString()
-//        }
-//    }
+                string = string + String(character)
+                messageLabel.text = string
+                messageLabel.attributedText = kMDAttributedString(text: string)
+            }
+        } else {
+            print("未找到 sourceString")
+            messageLabel.text = targetString
+            messageLabel.attributedText = kMDAttributedString(text: targetString)
+        }
+    }
     
     func startAnimating() {
         activityIndicator.isHidden = false

+ 3 - 3
AIEmoji/Common/NetworkManager/TSNetWork/TSNetworkManager.swift

@@ -61,15 +61,15 @@ class TSNetworkManager {
             case .stream(let result):
                 switch result {
                 case .success(let string):
-//                    print("Stream Received string: \(string)")
+                    debugPrint("Stream Received string: \(string)")
                     streamHandler(string)
                 case .failure(let error):
-                    print("Stream error: \(error)")
+                    debugPrint("Stream error: \(error)")
                     completion(.failure(error))
                 }
             case .complete(let cpl):
                 if let error = cpl.error {
-                    print("Stream Request failed with error: \(error)")
+                    debugPrint("Stream Request failed with error: \(error)")
                     completion(.failure(error))
                 } else {
                     completion(.success("Stream success"))