2026-05-01 21:27:39 +08:00
|
|
|
import SwiftUI
|
|
|
|
|
import XuqmSDK
|
2026-05-07 19:39:48 +08:00
|
|
|
import XuqmWebViewSDK
|
2026-05-01 21:27:39 +08:00
|
|
|
|
|
|
|
|
@main
|
|
|
|
|
struct XuqmDemoApp: App {
|
|
|
|
|
#if canImport(UIKit)
|
|
|
|
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
var body: some Scene {
|
|
|
|
|
WindowGroup {
|
|
|
|
|
ContentView()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if canImport(UIKit)
|
|
|
|
|
class AppDelegate: NSObject, UIApplicationDelegate {
|
|
|
|
|
func application(
|
|
|
|
|
_ application: UIApplication,
|
|
|
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
|
|
|
|
) -> Bool {
|
|
|
|
|
initializeSDK()
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
|
private func initializeSDK() {
|
|
|
|
|
let config = SDKConfig(
|
|
|
|
|
appKey: "ak_demo_chat",
|
|
|
|
|
debug: true
|
|
|
|
|
)
|
|
|
|
|
XuqmSDK.shared.initialize(config: config)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ContentView: View {
|
|
|
|
|
@StateObject private var authViewModel = AuthViewModel()
|
|
|
|
|
@State private var path = NavigationPath()
|
|
|
|
|
@State private var selectedTab = 0
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
#if !canImport(UIKit)
|
|
|
|
|
initializeSDK()
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
Group {
|
|
|
|
|
if case .success = authViewModel.state {
|
|
|
|
|
MainTabView(authViewModel: authViewModel, path: $path, selectedTab: $selectedTab)
|
|
|
|
|
} else {
|
|
|
|
|
NavigationStack {
|
|
|
|
|
LoginView(viewModel: authViewModel)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct MainTabView: View {
|
|
|
|
|
@ObservedObject var authViewModel: AuthViewModel
|
|
|
|
|
@Binding var path: NavigationPath
|
|
|
|
|
@Binding var selectedTab: Int
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
NavigationStack(path: $path) {
|
|
|
|
|
TabView(selection: $selectedTab) {
|
|
|
|
|
ConversationListView(path: $path)
|
|
|
|
|
.tabItem {
|
|
|
|
|
Image(systemName: "message.fill")
|
|
|
|
|
Text("会话")
|
|
|
|
|
}
|
|
|
|
|
.tag(0)
|
|
|
|
|
|
|
|
|
|
UpdateCheckView()
|
|
|
|
|
.tabItem {
|
|
|
|
|
Image(systemName: "arrow.up.circle.fill")
|
|
|
|
|
Text("更新")
|
|
|
|
|
}
|
|
|
|
|
.tag(1)
|
|
|
|
|
|
2026-05-07 19:39:48 +08:00
|
|
|
WebViewDemoView(path: $path)
|
|
|
|
|
.tabItem {
|
|
|
|
|
Image(systemName: "globe")
|
|
|
|
|
Text("网页")
|
|
|
|
|
}
|
|
|
|
|
.tag(2)
|
|
|
|
|
|
2026-05-01 21:27:39 +08:00
|
|
|
ProfileView(authViewModel: authViewModel)
|
|
|
|
|
.tabItem {
|
|
|
|
|
Image(systemName: "person.fill")
|
|
|
|
|
Text("我的")
|
|
|
|
|
}
|
2026-05-07 19:39:48 +08:00
|
|
|
.tag(3)
|
2026-05-01 21:27:39 +08:00
|
|
|
}
|
|
|
|
|
.navigationDestination(for: AppRoute.self) { route in
|
|
|
|
|
switch route {
|
|
|
|
|
case .chat(let targetId, let targetName):
|
|
|
|
|
ChatView(targetId: targetId, targetName: targetName, currentUserId: authViewModel.currentUserId)
|
2026-05-07 19:39:48 +08:00
|
|
|
case .webView:
|
|
|
|
|
XWebViewPage(
|
|
|
|
|
config: XWebViewConfig(
|
|
|
|
|
url: "https://example.com",
|
|
|
|
|
title: "独立页面"
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-05-01 21:27:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|