Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
de123c79
Commit
de123c79
authored
Dec 02, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// AI
parent
829543b1
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
407 additions
and
103 deletions
+407
-103
Podfile
galaxy/Podfile
+1
-1
project.pbxproj
galaxy/galaxy.xcodeproj/project.pbxproj
+12
-0
AppDelegate.swift
galaxy/galaxy/AppDelegate.swift
+8
-42
YHAIChatConfiguration.swift
...odules/AI/AI-Dialogue(AI对话)/C/YHAIChatConfiguration.swift
+3
-2
YHAIMainChatViewController.swift
...s/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
+7
-0
YHAIRequestManager.swift
...s/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
+8
-9
YHAIRobotChatViewController.swift
.../AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
+11
-0
YHAIChatDataBaseManager.swift
...ules/AI/AI-Dialogue(AI对话)/M/YHAIChatDataBaseManager.swift
+100
-0
YHAIChatDataBaseModel.swift
...odules/AI/AI-Dialogue(AI对话)/M/YHAIChatDataBaseModel.swift
+86
-0
YHAIMessageModel.swift
...ses/Modules/AI/AI-Dialogue(AI对话)/M/YHAIMessageModel.swift
+69
-24
YHAIChatInputShadowView.swift
...ules/AI/AI-Dialogue(AI对话)/V/YHAIChatInputShadowView.swift
+42
-0
YHAIChatShadowView.swift
...s/Modules/AI/AI-Dialogue(AI对话)/V/YHAIChatShadowView.swift
+1
-3
YHAITextInputView.swift
...es/Modules/AI/AI-Dialogue(AI对话)/V/YHAITextInputView.swift
+11
-0
YHAITextMessageCell.swift
.../Modules/AI/AI-Dialogue(AI对话)/V/YHAITextMessageCell.swift
+1
-1
YHStartPageViewController.swift
...lasses/Modules/Home(首页)/C/YHStartPageViewController.swift
+3
-21
YhConstant.swift
galaxy/galaxy/Classes/Tools/Helper/YhConstant.swift
+44
-0
No files found.
galaxy/Podfile
View file @
de123c79
...
...
@@ -111,7 +111,7 @@ target 'galaxy' do
pod
'RealmSwift'
,
'20.0.0'
pod
'Realm'
,
'20.0.0'
#调试工具
pod
'LLDebugTool'
,
'1.3.8.1'
,
:configurations
=>
[
'Debug'
]
pod
'LLDebugTool
Swift
'
,
'1.3.8.1'
,
:configurations
=>
[
'Debug'
]
end
...
...
galaxy/galaxy.xcodeproj/project.pbxproj
View file @
de123c79
...
...
@@ -684,6 +684,9 @@
04BE39482CFABB7F00BD31DB
/* YHAIChatBannerCollectionCell.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04BE39472CFABB7F00BD31DB
/* YHAIChatBannerCollectionCell.swift */
;
};
04BE394A2CFABC5E00BD31DB
/* YHAIChatShadowView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04BE39492CFABC5E00BD31DB
/* YHAIChatShadowView.swift */
;
};
04BE394C2CFAC16600BD31DB
/* YHAIChatCustomFlowLayout.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04BE394B2CFAC16600BD31DB
/* YHAIChatCustomFlowLayout.swift */
;
};
04BE394E2CFD92C100BD31DB
/* YHAIChatInputShadowView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04BE394D2CFD92C100BD31DB
/* YHAIChatInputShadowView.swift */
;
};
04BE39502CFD9B5900BD31DB
/* YHAIChatDataBaseManager.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04BE394F2CFD9B5800BD31DB
/* YHAIChatDataBaseManager.swift */
;
};
04BE39522CFDA19000BD31DB
/* YHAIChatDataBaseModel.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04BE39512CFDA19000BD31DB
/* YHAIChatDataBaseModel.swift */
;
};
04C693622B723AB8004C1758
/* YHMySettingViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04C693612B723AB8004C1758
/* YHMySettingViewController.swift */
;
};
04C693642B723B56004C1758
/* YHMySettingCell.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04C693632B723B56004C1758
/* YHMySettingCell.swift */
;
};
04C85DDF2C364FE9008B20D6
/* YHAboutUsCell.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
04C85DDE2C364FE9008B20D6
/* YHAboutUsCell.swift */
;
};
...
...
@@ -1750,6 +1753,9 @@
04BE39472CFABB7F00BD31DB
/* YHAIChatBannerCollectionCell.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHAIChatBannerCollectionCell.swift
;
sourceTree
=
"<group>"
;
};
04BE39492CFABC5E00BD31DB
/* YHAIChatShadowView.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHAIChatShadowView.swift
;
sourceTree
=
"<group>"
;
};
04BE394B2CFAC16600BD31DB
/* YHAIChatCustomFlowLayout.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHAIChatCustomFlowLayout.swift
;
sourceTree
=
"<group>"
;
};
04BE394D2CFD92C100BD31DB
/* YHAIChatInputShadowView.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHAIChatInputShadowView.swift
;
sourceTree
=
"<group>"
;
};
04BE394F2CFD9B5800BD31DB
/* YHAIChatDataBaseManager.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHAIChatDataBaseManager.swift
;
sourceTree
=
"<group>"
;
};
04BE39512CFDA19000BD31DB
/* YHAIChatDataBaseModel.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHAIChatDataBaseModel.swift
;
sourceTree
=
"<group>"
;
};
04C693612B723AB8004C1758
/* YHMySettingViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHMySettingViewController.swift
;
sourceTree
=
"<group>"
;
};
04C693632B723B56004C1758
/* YHMySettingCell.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHMySettingCell.swift
;
sourceTree
=
"<group>"
;
};
04C85DDE2C364FE9008B20D6
/* YHAboutUsCell.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YHAboutUsCell.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -3988,6 +3994,8 @@
045F28492CF6F5B100520F19
/* YHAIViewModel.swift */
,
045F284B2CF6F65200520F19
/* YHAIListModel.swift */
,
04BE39272CF848F300BD31DB
/* YHAIMessageModel.swift */
,
04BE39512CFDA19000BD31DB
/* YHAIChatDataBaseModel.swift */
,
04BE394F2CFD9B5800BD31DB
/* YHAIChatDataBaseManager.swift */
,
);
path
=
M
;
sourceTree
=
"<group>"
;
...
...
@@ -4010,6 +4018,7 @@
04BE39452CFAB5F100BD31DB
/* YHAIChatBannerItemCell.swift */
,
04BE39472CFABB7F00BD31DB
/* YHAIChatBannerCollectionCell.swift */
,
04BE39492CFABC5E00BD31DB
/* YHAIChatShadowView.swift */
,
04BE394D2CFD92C100BD31DB
/* YHAIChatInputShadowView.swift */
,
04BE394B2CFAC16600BD31DB
/* YHAIChatCustomFlowLayout.swift */
,
);
path
=
V
;
...
...
@@ -6103,6 +6112,7 @@
042B20D42CEAE5E900655093
/* YHImproveTargetListCell.swift in Sources */
,
04D144762C0452E200EE3758
/* YHOneKeyLoginManager.swift in Sources */
,
A5551FFE2B4C26CE00510980
/* YHBaseViewModel.swift in Sources */
,
04BE394E2CFD92C100BD31DB
/* YHAIChatInputShadowView.swift in Sources */
,
04B360F72C646B4F001EB053
/* YHPrincipleEnvelopeModel.swift in Sources */
,
048B2A4A2BC7D9DC00A93BF0
/* YHMyLikeViewController.swift in Sources */
,
A567E5AE2BD7643D00D5D5A0
/* YHHomeKingKongBlockItem.swift in Sources */
,
...
...
@@ -6634,6 +6644,7 @@
A598E9E62C7EF39D00F84739
/* YHTravelDocsPreparationDetailVC.swift in Sources */
,
045EEEF82B9F171A0022A143
/* YHFormItemOnlyDoubleChoiceCell.swift in Sources */
,
A598E9DF2C7CB2C400F84739
/* YHTravelDocsPreparationViewModel.swift in Sources */
,
04BE39502CFD9B5900BD31DB
/* YHAIChatDataBaseManager.swift in Sources */
,
04CA2BE82CB769CD00F36DE7
/* YHResignUploadTravelCardListViewController.swift in Sources */
,
0480976D2BA158A1000B9DCA
/* YHCertificateListVC.swift in Sources */
,
04CCEDFF2CA161910026EA70
/* YHHKRecordsFamilyMembers.swift in Sources */
,
...
...
@@ -6654,6 +6665,7 @@
04A271252BAC33BB00652B1B
/* YHFilePreviewTool.swift in Sources */
,
044F39322CB64CC0007CA277
/* YHBottomPresentationController.swift in Sources */
,
045EEEC32B9F171A0022A143
/* YHOtherResidenceFillView.swift in Sources */
,
04BE39522CFDA19000BD31DB
/* YHAIChatDataBaseModel.swift in Sources */
,
045EEE792B9F171A0022A143
/* YHPreviewViewModel.swift in Sources */
,
A54A07C92C7F478200F749AB
/* YHTravelHKDLGuideSheetView.swift in Sources */
,
04174D782BCD5B74000BA46D
/* YHMessageListVC.swift in Sources */
,
...
...
galaxy/galaxy/AppDelegate.swift
View file @
de123c79
...
...
@@ -17,6 +17,8 @@ import SensorsAnalyticsSDK
import
AGConnectCore
import
AGConnectCredential
import
AGConnectAppLinking
import
LLDebugToolSwift
import
LLDebugTool
@main
class
AppDelegate
:
UIResponder
,
UIApplicationDelegate
,
WXApiDelegate
{
...
...
@@ -25,7 +27,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {
Thread
.
sleep
(
forTimeInterval
:
0.5
)
// 应产品同学Nick要求 启动页时间展示长点
#if DEBUG
LLDebugTool
.
shared
()
.
startWorking
()
#else
#endif
setupAudionConfig
()
//初始化 神策sdk
...
...
@@ -206,48 +211,9 @@ extension AppDelegate {
//1.设置HomePageView为主窗口
func
setupRootVCWithTabBar
()
{
let
tabBarController
=
YHTabBarViewController
()
let
homeVC
=
YHHomeHoldViewPageViewController
()
tabBarController
.
delegate
=
homeVC
let
v0
=
YHNavigationController
(
rootVC
:
homeVC
)
let
v1
=
YHNavigationController
(
rootVC
:
YHServiceCenterViewController
())
let
v2
=
YHNavigationController
(
rootVC
:
YHAITabViewController
())
let
v3
=
YHNavigationController
(
rootVC
:
YHCommunityViewController
())
let
v4
=
YHNavigationController
(
rootVC
:
YHMyViewController
())
// 截获AI tabbarItem 点击事件
tabBarController
.
shouldHijackHandler
=
{
[
weak
self
]
tabBarController
,
viewController
,
index
in
guard
let
self
=
self
else
{
return
false
}
if
index
==
2
{
return
true
}
return
false
}
tabBarController
.
didHijackHandler
=
{
[
weak
self
]
tabBarController
,
viewController
,
index
in
guard
let
self
=
self
else
{
return
}
if
index
==
2
{
let
vc
=
YHAITabViewController
()
UIViewController
.
current
?
.
navigationController
?
.
pushViewController
(
vc
)
}
}
v0
.
tabBarItem
=
ESTabBarItem
.
init
(
YHHomeLottieAnimateContentView
(),
title
:
"首页"
,
image
:
UIImage
(
named
:
"home"
),
selectedImage
:
UIImage
(
named
:
"home_1"
))
v1
.
tabBarItem
=
ESTabBarItem
.
init
(
YHServiceLottieAnimateContentView
(),
title
:
"服务"
,
image
:
UIImage
(
named
:
"service"
),
selectedImage
:
UIImage
(
named
:
"service_1"
))
v2
.
tabBarItem
=
ESTabBarItem
.
init
(
YHAITabBarItemContentView
(),
title
:
"AI"
,
image
:
UIImage
(
named
:
"service"
),
selectedImage
:
UIImage
(
named
:
"service_1"
))
v3
.
tabBarItem
=
ESTabBarItem
.
init
(
YHCommunityLottieAnimateContentView
(),
title
:
"朋友"
,
image
:
UIImage
(
named
:
"msg"
),
selectedImage
:
UIImage
(
named
:
"msg_1"
))
v4
.
tabBarItem
=
ESTabBarItem
.
init
(
YHMyLottieAnimateContentView
(),
title
:
"我的"
,
image
:
UIImage
(
named
:
"me"
),
selectedImage
:
UIImage
(
named
:
"me_1"
))
tabBarController
.
viewControllers
=
[
v0
,
v1
,
v2
,
v3
,
v4
]
tabBarController
.
tabBar
.
backgroundColor
=
.
white
window
=
UIWindow
(
frame
:
UIScreen
.
main
.
bounds
)
window
?
.
rootViewController
=
tabBarController
window
?
.
rootViewController
=
configTabBarController
()
window
?
.
makeKeyAndVisible
()
if
YHLoginManager
.
shared
.
needJumpToMsgTabFlag
{
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIChatConfiguration.swift
View file @
de123c79
...
...
@@ -58,13 +58,13 @@ class YHAIChatConfiguration {
}
return
cell
}
else
if
msgType
==
.
card
{
}
else
if
msgType
==
.
card
List
{
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
YHCardMessageCell
.
cellReuseIdentifier
,
for
:
indexPath
)
as!
YHCardMessageCell
return
cell
}
else
{
print
(
"无法识别该消息,请升级APP版本"
)
print
(
"contentType:
\(
msg
.
getType
()
)
"
)
print
(
"contentType:
\(
msg
)
"
)
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
YHAITextMessageCell
.
cellReuseIdentifier
,
for
:
indexPath
)
as!
YHAITextMessageCell
msg
.
body
.
contentType
=
YHMessageType
.
none
.
rawValue
msg
.
body
.
contentText
=
"无法识别该消息,请升级APP版本"
...
...
@@ -95,6 +95,7 @@ class YHAIChatConfiguration {
// 多个文字需要拼接
find
=
true
msg
.
body
.
contentText
+=
res
.
body
.
contentText
msg
.
updateBodyToData
()
}
}
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
View file @
de123c79
...
...
@@ -77,6 +77,8 @@ class YHAIMainChatViewController: YHBaseViewController {
gk_navigationBar
.
isHidden
=
true
view
.
backgroundColor
=
.
clear
IQKeyboardManager
.
shared
.
enable
=
false
let
historyMsgs
=
YHAIChatDataBaseManager
.
shared
.
readHistoryUIMessages
()
messages
.
append
(
contentsOf
:
historyMsgs
)
gk_navTitle
=
"AI对话"
self
.
view
.
addSubview
(
self
.
tableView
)
...
...
@@ -122,7 +124,12 @@ class YHAIMainChatViewController: YHBaseViewController {
guard
let
self
=
self
else
{
return
}
YHAIChatConfiguration
.
defaultConfig
.
handleReceiveMessage
(
res
,
done
,
&
messages
)
if
done
{
print
(
"RESPONSE-DONE"
)
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
let
dbMsgs
=
messages
.
map
{
return
YHAIChatDBMessage
.
createMessage
(
$0
)
}
YHAIChatDataBaseManager
.
shared
.
addDBMessages
(
dbMsgs
)
}
self
.
scrollToBottom
()
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
View file @
de123c79
...
...
@@ -21,7 +21,6 @@ class YHAIRequestManager: NSObject {
let
prefix_data
=
"data:"
let
viewModel
=
YHAIViewModel
()
// 每次回答的唯一标识符
var
uuid
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
var
chatId
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
...
...
@@ -187,12 +186,12 @@ class YHAIRequestManager: NSObject {
}
else
if
line
.
starts
(
with
:
prefix_data
)
{
if
let
dataRange
=
line
.
range
(
of
:
prefix_data
)
{
let
jsonString
=
String
(
line
[
dataRange
.
upperBound
...
])
receiveMessage
.
data
=
jsonString
do
{
if
let
jsonData
=
jsonString
.
data
(
using
:
.
utf8
)
{
let
jsonDict
=
try
JSONSerialization
.
jsonObject
(
with
:
jsonData
,
options
:
[])
as?
[
String
:
Any
]
let
dic
=
(
jsonDict
??
[:])
receiveMessage
.
data
=
dic
receiveMessage
.
data
Dict
=
dic
if
let
body
=
YHAIMessageBody
.
deserialize
(
from
:
dic
)
{
receiveMessage
.
body
=
body
}
...
...
@@ -208,12 +207,7 @@ class YHAIRequestManager: NSObject {
}
}
if
receiveMessage
.
isFinishd
()
{
// 一段话结束需要重新生成uuid 来
uuid
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
}
print
(
"msgType:
\(
receiveMessage
.
getType
()
)
, compltete:
\(
receiveMessage
.
isFinishd
()
)
, uuid:
\(
receiveMessage
.
uuid
)
,
\(
receiveMessage
.
body
.
contentText
)
"
)
print
(
"MESSAGE_RECEIVE:
\n
\(
receiveMessage
)
"
)
let
sessionDone
=
receiveMessage
.
body
.
isDone
()
if
sessionDone
{
...
...
@@ -222,6 +216,11 @@ class YHAIRequestManager: NSObject {
if
!
receiveMessage
.
body
.
isStart
()
{
completion
?(
receiveMessage
,
sessionDone
)
}
if
receiveMessage
.
isFinishd
()
{
// 一段话结束需要重新生成uuid 来
uuid
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
}
}
}
// arr 结束
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
View file @
de123c79
...
...
@@ -81,6 +81,8 @@ class YHAIRobotChatViewController: YHBaseViewController {
IQKeyboardManager
.
shared
.
enable
=
false
view
.
backgroundColor
=
.
clear
view
.
addSubview
(
bgImgView
)
let
historyMsgs
=
YHAIChatDataBaseManager
.
shared
.
readHistoryUIMessages
()
messages
.
append
(
contentsOf
:
historyMsgs
)
gk_navTitle
=
"新港生活规划师"
gk_navTitleColor
=
.
mainTextColor
...
...
@@ -131,7 +133,16 @@ class YHAIRobotChatViewController: YHBaseViewController {
guard
let
self
=
self
else
{
return
}
YHAIChatConfiguration
.
defaultConfig
.
handleReceiveMessage
(
res
,
done
,
&
messages
)
if
done
{
print
(
"RESPONSE-DONE"
)
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
let
dbMsgs
=
messages
.
map
{
return
YHAIChatDBMessage
.
createMessage
(
$0
)
}
messages
.
map
{
print
(
"-----------------7"
)
print
(
"
\(
$0
)
"
)
}
// YHAIChatDataBaseManager.shared.addDBMessages(dbMsgs)
}
self
.
scrollToBottom
()
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/M/YHAIChatDataBaseManager.swift
0 → 100644
View file @
de123c79
//
// YHAIChatDataBaseManager.swift
// galaxy
//
// Created by Dufet on 2024/12/2.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import
UIKit
import
Realm
import
RealmSwift
class
YHAIChatDataBaseManager
{
static
let
shared
=
YHAIChatDataBaseManager
()
let
dbName
=
"AI_CHAT_DB.realm"
// 如果要存储的数据模型属性发生变化,需要配置当前版本号比之前大
let
dbVersion
:
UInt64
=
1
init
()
{
configDataBase
()
}
private
func
configDataBase
()
{
let
docPath
=
NSSearchPathForDirectoriesInDomains
(
FileManager
.
SearchPathDirectory
.
documentDirectory
,
FileManager
.
SearchPathDomainMask
.
userDomainMask
,
true
)[
0
]
as
String
let
dbPath
=
docPath
.
appending
(
"/
\(
dbName
)
"
)
let
config
=
Realm
.
Configuration
(
fileURL
:
URL
.
init
(
string
:
dbPath
),
inMemoryIdentifier
:
nil
,
encryptionKey
:
nil
,
readOnly
:
false
,
schemaVersion
:
dbVersion
,
migrationBlock
:
{
(
migration
,
oldSchemaVersion
)
in
},
deleteRealmIfMigrationNeeded
:
false
,
shouldCompactOnLaunch
:
nil
,
objectTypes
:
nil
)
Realm
.
Configuration
.
defaultConfiguration
=
config
Realm
.
asyncOpen
{
result
in
switch
result
{
case
let
.
success
(
succeed
):
print
(
"Realm 服务器配置成功!"
)
break
case
let
.
failure
(
error
):
print
(
"Realm 数据库配置失败:
\(
error
.
localizedDescription
)
"
)
break
}
}
}
private
func
getDB
()
->
Realm
{
let
docPath
=
NSSearchPathForDirectoriesInDomains
(
FileManager
.
SearchPathDirectory
.
documentDirectory
,
FileManager
.
SearchPathDomainMask
.
userDomainMask
,
true
)[
0
]
as
String
let
dbPath
=
docPath
.
appending
(
"/
\(
dbName
)
"
)
/// 传入路径会自动创建数据库
let
defaultRealm
=
try!
Realm
(
fileURL
:
URL
.
init
(
string
:
dbPath
)
!
)
return
defaultRealm
}
func
addDBMessages
(
_
messages
:
[
YHAIChatDBMessage
])
{
// 获取 Realm 实例
let
defaultRealm
=
self
.
getDB
()
// 开始写入事务
for
message
in
messages
{
let
students
=
getDBMessageBy
(
uuid
:
message
.
uuid
)
try!
defaultRealm
.
write
{
// 将新对象添加到 Realm 数据库
defaultRealm
.
add
(
message
,
update
:
students
.
count
>
0
?
.
modified
:
.
all
)
}
}
}
func
addDBMessage
(
_
message
:
YHAIChatDBMessage
)
->
Void
{
let
defaultRealm
=
self
.
getDB
()
try!
defaultRealm
.
write
{
defaultRealm
.
add
(
message
)
}
print
(
defaultRealm
.
configuration
.
fileURL
??
""
)
}
/// 获取 所保存的消息
func
getDBMessages
()
->
Results
<
YHAIChatDBMessage
>
{
let
defaultRealm
=
self
.
getDB
()
return
defaultRealm
.
objects
(
YHAIChatDBMessage
.
self
)
}
func
getDBMessageBy
(
uuid
:
String
)
->
Results
<
YHAIChatDBMessage
>
{
return
self
.
readDBMessages
(
"uuid = '
\(
uuid
)
'"
)
}
func
readDBMessages
(
_
predicate
:
String
)
->
Results
<
YHAIChatDBMessage
>
{
let
defaultRealm
=
self
.
getDB
()
print
(
defaultRealm
.
configuration
.
fileURL
??
""
)
let
predicate
=
NSPredicate
(
format
:
predicate
)
let
results
=
defaultRealm
.
objects
(
YHAIChatDBMessage
.
self
)
return
results
.
filter
(
predicate
)
}
func
readHistoryUIMessages
()
->
[
YHAIChatMessage
]
{
let
result
=
YHAIChatDataBaseManager
.
shared
.
getDBMessages
()
var
arr
=
[
YHAIChatMessage
]()
for
msg
in
result
{
let
model
=
msg
.
getMessage
()
arr
.
append
(
model
)
}
return
arr
}
}
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/M/YHAIChatDataBaseModel.swift
0 → 100644
View file @
de123c79
//
// YHAIChatDataBaseModel.swift
// galaxy
//
// Created by Dufet on 2024/12/2.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import
UIKit
import
Realm
import
RealmSwift
class
YHAIChatDataBaseModel
:
NSObject
{
}
class
YHAIChatDBMessage
:
Object
{
@objc
var
uuid
:
String
=
""
@objc
dynamic
var
id
:
String
=
""
@objc
dynamic
var
event
:
String
=
""
@objc
dynamic
var
data
:
String
=
""
@objc
dynamic
var
is_self
:
Bool
=
false
@objc
dynamic
var
is_done
:
Bool
=
false
//重写 Object.primaryKey() 可以设置模型的主键。
//声明主键之后,对象将被允许查询,更新速度更加高效,并且要求每个对象保持唯一性。
//一旦带有主键的对象被添加到 Realm 之后,该对象的主键将不可修改。
override
static
func
primaryKey
()
->
String
?
{
return
"uuid"
}
//重写 Object.ignoredProperties() 可以防止 Realm 存储数据模型的某个属性
override
static
func
ignoredProperties
()
->
[
String
]
{
// return ["tempID"]
return
[]
}
//重写 Object.indexedProperties() 方法可以为数据模型中需要添加索引的属性建立索引,Realm 支持为字符串、整型、布尔值以及 Date 属性建立索引。
override
static
func
indexedProperties
()
->
[
String
]
{
// return ["name"]
return
[]
}
static
func
createMessage
(
_
message
:
YHAIChatMessage
)
->
YHAIChatDBMessage
{
let
msg
=
YHAIChatDBMessage
()
msg
.
uuid
=
message
.
uuid
msg
.
id
=
message
.
id
msg
.
event
=
message
.
event
msg
.
data
=
message
.
data
msg
.
is_self
=
message
.
isSelf
msg
.
is_done
=
message
.
isDone
print
(
"DB WRITE--
\(
message
)
"
)
return
msg
}
func
getMessage
()
->
YHAIChatMessage
{
let
msg
=
YHAIChatMessage
()
msg
.
uuid
=
self
.
uuid
msg
.
id
=
self
.
id
msg
.
event
=
self
.
event
msg
.
data
=
self
.
data
msg
.
isSelf
=
self
.
is_self
msg
.
isDone
=
self
.
is_done
print
(
"DB READ--
\(
msg
)
"
)
if
let
jsonData
=
self
.
data
.
data
(
using
:
.
utf8
)
{
do
{
let
jsonDict
=
try
JSONSerialization
.
jsonObject
(
with
:
jsonData
,
options
:
[])
as?
[
String
:
Any
]
let
dic
=
(
jsonDict
??
[:])
msg
.
dataDict
=
dic
if
let
body
=
YHAIMessageBody
.
deserialize
(
from
:
dic
)
{
msg
.
body
=
body
}
}
catch
{
}
}
return
msg
}
}
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/M/YHAIMessageModel.swift
View file @
de123c79
...
...
@@ -15,11 +15,11 @@ class YHAIMessageModel: NSObject {
enum
YHAIMessageType
:
Int
{
case
none
=
0
case
AIT
ext
=
1
// 文字消息
case
fixProductList
=
2
// 固定商品
列表消息
case
productList
=
3
case
card
=
4
case
unknown
=
0
case
t
ext
=
1
// 文字消息
case
cardList
=
2
// 卡片
列表消息
case
productList
=
3
// 商品列表消息
case
fixProductList
=
5
// 文章列表消息
// 自定义case
case
thinking
=
9527
// 思考消息
...
...
@@ -31,7 +31,8 @@ class YHAIChatMessage: CustomStringConvertible {
var
id
:
String
=
""
var
event
:
String
=
""
var
data
:
[
String
:
Any
]
=
[:]
var
data
:
String
=
""
var
dataDict
:
[
String
:
Any
]
=
[:]
var
uuid
:
String
=
""
var
isSelf
:
Bool
=
false
...
...
@@ -56,12 +57,12 @@ class YHAIChatMessage: CustomStringConvertible {
func
isTextMessage
()
->
Bool
{
let
type
=
self
.
getType
()
return
type
==
.
AIT
ext
||
type
==
.
recommendText
return
type
==
.
t
ext
||
type
==
.
recommendText
}
func
isNeedSpiceMessage
()
->
Bool
{
let
type
=
self
.
getType
()
return
type
==
.
AIT
ext
return
type
==
.
t
ext
}
static
func
createQuestionMessage
(
_
text
:
String
)
->
YHAIChatMessage
{
...
...
@@ -90,32 +91,38 @@ class YHAIChatMessage: CustomStringConvertible {
}
func
updateBodyToData
()
{
data
[
"contentType"
]
=
body
.
contentType
data
[
"contentText"
]
=
body
.
contentText
data
Dict
=
body
.
toDictionary
()
??
[:]
data
=
self
.
dicToJSONString
(
dict
:
dataDict
)
}
func
updateDataToBody
()
{
if
let
contentText
=
data
[
"contentText"
]
as?
String
{
body
.
contentText
=
contentText
}
if
let
contentType
=
data
[
"contentType"
]
as?
Int
{
body
.
contentType
=
contentType
}
func
dicToJSONString
(
dict
:
[
String
:
Any
])
->
String
{
if
let
jsonData
=
try
?
JSONSerialization
.
data
(
withJSONObject
:
dict
,
options
:
.
prettyPrinted
)
{
return
String
(
data
:
jsonData
,
encoding
:
.
utf8
)
??
""
}
return
""
}
// 获取消息类型
func
getType
()
->
YHAIMessageType
{
if
let
contentType
=
data
[
"contentType"
]
as?
Int
{
if
let
contentType
=
data
Dict
[
"contentType"
]
as?
Int
{
if
contentType
==
YHAIMessageType
.
thinking
.
rawValue
{
return
.
thinking
}
if
contentType
==
YHAIMessageType
.
AIT
ext
.
rawValue
{
if
let
type
=
data
[
"type"
]
as?
String
{
if
contentType
==
YHAIMessageType
.
t
ext
.
rawValue
{
if
let
type
=
data
Dict
[
"type"
]
as?
String
{
if
type
==
"follow_up"
{
return
.
recommendText
}
}
return
.
AIText
return
.
text
}
if
contentType
==
YHAIMessageType
.
cardList
.
rawValue
{
return
.
cardList
}
if
contentType
==
YHAIMessageType
.
fixProductList
.
rawValue
{
return
.
fixProductList
...
...
@@ -123,15 +130,17 @@ class YHAIChatMessage: CustomStringConvertible {
if
contentType
==
YHAIMessageType
.
productList
.
rawValue
{
return
.
productList
}
}
return
.
none
return
.
unknown
}
// 获取文字消息的文字
func
getText
()
->
String
{
let
msgType
=
getType
()
if
msgType
==
.
AIT
ext
||
msgType
==
.
recommendText
{
if
let
text
=
data
[
"contentText"
]
as?
String
,
!
text
.
isEmpty
{
if
msgType
==
.
t
ext
||
msgType
==
.
recommendText
{
if
let
text
=
data
Dict
[
"contentText"
]
as?
String
,
!
text
.
isEmpty
{
return
text
}
}
...
...
@@ -139,11 +148,11 @@ class YHAIChatMessage: CustomStringConvertible {
}
var
description
:
String
{
return
"uudi:
\(
uuid
)\n
,
id:
\(
id
)\n
, event:
\(
event
)\n
, data:
\(
data
)
)
\n
\n
"
return
"uudi:
\(
uuid
)\n
,
id:
\(
id
)\n
, event:
\(
event
)\n
, data:
\(
data
)\n
dataDict:
\(
dataDict
)\n
dataBody:
\(
body
)\n
\n
"
}
}
class
YHAIMessageBody
:
SmartCodable
{
class
YHAIMessageBody
:
SmartCodable
,
CustomStringConvertible
{
// {"contentType":1, "contentText":"11月爆款楼盘。", "botId":"7441190609433755702", "status":"delta", "type":"answer", "chatId":"7442585762052194356"
var
contentType
:
Int
=
0
...
...
@@ -203,9 +212,30 @@ class YHAIMessageBody: SmartCodable {
return
nil
}
func
getCardList
()
->
YHFixProductListModel
?
{
do
{
if
let
jsonData
=
contentText
.
data
(
using
:
.
utf8
)
{
let
dataDict
=
try
JSONSerialization
.
jsonObject
(
with
:
jsonData
,
options
:
[])
as?
[
String
:
Any
]
let
dict
=
dataDict
??
[:]
if
contentType
==
YHAIMessageType
.
cardList
.
rawValue
{
if
let
productList
=
YHFixProductListModel
.
deserialize
(
from
:
dict
)
{
return
productList
}
}
}
}
catch
{
}
return
nil
}
required
init
()
{
}
var
description
:
String
{
return
"contentType:
\(
contentType
)\n
, contentText:
\(
contentText
)\n
, type:
\(
type
)\n
, status:
\(
status
)
)
\n
"
}
}
class
YHProductListModel
:
SmartCodable
{
...
...
@@ -263,6 +293,21 @@ class YHFixProductListModel: SmartCodable {
}
}
class
YHCardListModel
:
SmartCodable
{
var
icon
:
String
=
""
var
title
:
String
=
""
var
description
:
String
=
""
var
btn_text
:
String
=
""
var
redirect_mode
:
Int
=
0
var
redirect_path
:
String
=
""
var
list
:
[
YHFixProductItemModel
]
=
[]
required
init
()
{
}
}
class
YHFixProductItemModel
:
SmartCodable
{
var
title
:
String
=
""
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAIChatInputShadowView.swift
0 → 100644
View file @
de123c79
//
// YHAIChatInputShadowView.swift
// galaxy
//
// Created by Dufet on 2024/12/2.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import
UIKit
import
UIKit
class
YHAIChatInputShadowView
:
UIView
{
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
setupShadow
()
}
required
init
?(
coder
:
NSCoder
)
{
super
.
init
(
coder
:
coder
)
setupShadow
()
}
private
func
setupShadow
()
{
let
shadowPath
=
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
12
)
layer
.
shadowPath
=
shadowPath
.
cgPath
layer
.
shadowColor
=
UIColor
(
red
:
0
,
green
:
0
,
blue
:
0
,
alpha
:
0.16
)
.
cgColor
layer
.
shadowOpacity
=
1
layer
.
shadowRadius
=
6
layer
.
shadowOffset
=
CGSize
(
width
:
0
,
height
:
0
)
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
// 确保在布局更新时更新阴影路径
setupShadow
()
}
}
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAIChatShadowView.swift
View file @
de123c79
...
...
@@ -23,7 +23,6 @@ class YHAIChatShadowView: UIView {
private
func
setupShadow
()
{
// 创建阴影路径
let
shadowPath
=
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
6
)
// 设置阴影属性
layer
.
shadowPath
=
shadowPath
.
cgPath
layer
.
shadowColor
=
UIColor
(
red
:
0
,
green
:
0
,
blue
:
0
,
alpha
:
0.06
)
.
cgColor
...
...
@@ -35,8 +34,7 @@ class YHAIChatShadowView: UIView {
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
// 确保在布局更新时更新阴影路径
let
shadowPath
=
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
6
)
layer
.
shadowPath
=
shadowPath
.
cgPath
setupShadow
()
}
}
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAITextInputView.swift
View file @
de123c79
...
...
@@ -45,6 +45,7 @@ class YHAITextInputView: UIView {
}
lazy
var
contentView
:
UIView
=
{
let
v
=
UIView
()
v
.
backgroundColor
=
.
white
v
.
layer
.
cornerRadius
=
12.0
v
.
layer
.
borderWidth
=
2.0
v
.
layer
.
borderColor
=
UIColor
.
brandMainColor
.
cgColor
...
...
@@ -81,6 +82,11 @@ class YHAITextInputView: UIView {
return
lottieView
}()
lazy
var
shadowView
:
YHAIChatInputShadowView
=
{
let
v
=
YHAIChatInputShadowView
()
return
v
}()
@objc
func
didSendButtonClicked
()
{
sendBlock
?(
textView
.
text
)
status
=
.
loading
...
...
@@ -136,6 +142,7 @@ class YHAITextInputView: UIView {
func
createUI
()
{
self
.
addSubview
(
whiteView
)
whiteView
.
addSubview
(
shadowView
)
whiteView
.
addSubview
(
contentView
)
contentView
.
addSubview
(
sendBtn
)
contentView
.
addSubview
(
loadingImgView
)
...
...
@@ -153,6 +160,10 @@ class YHAITextInputView: UIView {
make
.
right
.
equalTo
(
-
20
)
}
shadowView
.
snp
.
makeConstraints
{
make
in
make
.
edges
.
equalTo
(
contentView
)
}
sendBtn
.
snp
.
makeConstraints
{
make
in
make
.
width
.
equalTo
(
24
)
make
.
height
.
equalTo
(
24
)
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAITextMessageCell.swift
View file @
de123c79
...
...
@@ -19,7 +19,7 @@ class YHAITextMessageCell: UITableViewCell {
didSet
{
messageLabel
.
text
=
message
.
body
.
contentText
rightAngleView
.
backgroundColor
=
message
.
isSelf
?
.
brandMainColor
:
.
white
rightAngleView
.
isHidden
=
message
.
getType
()
!=
.
AIT
ext
rightAngleView
.
isHidden
=
message
.
getType
()
!=
.
t
ext
if
message
.
isSelf
{
...
...
galaxy/galaxy/Classes/Modules/Home(首页)/C/YHStartPageViewController.swift
View file @
de123c79
...
...
@@ -177,29 +177,11 @@ private extension YHStartPageViewController {
//1.设置主窗口
func
setupRootVC
()
{
gk_navigationBar
.
isHidden
=
false
let
tabBarController
=
YHTabBarViewController
()
// let homeVC = YHHomePageViewController()
let
homeVC
=
YHHomeHoldViewPageViewController
()
tabBarController
.
delegate
=
homeVC
let
v0
=
YHNavigationController
(
rootVC
:
homeVC
)
let
v1
=
YHNavigationController
(
rootVC
:
YHServiceCenterViewController
())
let
v2
=
YHNavigationController
(
rootVC
:
YHCommunityViewController
())
let
v3
=
YHNavigationController
(
rootVC
:
YHMyViewController
())
v0
.
tabBarItem
=
ESTabBarItem
.
init
(
YHHomeLottieAnimateContentView
(),
title
:
"首页"
,
image
:
UIImage
(
named
:
"home"
),
selectedImage
:
UIImage
(
named
:
"home_1"
))
v1
.
tabBarItem
=
ESTabBarItem
.
init
(
YHServiceLottieAnimateContentView
(),
title
:
"服务"
,
image
:
UIImage
(
named
:
"service"
),
selectedImage
:
UIImage
(
named
:
"service_1"
))
v2
.
tabBarItem
=
ESTabBarItem
.
init
(
YHCommunityLottieAnimateContentView
(),
title
:
"朋友"
,
image
:
UIImage
(
named
:
"msg"
),
selectedImage
:
UIImage
(
named
:
"msg_1"
))
v3
.
tabBarItem
=
ESTabBarItem
.
init
(
YHMyLottieAnimateContentView
(),
title
:
"我的"
,
image
:
UIImage
(
named
:
"me"
),
selectedImage
:
UIImage
(
named
:
"me_1"
))
tabBarController
.
viewControllers
=
[
v0
,
v1
,
v2
,
v3
]
tabBarController
.
tabBar
.
backgroundColor
=
.
white
gk_navigationBar
.
isHidden
=
false
let
window
=
UIApplication
.
shared
.
yhKeyWindow
()
window
?
.
rootViewController
=
tabBarController
window
?
.
rootViewController
=
configTabBarController
()
window
?
.
makeKeyAndVisible
()
if
YHLoginManager
.
shared
.
needJumpToMsgTabFlag
{
...
...
galaxy/galaxy/Classes/Tools/Helper/YhConstant.swift
View file @
de123c79
...
...
@@ -7,6 +7,8 @@
//
import
UIKit
import
ESTabBarController_swift
// MARK: - 统一上传图片的最大值
let
picMaxSize
:
Int
=
2
*
1024
*
1024
...
...
@@ -162,6 +164,48 @@ func goToMessagePage() {
NotificationCenter
.
default
.
post
(
name
:
YhConstant
.
YhNotification
.
goMessageVCNotifiction
,
object
:
nil
)
}
func
configTabBarController
()
->
YHTabBarViewController
{
let
tabBarController
=
YHTabBarViewController
()
let
homeVC
=
YHHomeHoldViewPageViewController
()
tabBarController
.
delegate
=
homeVC
let
v0
=
YHNavigationController
(
rootVC
:
homeVC
)
let
v1
=
YHNavigationController
(
rootVC
:
YHServiceCenterViewController
())
let
v2
=
YHNavigationController
(
rootVC
:
YHAITabViewController
())
let
v3
=
YHNavigationController
(
rootVC
:
YHCommunityViewController
())
let
v4
=
YHNavigationController
(
rootVC
:
YHMyViewController
())
// 截获AI tabbarItem 点击事件
tabBarController
.
shouldHijackHandler
=
{
tabBarController
,
viewController
,
index
in
if
index
==
2
{
return
true
}
return
false
}
tabBarController
.
didHijackHandler
=
{
tabBarController
,
viewController
,
index
in
if
index
==
2
{
let
vc
=
YHAITabViewController
()
UIViewController
.
current
?
.
navigationController
?
.
pushViewController
(
vc
)
}
}
v0
.
tabBarItem
=
ESTabBarItem
.
init
(
YHHomeLottieAnimateContentView
(),
title
:
"首页"
,
image
:
UIImage
(
named
:
"home"
),
selectedImage
:
UIImage
(
named
:
"home_1"
))
v1
.
tabBarItem
=
ESTabBarItem
.
init
(
YHServiceLottieAnimateContentView
(),
title
:
"服务"
,
image
:
UIImage
(
named
:
"service"
),
selectedImage
:
UIImage
(
named
:
"service_1"
))
v2
.
tabBarItem
=
ESTabBarItem
.
init
(
YHAITabBarItemContentView
(),
title
:
"AI"
,
image
:
UIImage
(
named
:
"service"
),
selectedImage
:
UIImage
(
named
:
"service_1"
))
v3
.
tabBarItem
=
ESTabBarItem
.
init
(
YHCommunityLottieAnimateContentView
(),
title
:
"朋友"
,
image
:
UIImage
(
named
:
"msg"
),
selectedImage
:
UIImage
(
named
:
"msg_1"
))
v4
.
tabBarItem
=
ESTabBarItem
.
init
(
YHMyLottieAnimateContentView
(),
title
:
"我的"
,
image
:
UIImage
(
named
:
"me"
),
selectedImage
:
UIImage
(
named
:
"me_1"
))
tabBarController
.
viewControllers
=
[
v0
,
v1
,
v2
,
v3
,
v4
]
tabBarController
.
tabBar
.
backgroundColor
=
.
white
return
tabBarController
}
// MARK: - 常量定义
class
YhConstant
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment