|
@@ -10,6 +10,13 @@ import UIKit
|
|
|
class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
|
|
|
|
|
|
var sendComplete:(([Any])->Void)?
|
|
|
+ //AI是否正在回答问题
|
|
|
+ var isAIAnswering:Bool = false{
|
|
|
+ didSet{
|
|
|
+ sendEnabled(enabled: !isAIAnswering)
|
|
|
+// chatInputFullScreenVC?.isAIAnswering = isAIAnswering
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
lazy var InputBarView:UIView = {
|
|
|
let InputBarView = UIView()
|
|
@@ -31,9 +38,13 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
|
|
|
let magnifyBtn = UIButton.createButton(image: UIImage(named: "chat_send_magnify")) { [weak self] in
|
|
|
guard let self = self else { return }
|
|
|
let vc = TSChatInputFullScreenVC()
|
|
|
+
|
|
|
+// chatInputFullScreenVC = vc
|
|
|
+
|
|
|
vc.text = textView.text
|
|
|
vc.sendComplete = { [weak self] date in
|
|
|
guard let self = self else { return }
|
|
|
+// chatInputFullScreenVC = nil
|
|
|
if let text = date.first as? String {
|
|
|
textView.text = text
|
|
|
textView.resignFirstResponder()
|
|
@@ -45,6 +56,7 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
|
|
|
|
|
|
vc.closeComplete = { [weak self] text in
|
|
|
guard let self = self else { return }
|
|
|
+// chatInputFullScreenVC = nil
|
|
|
textView.text = text
|
|
|
textView.resignFirstResponder()
|
|
|
textDidChange()
|
|
@@ -52,11 +64,15 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
|
|
|
}
|
|
|
|
|
|
kPresentModalVC(target: self, modelVC: vc)
|
|
|
+
|
|
|
}
|
|
|
magnifyBtn.isHidden = true
|
|
|
return magnifyBtn
|
|
|
}()
|
|
|
|
|
|
+
|
|
|
+// var chatInputFullScreenVC: TSChatInputFullScreenVC?
|
|
|
+
|
|
|
private let minHeight: CGFloat = 56//24
|
|
|
private let maxHeight: CGFloat = 154
|
|
|
lazy var textView: TSCustomTextView = {
|
|
@@ -122,12 +138,19 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
|
|
|
override func dealThings() {
|
|
|
// 监听文本变化事件
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(textDidChange), name: UITextView.textDidChangeNotification, object: textView)
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(handleAIAnsweringNotification(_:)), name: .kAIAnsweringNotification, object: nil)
|
|
|
}
|
|
|
|
|
|
func sendMsg(){
|
|
|
- if textView.text.replacingOccurrences(of: " ", with: "").count <= 0 {
|
|
|
+
|
|
|
+ if sendBtn.isEnabled == false {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// if textView.text.replacingOccurrences(of: " ", with: "").count <= 0 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+
|
|
|
if let string = textView.text {
|
|
|
sendComplete?([string])
|
|
|
textView.resignFirstResponder()
|
|
@@ -135,7 +158,9 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
|
|
|
}
|
|
|
|
|
|
func sendEnabled(enabled:Bool){
|
|
|
- if enabled == true ,textView.text.replacingOccurrences(of: " ", with: "").count > 0 {
|
|
|
+ if enabled == true,
|
|
|
+ isAIAnswering == false,
|
|
|
+ textView.text.replacingOccurrences(of: " ", with: "").count > 0 {
|
|
|
sendBtn.isEnabled = true
|
|
|
}else{
|
|
|
sendBtn.isEnabled = false
|
|
@@ -149,6 +174,14 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
|
|
|
magnifyBtn.isHidden = true
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @objc func handleAIAnsweringNotification(_ notification: Notification) {
|
|
|
+ if let userInfo = notification.userInfo, let boolValue = userInfo[kIsAIAnswering] as? Bool {
|
|
|
+ isAIAnswering = boolValue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
deinit {
|
|
|
// 移除通知监听
|
|
|
NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: textView)
|