@@ -110,6 +110,9 @@ struct EditInfoView: View {
110
110
}
111
111
112
112
// MARK: Image
113
+ @State private var largeImageUrlStr = " "
114
+ @State private var largeNSImage : NSImage ? = nil
115
+
113
116
@MainActor
114
117
@ViewBuilder
115
118
func imagePickAndShowView( ) -> some View {
@@ -129,84 +132,119 @@ struct EditInfoView: View {
129
132
}
130
133
}
131
134
}
132
- ScrollView {
133
- if let infoImgs = info. imgs {
134
- if infoImgs. count > 0 {
135
- LazyVGrid ( columns: [ GridItem ( . adaptive( minimum: 150 ) , spacing: 10 ) ] ) {
136
- ForEach ( Array ( infoImgs. enumerated ( ) ) , id: \. 0 ) { i, img in
137
- VStack {
138
- if let data = img. imgData {
139
- if let nsImg = NSImage ( data: data) {
140
- Image ( nsImage: nsImg)
141
- . resizable ( )
142
- . scaledToFit ( )
143
- . cornerRadius ( 5 )
144
- . contextMenu {
145
- Button {
146
- IOInfo . updateCoverImage ( info: info, img: img)
147
- } label: {
148
- Label ( " 设为封面图 " , image: " doc.text.image " )
149
- }
150
- Button {
151
- info. imgs? . remove ( at: i)
152
- IOImg . delete ( img)
153
- } label: {
154
- Label ( " 删除 " , image: " circle " )
155
- }
135
+ ZStack {
136
+ ScrollView {
137
+ if let infoImgs = info. imgs {
138
+ if infoImgs. count > 0 {
139
+ LazyVGrid ( columns: [ GridItem ( . adaptive( minimum: 150 ) , spacing: 10 ) ] ) {
140
+ ForEach ( Array ( infoImgs. enumerated ( ) ) , id: \. 0 ) { i, img in
141
+ VStack {
142
+ if let data = img. imgData {
143
+ if let nsImg = NSImage ( data: data) {
144
+ Image ( nsImage: nsImg)
145
+ . resizable ( )
146
+ . scaledToFit ( )
147
+ . cornerRadius ( 5 )
148
+ . onTapGesture ( perform: {
149
+ largeNSImage = nsImg
150
+ } )
151
+ . contextMenu {
152
+ Button {
153
+ IOInfo . updateCoverImage ( info: info, img: img)
154
+ } label: {
155
+ Label ( " 设为封面图 " , image: " doc.text.image " )
156
+ }
157
+ Button {
158
+ info. imgs? . remove ( at: i)
159
+ IOImg . delete ( img)
160
+ } label: {
161
+ Label ( " 删除 " , image: " circle " )
162
+ }
156
163
157
- }
158
- }
159
- } else if img. url. isEmpty == false {
160
- NukeImage ( url: img. url)
161
- . contextMenu {
162
- Button {
163
- IOInfo . updateCoverImage ( info: info, img: IOImg ( url: img. url) )
164
- } label: {
165
- Label ( " 设为封面图 " , image: " doc.text.image " )
164
+ }
166
165
}
167
- Button {
168
- let p = NSPasteboard . general
169
- p. declareTypes ( [ . string] , owner: nil )
170
- p. setString ( img. url, forType: . string)
171
- } label: {
172
- Label ( " 复制图片链接 " , image: " circle " )
166
+ } else if img. url. isEmpty == false {
167
+ NukeImage ( url: img. url)
168
+ . contextMenu {
169
+ Button {
170
+ IOInfo . updateCoverImage ( info: info, img: IOImg ( url: img. url) )
171
+ } label: {
172
+ Label ( " 设为封面图 " , image: " doc.text.image " )
173
+ }
174
+ Button {
175
+ let p = NSPasteboard . general
176
+ p. declareTypes ( [ . string] , owner: nil )
177
+ p. setString ( img. url, forType: . string)
178
+ } label: {
179
+ Label ( " 复制图片链接 " , image: " circle " )
180
+ }
181
+ Button {
182
+ info. imgs? . remove ( at: i)
183
+ IOImg . delete ( img)
184
+ } label: {
185
+ Label ( " 删除 " , image: " circle " )
186
+ }
173
187
}
174
- Button {
175
- info. imgs? . remove ( at: i)
176
- IOImg . delete ( img)
177
- } label: {
178
- Label ( " 删除 " , image: " circle " )
188
+ . onTapGesture {
189
+ largeImageUrlStr = img. url
179
190
}
180
191
}
192
+ } // end VStack
193
+ } // end ForEach
194
+ } // end LazyVGrid
195
+ }
196
+ } // end if let
197
+ if info. imageUrls. isEmpty == false {
198
+ LazyVGrid ( columns: [ GridItem ( . adaptive( minimum: 150 ) , spacing: 10 ) ] ) {
199
+ ForEach ( info. imageUrls, id: \. self) { img in
200
+ NukeImage ( url: img)
201
+ . contextMenu {
202
+ Button {
203
+ IOInfo . updateCoverImage ( info: info, img: IOImg ( url: img) )
204
+ } label: {
205
+ Label ( " 设为封面图 " , image: " doc.text.image " )
206
+ }
207
+ Button {
208
+ let p = NSPasteboard . general
209
+ p. declareTypes ( [ . string] , owner: nil )
210
+ p. setString ( img, forType: . string)
211
+ } label: {
212
+ Label ( " 复制图片链接 " , image: " circle " )
181
213
}
182
- } // end VStack
183
- } // end ForEach
184
- } // end LazyVGrid
185
- }
186
- } // end if let
187
- if info. imageUrls. isEmpty == false {
188
- LazyVGrid ( columns: [ GridItem ( . adaptive( minimum: 150 ) , spacing: 10 ) ] ) {
189
- ForEach ( info. imageUrls, id: \. self) { img in
190
- NukeImage ( url: img)
191
- . contextMenu {
192
- Button {
193
- IOInfo . updateCoverImage ( info: info, img: IOImg ( url: img) )
194
- } label: {
195
- Label ( " 设为封面图 " , image: " doc.text.image " )
196
214
}
197
- Button {
198
- let p = NSPasteboard . general
199
- p. declareTypes ( [ . string] , owner: nil )
200
- p. setString ( img, forType: . string)
201
- } label: {
202
- Label ( " 复制图片链接 " , image: " circle " )
215
+ . onTapGesture {
216
+ withAnimation {
217
+ largeImageUrlStr = img
218
+ }
203
219
}
204
220
}
205
221
}
206
222
}
223
+ } // end scrollView
224
+ if largeImageUrlStr. isEmpty == false {
225
+ NukeImage ( url: largeImageUrlStr)
226
+ . onTapGesture {
227
+ withAnimation {
228
+ largeImageUrlStr = " "
229
+ }
230
+ }
231
+ }
232
+ if largeNSImage != nil {
233
+ Image ( nsImage: largeNSImage!)
234
+ . resizable ( )
235
+ . scaledToFit ( )
236
+ . onTapGesture {
237
+ withAnimation {
238
+ largeNSImage = nil
239
+ }
240
+ }
207
241
}
208
242
}
209
243
}
244
+ . onChange ( of: info, { oldValue, newValue in
245
+ largeImageUrlStr = " "
246
+ largeNSImage = nil
247
+ } )
210
248
. padding ( 10 )
211
249
. tabItem { Label ( " 图集 " , systemImage: " circle " ) }
212
250
. tag ( 5 )
@@ -306,7 +344,13 @@ struct EditInfoView: View {
306
344
func urlInputView( ) -> some View {
307
345
HStack {
308
346
TextField ( " 地址: " , text: $info. url, prompt: Text ( " 输入或粘贴 url,例如 https://www.starming.com " ) ) . rounded ( )
309
- . onSubmit {
347
+ // .onSubmit {
348
+ // Task.detached(priority: .background, operation: {
349
+ //
350
+ // })
351
+ // }
352
+ if info. url. isEmpty == false {
353
+ Button {
310
354
Task {
311
355
// MARK: 获取 Web 内容
312
356
info. name = " 获取标题中...... "
@@ -321,8 +365,9 @@ struct EditInfoView: View {
321
365
}
322
366
}
323
367
}
368
+ } label: {
369
+ Text ( " 解析 " )
324
370
}
325
- if info. url. isEmpty == false {
326
371
Button {
327
372
gotoWebBrowser ( urlStr: info. url)
328
373
} label: {
@@ -454,7 +499,6 @@ struct EditInfoView: View {
454
499
var imageUrls = [ String] ( )
455
500
456
501
// 获取图集
457
-
458
502
do {
459
503
let imgs = try soup. select ( " img " ) . array ( )
460
504
if imgs. count > 0 {
0 commit comments