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() static let shared = Config()
// HOST // HOST
private let host = "http://jm.rbq.college" private let host = "https://jm.rbq.college"
// //
private init() {} private init() {}

View File

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

View File

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