forked from andeya/pholcus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offline.go
276 lines (245 loc) · 5.71 KB
/
offline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package gui
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"github.com/henrylee2cn/pholcus/app"
"github.com/henrylee2cn/pholcus/config"
"github.com/henrylee2cn/pholcus/logs"
"github.com/henrylee2cn/pholcus/runtime/status"
)
func offlineWindow() {
mw.Close()
if err := (MainWindow{
AssignTo: &mw,
DataBinder: DataBinder{
AssignTo: &db,
DataSource: Input,
ErrorPresenter: ErrorPresenterRef{&ep},
},
Title: config.FULL_NAME + " 【 运行模式 -> 单机 】",
MinSize: Size{1100, 700},
Layout: VBox{MarginsZero: true},
Children: []Widget{
Composite{
AssignTo: &setting,
Layout: Grid{Columns: 2},
Children: []Widget{
// 任务列表
TableView{
ColumnSpan: 1,
MinSize: Size{550, 450},
AlternatingRowBGColor: walk.RGB(255, 255, 224),
CheckBoxes: true,
ColumnsOrderable: true,
Columns: []TableViewColumn{
{Title: "#", Width: 45},
{Title: "任务", Width: 110 /*, Format: "%.2f", Alignment: AlignFar*/},
{Title: "描述", Width: 370},
},
Model: spiderMenu,
},
VSplitter{
ColumnSpan: 1,
MinSize: Size{550, 450},
Children: []Widget{
VSplitter{
Children: []Widget{
Label{
Text: "自定义配置(多任务请分别多包一层“<>”):",
},
LineEdit{
Text: Bind("Keyins"),
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*采集上限(默认限制URL数):",
},
NumberEdit{
Value: Bind("Limit"),
Suffix: "",
Decimals: 0,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*并发协程:(1~99999)",
},
NumberEdit{
Value: Bind("ThreadNum", Range{1, 99999}),
Suffix: "",
Decimals: 0,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*分批输出大小:(1~5,000,000 条数据)",
},
NumberEdit{
Value: Bind("DockerCap", Range{1, 5000000}),
Suffix: "",
Decimals: 0,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*暂停时长参考:",
},
ComboBox{
Value: Bind("Pausetime", SelRequired{}),
DisplayMember: "Key",
BindingMember: "Int64",
Model: GuiOpt.Pausetime,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*代理IP更换频率:",
},
ComboBox{
Value: Bind("ProxyMinute", SelRequired{}),
DisplayMember: "Key",
BindingMember: "Int64",
Model: GuiOpt.ProxyMinute,
},
},
},
RadioButtonGroupBox{
ColumnSpan: 1,
Title: "*输出方式",
Layout: HBox{},
DataMember: "OutType",
Buttons: outputList,
},
},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
VSplitter{
Children: []Widget{
// 必填项错误检查
LineErrorPresenter{
AssignTo: &ep,
},
},
},
HSplitter{
MaxSize: Size{220, 50},
Children: []Widget{
Label{
Text: "继承并保存成功记录",
},
CheckBox{
Checked: Bind("SuccessInherit"),
},
},
},
HSplitter{
MaxSize: Size{220, 50},
Children: []Widget{
Label{
Text: "继承并保存失败记录",
},
CheckBox{
Checked: Bind("FailureInherit"),
},
},
},
VSplitter{
MaxSize: Size{90, 50},
Children: []Widget{
PushButton{
Text: "暂停/恢复",
AssignTo: &pauseRecoverBtn,
OnClicked: offlinePauseRecover,
},
},
},
VSplitter{
MaxSize: Size{90, 50},
Children: []Widget{
PushButton{
Text: "开始运行",
AssignTo: &runStopBtn,
OnClicked: offlineRunStop,
},
},
},
},
},
},
}.Create()); err != nil {
panic(err)
}
setWindow()
pauseRecoverBtn.SetVisible(false)
// 初始化应用
Init()
// 运行窗体程序
mw.Run()
}
// 暂停\恢复
func offlinePauseRecover() {
switch app.LogicApp.Status() {
case status.RUN:
pauseRecoverBtn.SetText("恢复运行")
case status.PAUSE:
pauseRecoverBtn.SetText("暂停")
}
app.LogicApp.PauseRecover()
}
// 开始\停止控制
func offlineRunStop() {
if !app.LogicApp.IsStopped() {
go func() {
runStopBtn.SetEnabled(false)
runStopBtn.SetText("停止中…")
pauseRecoverBtn.SetVisible(false)
pauseRecoverBtn.SetText("暂停")
app.LogicApp.Stop()
offlineResetBtn()
}()
return
}
if err := db.Submit(); err != nil {
logs.Log.Error("%v", err)
return
}
// 读取任务
Input.Spiders = spiderMenu.GetChecked()
// if len(Input.Spiders) == 0 {
// logs.Log.Warning(" * —— 亲,任务列表不能为空哦~")
// return
// }
runStopBtn.SetText("停止")
// 记录配置信息
SetTaskConf()
// 更新蜘蛛队列
SpiderPrepare()
go func() {
pauseRecoverBtn.SetText("暂停")
pauseRecoverBtn.SetVisible(true)
app.LogicApp.Run()
offlineResetBtn()
pauseRecoverBtn.SetVisible(false)
pauseRecoverBtn.SetText("暂停")
}()
}
// Offline 模式下按钮状态控制
func offlineResetBtn() {
runStopBtn.SetEnabled(true)
runStopBtn.SetText("开始运行")
}