This commit is contained in:
2025-08-18 23:59:43 +08:00
parent d80289fe73
commit 77d2a93fe0
3 changed files with 24 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ final class Config {
static let shared = Config()
// HOST
private let host = "http://jm.rbq.college"
private let host = "https://jm.rbq.college"
//
private init() {}

View File

@@ -110,7 +110,7 @@ struct PhotoView: View {
if totalImages > 0, currentImageIndex > 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
withAnimation {
proxy.scrollTo(currentImageIndex, anchor: .top)
proxy.scrollTo(savedIndex, anchor: .top)
}
}
}

View File

@@ -36,7 +36,7 @@ class SearchHistoryManager {
}
}
//
// ID
struct SearchView: View {
@State private var searchQuery: String = ""
@State private var searchResults: [AlbumItem] = []
@@ -44,13 +44,16 @@ struct SearchView: View {
@State private var showAlert: Bool = false
@State private var alertMessage: String = ""
@State private var searchHistory: [String] = []
//
@State private var navigationPath = NavigationPath()
var body: some View {
NavigationStack {
// 使NavigationStack
NavigationStack(path: $navigationPath) {
Form {
Section(header: Text("Jetson Media")) {
HStack {
TextField("输入搜索内容", text: $searchQuery)
TextField("输入搜索内容或ID", text: $searchQuery)
.textFieldStyle(RoundedBorderTextFieldStyle())
.onChange(of: searchQuery) {
if $0.isEmpty {
@@ -69,7 +72,7 @@ struct SearchView: View {
}
}
//
//
if searchQuery.isEmpty && !searchHistory.isEmpty {
Section(header: HStack {
Text("搜索历史")
@@ -82,19 +85,15 @@ struct SearchView: View {
.font(.subheadline)
}) {
ForEach(searchHistory, id: \.self) { query in
// HStack
HStack {
//
Text(query)
.foregroundColor(.primary)
.frame(maxWidth: .infinity, alignment: .leading)
.onTapGesture {
//
searchQuery = query
performSearch()
}
//
Button(action: {
SearchHistoryManager.shared.removeHistory(query)
loadHistory()
@@ -102,7 +101,7 @@ struct SearchView: View {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.gray)
}
.buttonStyle(PlainButtonStyle()) //
.buttonStyle(PlainButtonStyle())
}
}
}
@@ -129,6 +128,10 @@ struct SearchView: View {
.onAppear {
loadHistory()
}
//
.navigationDestination(for: Int.self) { albumId in
PhotoView(albumId: String(albumId))
}
}
.alert(isPresented: $showAlert) {
Alert(title: Text("提示"), message: Text(alertMessage), dismissButton: .default(Text("确定")))
@@ -142,6 +145,16 @@ struct SearchView: View {
private func performSearch() {
guard !searchQuery.isEmpty else { return }
//
if let albumId = Int(searchQuery) {
// ID
SearchHistoryManager.shared.addHistory(searchQuery)
loadHistory()
navigationPath.append(albumId)
return
}
//
SearchHistoryManager.shared.addHistory(searchQuery)
loadHistory()