feat: 优化跨页选择和批量操作,默认每页10条,全选作用于全部匹配结果
CI / lint-and-build (push) Has been cancelled

This commit is contained in:
2026-06-30 11:47:24 +06:00
parent ba54db52e5
commit 2a53f6a862
@@ -12,11 +12,15 @@ struct VideoListView: View {
@State private var showDownloadPanel = false @State private var showDownloadPanel = false
@State private var downloadResults: [(video: VideoItem, playInfos: [PlayInfo])] = [] @State private var downloadResults: [(video: VideoItem, playInfos: [PlayInfo])] = []
private let pageSizes = [20, 50, 100] private let pageSizes = [10, 20, 50, 100]
@State private var pageSizeIndex = 0 @State private var pageSizeIndex = 0
private var pageSize: Int { pageSizes[pageSizeIndex] } private var pageSize: Int { pageSizes[pageSizeIndex] }
@State private var pageNo = 1 @State private var pageNo = 1
private var totalPages: Int { max(1, (filteredVideos.count + pageSize - 1) / pageSize) } private var totalPages: Int { max(1, (filteredVideos.count + pageSize - 1) / pageSize) }
private var currentPageSelectedCount: Int {
let currentPageIds = Set(displayVideos.map(\.videoId))
return selectedVideos.intersection(currentPageIds).count
}
var body: some View { var body: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
@@ -54,10 +58,10 @@ struct VideoListView: View {
.disabled(selectedVideos.isEmpty || isLoading) .disabled(selectedVideos.isEmpty || isLoading)
Button("全选") { Button("全选") {
if selectedVideos.count == displayVideos.count { if selectedVideos.count == filteredVideos.count {
selectedVideos.removeAll() selectedVideos.removeAll()
} else { } else {
selectedVideos = Set(displayVideos.map(\.videoId)) selectedVideos = Set(filteredVideos.map(\.videoId))
} }
} }
@@ -165,6 +169,15 @@ struct VideoListView: View {
HStack { HStack {
Text("\(filteredVideos.count) 条,已选 \(selectedVideos.count)") Text("\(filteredVideos.count) 条,已选 \(selectedVideos.count)")
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
if !selectedVideos.isEmpty {
Button("取消选择") {
selectedVideos.removeAll()
}
.buttonStyle(.borderless)
.foregroundStyle(.secondary)
}
Spacer() Spacer()
Picker("每页", selection: $pageSizeIndex) { Picker("每页", selection: $pageSizeIndex) {
@@ -277,7 +290,7 @@ struct VideoListView: View {
loadingStatus = "" loadingStatus = ""
var results: [(video: VideoItem, playInfos: [PlayInfo])] = [] var results: [(video: VideoItem, playInfos: [PlayInfo])] = []
var errors: [String] = [] var errors: [String] = []
let selected = displayVideos.filter { selectedVideos.contains($0.videoId) } let selected = filteredVideos.filter { selectedVideos.contains($0.videoId) }
for (index, video) in selected.enumerated() { for (index, video) in selected.enumerated() {
loadingStatus = "正在获取下载地址 (\(index + 1)/\(selected.count))「\(video.title)」..." loadingStatus = "正在获取下载地址 (\(index + 1)/\(selected.count))「\(video.title)」..."
let playInfos = await fetchPlayInfoWithRetry(videoId: video.videoId, title: video.title, maxRetries: 3) let playInfos = await fetchPlayInfoWithRetry(videoId: video.videoId, title: video.title, maxRetries: 3)