Commit 450158aa authored by Steven杜宇's avatar Steven杜宇

// AI

parent 9bae58cc
...@@ -64,11 +64,6 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -64,11 +64,6 @@ class YHAIMainChatViewController: YHBaseViewController {
} }
} }
} }
v.keyBoardChangeBlock = {
[weak self] isKeyBoardShow in
guard let self = self else { return }
self.scrollToBottom()
}
return v return v
}() }()
...@@ -94,7 +89,7 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -94,7 +89,7 @@ class YHAIMainChatViewController: YHBaseViewController {
tableView.snp.makeConstraints { make in tableView.snp.makeConstraints { make in
make.left.right.equalTo(0) make.left.right.equalTo(0)
make.top.equalTo(0) make.top.equalTo(0)
make.bottom.equalTo(bottomInputView.snp.top).offset(-10) make.bottom.equalTo(-64-k_Height_safeAreaInsetsBottom())
} }
bottomInputView.snp.makeConstraints { make in bottomInputView.snp.makeConstraints { make in
...@@ -115,6 +110,11 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -115,6 +110,11 @@ class YHAIMainChatViewController: YHBaseViewController {
autoResponseLocalPictureMessage() autoResponseLocalPictureMessage()
} }
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.bottomInputView.showKeyBoard(false)
}
func scrollToBottom() { func scrollToBottom() {
self.tableView.reloadData { self.tableView.reloadData {
if self.messages.count > 0 { if self.messages.count > 0 {
...@@ -171,12 +171,15 @@ class YHAIMainChatViewController: YHBaseViewController { ...@@ -171,12 +171,15 @@ class YHAIMainChatViewController: YHBaseViewController {
return !uuids.contains($0.messageId) return !uuids.contains($0.messageId)
} }
messages.insert(contentsOf: results, at: 0) messages.insert(contentsOf: results, at: 0)
self.tableView.reloadData() self.tableView.reloadData {
self.scrollToBottom()
}
} }
} }
func autoResponseLocalPictureMessage() { func autoResponseLocalPictureMessage() {
if isNeedAutoResponseImage { if isNeedAutoResponseImage {
isNeedAutoResponseImage = false
let previewUrl = "https://prod-cdn-pub.galaxy-immi.com/5000000/chats/mask_group.png" let previewUrl = "https://prod-cdn-pub.galaxy-immi.com/5000000/chats/mask_group.png"
let msg = self.chatConfig.createRobotResponseLocalPictureMessage("ai_auto_chat_img", previewUrl:previewUrl) let msg = self.chatConfig.createRobotResponseLocalPictureMessage("ai_auto_chat_img", previewUrl:previewUrl)
messages.append(msg) messages.append(msg)
...@@ -292,6 +295,11 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource ...@@ -292,6 +295,11 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
} }
} }
cell.updateSizeBlock = {
[weak self] in
guard let self = self else { return }
self.tableView.reloadData()
}
} }
return cell return cell
......
...@@ -70,11 +70,6 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -70,11 +70,6 @@ class YHAIRobotChatViewController: YHBaseViewController {
} }
} }
} }
v.keyBoardChangeBlock = {
[weak self] isKeyBoardShow in
guard let self = self else { return }
self.scrollToBottom()
}
return v return v
}() }()
...@@ -121,7 +116,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -121,7 +116,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
tableView.snp.makeConstraints { make in tableView.snp.makeConstraints { make in
make.left.right.equalTo(0) make.left.right.equalTo(0)
make.top.equalTo(k_Height_NavigationtBarAndStatuBar) make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalTo(bottomInputView.snp.top).offset(-10) make.bottom.equalTo(-64-k_Height_safeAreaInsetsBottom())
} }
bottomInputView.snp.makeConstraints { make in bottomInputView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview() make.left.right.bottom.equalToSuperview()
...@@ -130,6 +125,11 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -130,6 +125,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
getHistoryMessages(false) getHistoryMessages(false)
} }
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.bottomInputView.showKeyBoard(false)
}
func scrollToBottom() { func scrollToBottom() {
self.tableView.reloadData { self.tableView.reloadData {
if self.messages.count > 0 { if self.messages.count > 0 {
...@@ -140,6 +140,12 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -140,6 +140,12 @@ class YHAIRobotChatViewController: YHBaseViewController {
} }
func sendMessage(_ text: String) { func sendMessage(_ text: String) {
if self.bottomInputView.status == .loading {
YHHUD.flash(message: "AI回复未结束")
return
}
self.chatConfig.removeThinkingMessageFromChatList(&messages) self.chatConfig.removeThinkingMessageFromChatList(&messages)
let question = YHAIChatMessage.createQuestionMessage(text) let question = YHAIChatMessage.createQuestionMessage(text)
messages.append(question) messages.append(question)
...@@ -186,9 +192,7 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -186,9 +192,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
return !uuids.contains($0.messageId) return !uuids.contains($0.messageId)
} }
messages.insert(contentsOf: results, at: 0) messages.insert(contentsOf: results, at: 0)
self.tableView.reloadData { self.tableView.reloadData()
self.scrollToBottom()
}
autoResponseLocalTextMessage() autoResponseLocalTextMessage()
} }
...@@ -200,11 +204,12 @@ class YHAIRobotChatViewController: YHBaseViewController { ...@@ -200,11 +204,12 @@ class YHAIRobotChatViewController: YHBaseViewController {
let text = "银河集团能够为您提供全方位、一站式的香港身份规划及本地生活服务。\n在身份规划方面,我们专注于香港优才、专才、留学等身份产品服务,根据您的个人情况和需求,量身定制最合适的身份规划方案,助您轻松获取香港身份,享受香港的各项福利和优势。\n同时,我们还提供丰富的香港本地生活服务,包括教育咨询、商务支持、个人账户开设、港宝(即香港宝宝)相关服务、保险规划以及房产购置等。我们的专业团队对香港市场有着深入的了解,能够为您提供精准、高效的服务,让您在香港的生活更加便捷、舒适。\n银河集团凭借多年的行业经验和丰富的成功案例,以及专业、敬业的团队,致力于为客户提供最优质、最贴心的服务。选择银河集团,您将享受到专业、高效、便捷的服务体验,让我们携手共创美好未来。" let text = "银河集团能够为您提供全方位、一站式的香港身份规划及本地生活服务。\n在身份规划方面,我们专注于香港优才、专才、留学等身份产品服务,根据您的个人情况和需求,量身定制最合适的身份规划方案,助您轻松获取香港身份,享受香港的各项福利和优势。\n同时,我们还提供丰富的香港本地生活服务,包括教育咨询、商务支持、个人账户开设、港宝(即香港宝宝)相关服务、保险规划以及房产购置等。我们的专业团队对香港市场有着深入的了解,能够为您提供精准、高效的服务,让您在香港的生活更加便捷、舒适。\n银河集团凭借多年的行业经验和丰富的成功案例,以及专业、敬业的团队,致力于为客户提供最优质、最贴心的服务。选择银河集团,您将享受到专业、高效、便捷的服务体验,让我们携手共创美好未来。"
let msg = self.chatConfig.createRobotResponseTextMessage(text) let msg = self.chatConfig.createRobotResponseTextMessage(text)
messages.append(msg) messages.append(msg)
self.tableView.reloadData {
self.scrollToBottom()
}
} }
} }
self.tableView.reloadData {
self.scrollToBottom()
}
} }
func uploadEvaluationMessage(_ msg: YHAIChatMessage, callback:((Bool)->())? = nil) { func uploadEvaluationMessage(_ msg: YHAIChatMessage, callback:((Bool)->())? = nil) {
...@@ -348,6 +353,11 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc ...@@ -348,6 +353,11 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
} }
} }
cell.updateSizeBlock = {
[weak self] in
guard let self = self else { return }
self.tableView.reloadData()
}
} }
return cell return cell
......
...@@ -11,6 +11,7 @@ import JXSegmentedView ...@@ -11,6 +11,7 @@ import JXSegmentedView
import IQKeyboardManagerSwift import IQKeyboardManagerSwift
let isNeedShowAutoPictureMsg = "isNeedShowAutoPictureMsg" let isNeedShowAutoPictureMsg = "isNeedShowAutoPictureMsg"
let isNeedShowAIChatKeyBoard = "isNeedShowAIChatKeyBoard"
class YHAIServiceListViewController: YHBaseViewController { class YHAIServiceListViewController: YHBaseViewController {
...@@ -81,7 +82,8 @@ class YHAIServiceListViewController: YHBaseViewController { ...@@ -81,7 +82,8 @@ class YHAIServiceListViewController: YHBaseViewController {
}() }()
@objc func didInputButtonClicked() { @objc func didInputButtonClicked() {
let dict:[String : Any] = [isNeedShowAutoPictureMsg : false] let dict:[String : Any] = [isNeedShowAutoPictureMsg : false,
isNeedShowAIChatKeyBoard : true]
NotificationCenter.default.post(name: YhConstant.YhNotification.didSwitchToAIChatNotification, object: dict) NotificationCenter.default.post(name: YhConstant.YhNotification.didSwitchToAIChatNotification, object: dict)
} }
...@@ -168,7 +170,7 @@ extension YHAIServiceListViewController: UICollectionViewDelegate, UICollectionV ...@@ -168,7 +170,7 @@ extension YHAIServiceListViewController: UICollectionViewDelegate, UICollectionV
} else if model.redirectPath == YHAIJumpPageType.appServiceTab.rawValue { } else if model.redirectPath == YHAIJumpPageType.appServiceTab.rawValue {
// 服务页 // 服务页
UIViewController.current?.navigationController?.popToRootViewController(animated: true) UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .service) goTabBarBy(tabType: .service)
} }
...@@ -176,7 +178,8 @@ extension YHAIServiceListViewController: UICollectionViewDelegate, UICollectionV ...@@ -176,7 +178,8 @@ extension YHAIServiceListViewController: UICollectionViewDelegate, UICollectionV
if model.businessType == YHAIRobotType.main.rawValue { if model.businessType == YHAIRobotType.main.rawValue {
// 切到主Robot // 切到主Robot
let dict:[String : Any] = [isNeedShowAutoPictureMsg : true] let dict:[String : Any] = [isNeedShowAutoPictureMsg : true,
isNeedShowAIChatKeyBoard : false]
NotificationCenter.default.post(name: YhConstant.YhNotification.didSwitchToAIChatNotification, object: dict) NotificationCenter.default.post(name: YhConstant.YhNotification.didSwitchToAIChatNotification, object: dict)
} else { } else {
......
...@@ -89,11 +89,13 @@ class YHAITabViewController: YHBaseViewController { ...@@ -89,11 +89,13 @@ class YHAITabViewController: YHBaseViewController {
@objc func didBackBtnClicked() { @objc func didBackBtnClicked() {
mainChatVC.bottomInputView.showKeyBoard(false)
if segmentedView.selectedIndex == 1 { // AI 对话 if segmentedView.selectedIndex == 1 { // AI 对话
// tab切换到港小宝 // tab切换到港小宝
self.segmentedView.selectItemAt(index: 0) self.segmentedView.selectItemAt(index: 0)
return return
} }
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} }
...@@ -211,15 +213,20 @@ class YHAITabViewController: YHBaseViewController { ...@@ -211,15 +213,20 @@ class YHAITabViewController: YHBaseViewController {
@objc func didJumoToAIChat(_ notify: Notification) { @objc func didJumoToAIChat(_ notify: Notification) {
var showImg = false var showImg = false
var showKeyBoard = false
if let dict = notify.object as? [String : Any] { if let dict = notify.object as? [String : Any] {
if let isShowImg = dict[isNeedShowAutoPictureMsg] as? Bool { if let isShowImg = dict[isNeedShowAutoPictureMsg] as? Bool {
showImg = isShowImg showImg = isShowImg
} }
if let isShowKeyBoard = dict[isNeedShowAIChatKeyBoard] as? Bool {
showKeyBoard = isShowKeyBoard
}
} }
printLog("SHOW_IMG: \(showImg)") printLog("SHOW_IMG: \(showImg)")
mainChatVC.isNeedAutoResponseImage = showImg mainChatVC.isNeedAutoResponseImage = showImg
jumpToItemIndex(itemIndex: 1) jumpToItemIndex(itemIndex: 1)
mainChatVC.bottomInputView.showKeyBoard() mainChatVC.bottomInputView.showKeyBoard(showKeyBoard)
} }
......
...@@ -12,12 +12,33 @@ class YHAICardItemView: UIView { ...@@ -12,12 +12,33 @@ class YHAICardItemView: UIView {
var cardModel = YHAIListItemModel() { var cardModel = YHAIListItemModel() {
didSet { didSet {
cardImgView.sd_setImage(with: URL(string: cardModel.cover), placeholderImage: UIImage(named: "global_default_image"))
cardTitleLabel.text = cardModel.title cardTitleLabel.text = cardModel.title
describeLabel.text = cardModel.description describeLabel.text = cardModel.description
cardImgView.sd_setImage(with: URL(string: cardModel.cover), placeholderImage: UIImage(named: "global_default_image")) {
[weak self] img, error, cacheType, url in
guard let self = self else { return }
let size = img?.size ?? CGSize(width: 100, height: 50)
var ratio = 0.5
if size.width != 0.0, size.height != 0.0 {
ratio = size.height/size.width
}
printLog("RATIO: \(ratio)")
self.cardImgView.snp.remakeConstraints { make in
make.left.equalTo(16)
make.right.equalTo(-16)
make.top.equalTo(self.lineView.snp.bottom).offset(16)
make.height.equalTo(self.cardImgView.snp.width).multipliedBy(ratio)
make.bottom.equalTo(self.cardTitleLabel.snp.top).offset(-10)
}
self.setNeedsLayout()
self.layoutIfNeeded()
self.updateSizeBlock?(size)
}
} }
} }
var updateSizeBlock:((CGSize)->())?
lazy var lineView: UIView = { lazy var lineView: UIView = {
let v = UIView() let v = UIView()
v.backgroundColor = .init(hex: 0xE9ECF0) v.backgroundColor = .init(hex: 0xE9ECF0)
...@@ -79,11 +100,11 @@ class YHAICardItemView: UIView { ...@@ -79,11 +100,11 @@ class YHAICardItemView: UIView {
make.left.equalTo(16) make.left.equalTo(16)
make.right.equalTo(-16) make.right.equalTo(-16)
make.top.equalTo(lineView.snp.bottom).offset(16) make.top.equalTo(lineView.snp.bottom).offset(16)
make.height.equalTo(303) make.height.equalTo(cardImgView.snp.width).multipliedBy(0.5)
make.bottom.equalTo(cardTitleLabel.snp.top).offset(-10)
} }
cardTitleLabel.snp.makeConstraints { make in cardTitleLabel.snp.makeConstraints { make in
make.top.equalTo(cardImgView.snp.bottom).offset(10)
make.left.equalTo(16) make.left.equalTo(16)
make.right.equalTo(-16) make.right.equalTo(-16)
} }
......
...@@ -134,12 +134,18 @@ class YHAITextInputView: UIView { ...@@ -134,12 +134,18 @@ class YHAITextInputView: UIView {
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
} }
func showKeyBoard() { func showKeyBoard(_ isShow: Bool) {
self.textView.becomeFirstResponder() if isShow {
self.textView.becomeFirstResponder()
} else {
self.textView.resignFirstResponder()
self.textView.endEditing(true)
}
} }
func createUI() { func createUI() {
self.backgroundColor = UIColor.init(hex: 0xF8FCFF)
self.addSubview(whiteView) self.addSubview(whiteView)
whiteView.addSubview(shadowView) whiteView.addSubview(shadowView)
whiteView.addSubview(contentView) whiteView.addSubview(contentView)
......
...@@ -111,7 +111,8 @@ class YHAITextMessageCell: UITableViewCell { ...@@ -111,7 +111,8 @@ class YHAITextMessageCell: UITableViewCell {
let tap = UITapGestureRecognizer(target: self, action: #selector(didMessageClicked)) let tap = UITapGestureRecognizer(target: self, action: #selector(didMessageClicked))
v.addGestureRecognizer(tap) v.addGestureRecognizer(tap)
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(didCopyTextButtonClicked)) let longPress = UILongPressGestureRecognizer(target: self, action: #selector(didCopyTextLongGesture(_:)))
longPress.minimumPressDuration = 2.0
v.addGestureRecognizer(longPress) v.addGestureRecognizer(longPress)
return v return v
}() }()
...@@ -186,11 +187,18 @@ class YHAITextMessageCell: UITableViewCell { ...@@ -186,11 +187,18 @@ class YHAITextMessageCell: UITableViewCell {
@objc func didCopyTextButtonClicked() { @objc func didCopyTextButtonClicked() {
let text = message.body.contentText let text = message.body.contentText
let pasteBoard = UIPasteboard.general UIPasteboard.general.string = text
pasteBoard.string = text
YHHUD.flash(message: "复制成功") YHHUD.flash(message: "复制成功")
} }
@objc func didCopyTextLongGesture(_ sender: UIGestureRecognizer) {
let text = message.body.contentText
if sender.state == .began && UIPasteboard.general.string != text {
UIPasteboard.general.string = text
YHHUD.flash(message: "复制成功")
}
}
lazy var shadowView: YHAIChatShadowView = { lazy var shadowView: YHAIChatShadowView = {
let v = YHAIChatShadowView() let v = YHAIChatShadowView()
return v return v
......
...@@ -51,7 +51,7 @@ class YHAIJumpPageTool { ...@@ -51,7 +51,7 @@ class YHAIJumpPageTool {
} else if path == YHAIJumpPageType.appServiceTab.rawValue { } else if path == YHAIJumpPageType.appServiceTab.rawValue {
// 服务页 // 服务页
UIViewController.current?.navigationController?.popToRootViewController(animated: true) UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .service) goTabBarBy(tabType: .service)
} }
...@@ -65,6 +65,8 @@ class YHCardMessageCell: UITableViewCell { ...@@ -65,6 +65,8 @@ class YHCardMessageCell: UITableViewCell {
static let cellReuseIdentifier = "YHCardMessageCell" static let cellReuseIdentifier = "YHCardMessageCell"
var updateSizeBlock:(()->())?
var evaluationResultCallback: ((Dictionary<String, Any>)->()) = { dic in } var evaluationResultCallback: ((Dictionary<String, Any>)->()) = { dic in }
var cardListModel = YHAIListInfoModel() { var cardListModel = YHAIListInfoModel() {
...@@ -78,6 +80,11 @@ class YHCardMessageCell: UITableViewCell { ...@@ -78,6 +80,11 @@ class YHCardMessageCell: UITableViewCell {
var lastItemView:YHAICardItemView? = nil var lastItemView:YHAICardItemView? = nil
for (index, item) in cardListModel.list.enumerated() { for (index, item) in cardListModel.list.enumerated() {
let productView = YHAICardItemView() let productView = YHAICardItemView()
productView.updateSizeBlock = {
[weak self] size in
guard let self = self else { return }
self.updateSizeBlock?()
}
productView.cardModel = item productView.cardModel = item
listView.addSubview(productView) listView.addSubview(productView)
productView.snp.makeConstraints { make in productView.snp.makeConstraints { make in
......
...@@ -188,7 +188,7 @@ class YHServerCenterHoldViewController: UIViewController { ...@@ -188,7 +188,7 @@ class YHServerCenterHoldViewController: UIViewController {
} }
self.segmentedView.selectItemAt(index: targetTabIndex) self.segmentedView.selectItemAt(index: targetTabIndex)
self.segmentedView.listContainer?.didClickSelectedItem(at: targetTabIndex) self.segmentedView.listContainer?.didClickSelectedItem(at: targetTabIndex)
UIViewController.current?.navigationController?.popToRootViewController(animated: true) UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .service) goTabBarBy(tabType: .service)
} }
} }
......
...@@ -185,7 +185,7 @@ class YHImproveSchemeViewController: YHBaseViewController { ...@@ -185,7 +185,7 @@ class YHImproveSchemeViewController: YHBaseViewController {
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} else { // 进入服务tab页 } else { // 进入服务tab页
self.navigationController?.popToRootViewController(animated: true) self.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .service) goTabBarBy(tabType: .service)
} }
} }
......
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