u1
This commit is contained in:
@@ -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() {}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user