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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import React, { useEffect, useState } from 'react'
import SiteModal from '@/components/Modal/SiteModa';
import { Checkbox, Input, Button, Modal, Form, Radio, DatePicker, Switch, Select, message } from 'antd'
import HourOfDaySelect from './HourOfDaySelect'
import DayOfWeekSelect from './DayOfWeekSelect'
import styles from './VisibleIISAgentConfig.less'
import moment from 'moment'
import { tr } from 'voca';
const { Item } = Form;
const VisibleIISAgentConfig = props => {
const [loading, setLoading] = useState(false);
const [previewVisible, setPreviewVisible] = useState(false)
const [selectRole, setSelectRole] = useState([])
const [isReentrant, setIsReentrant] = useState(false)
const [postCheck, setPostCheck] = useState(false)
const [reenCheck, setReenCheck] = useState(false)
const [logCheck, setLogCheck] = useState(false)
const [isEndTimeShow, setIsEndTimeShow] = useState(false)
const [isLoopShow, setIsLoopShow] = useState(false)
const [isDayLoopShow, setIsDayLoopShow] = useState(false)
const [isWeekLoopShow, setIsWeekLoopShow] = useState(false)
const [form] = Form.useForm();
const dateFormat = 'YYYY-MM-DD HH:mm:ss';
const { agentConfig, value, onIISAgentSubmit } = props
useEffect(() => {
if (agentConfig) {
form.setFieldsValue({
is_enable: agentConfig.Enabled,
url_type: agentConfig.Absolute ? false : true,
url_path: agentConfig.Url,
request_header: agentConfig.CustomHeader,
plan_type: agentConfig.LoopMode,
start_time: moment(agentConfig.StartFrom, dateFormat),
end_time: moment(agentConfig.EndAt, dateFormat),
loop_mode: agentConfig.LoopMode,
interval: agentConfig.Interval,
loop_unit: agentConfig.LoopUnit,
hour_of_day: agentConfig.HourOfDay && agentConfig.HourOfDay.split(","),
day_of_week: agentConfig.DayOfWeek,
time_out: agentConfig.Timeout,
post_state: agentConfig.UsePostState,
reentrant: agentConfig.AllowReentrant,
enable_log: agentConfig.AllowLog,
})
changeLoopMode(agentConfig.LoopMode)
setReenCheck(agentConfig.AllowReentrant)
setPostCheck(agentConfig.UsePostState)
setLogCheck(agentConfig.AllowLog)
}
form.setFieldsValue({
name: value
})
setSelectRole(props.value)
}, [props])
const handleCancel = () => {
setPreviewVisible(false)
}
const handleOk = () => {
let fv = form.getFieldValue()
onIISAgentSubmit && onIISAgentSubmit(
{
Url: fv.url_path,
CustomHeader: fv.request_header,
StartFrom: fv.start_time && fv.start_time.format(dateFormat),
EndAt: fv.end_time && fv.end_time.format(dateFormat),
MillisecondsTimeout: parseInt(fv.time_out) ,
LoopMode: fv.loop_mode,
LoopUnit: fv.loop_unit,
MonthOfYear: null,
WeekOfMonth: null,
DayOfWeek: fv.day_of_week && fv.day_of_week.toString(),
DayOfMonth: null,
HourOfDay: fv.hour_of_day && fv.hour_of_day.toString(),
Interval: fv.interval,
UsePostState: fv.post_state,
AllowReentrant: fv.reentrant,
AllowLog: fv.enable_log,
Enabled: fv.is_enable,
Timeout: parseInt(fv.time_out),
Absolute: true,
SiteInfo:null,
Name:fv.name,
Tolerate:null
}
)
setPreviewVisible(false)
}
const handleClick = () => {
if (value) {
setPreviewVisible(true)
} else {
message.error("请先输入方案名称!")
}
}
const onPostChange = (value) => {
setIsReentrant(value)
setPostCheck(value)
form.setFieldsValue({
post_state: value
})
}
const onReenChange = (value) => {
setReenCheck(value)
form.setFieldsValue({
reentrant: value
})
}
const onLogChange = (value) => {
setLogCheck(value)
form.setFieldsValue({
enable_log: value
})
}
const changeLoopMode = (value) => {
switch (value) {
case "ByOnce":
setIsEndTimeShow(false)
setIsLoopShow(true)
setIsWeekLoopShow(false)
setIsDayLoopShow(false)
break
case "BYLOOP":
setIsEndTimeShow(true)
setIsLoopShow(true)
setIsWeekLoopShow(false)
setIsDayLoopShow(false)
break
case "ByDay":
setIsEndTimeShow(true)
setIsLoopShow(false)
setIsWeekLoopShow(false)
setIsDayLoopShow(true)
break
case "ByWeek":
setIsEndTimeShow(true)
setIsLoopShow(false)
setIsWeekLoopShow(true)
setIsDayLoopShow(true)
break
}
}
const onLoopModeChange = (e) => {
changeLoopMode(e.target.value)
}
return (
<div className={styles.agent_container}>
<Input value={selectRole} disabled={true} />
<div className={styles.select_btn} onClick={handleClick}>推送计划</div>
<SiteModal
{...props}
title="编辑定时任务"
bodyStyle={{ width: '100%', minHeight: '100px' }}
style={{ top: 200, borderRadius: '20px' }}
width="800px"
destroyOnClose
cancelText="取消"
okText="确认"
visible={previewVisible}
onOk={() => handleOk()}
confirmLoading={loading}
visible={previewVisible}
onCancel={handleCancel}
>
<div className={styles.IISAgent_container}>
<Form form={form} labelCol={{ span: 4 }}>
<Item
label="计划名称"
name="name"
>
<Input placeholder="请输入计划名称" disabled={true} />
</Item>
<Item
label="是否开启"
name="is_enable"
>
<Select >
<Option value={true}>开启</Option>
<Option value={false}>关闭</Option>
</Select>
</Item>
<Item
label="路径类型"
name="url_type"
>
<Radio.Group >
<Radio value={false}>相对路径</Radio>
<Radio value={true}>绝对路径</Radio>
</Radio.Group>
</Item>
<Item
label="URL路径"
name="url_path"
>
<Input placeholder="请输入URL名称" />
</Item>
<Item
label="请求头"
name="request_header"
>
<Input placeholder="请输入URL名称" />
</Item>
<Item
label="执行方式"
name="loop_mode"
>
<Radio.Group onChange={onLoopModeChange}>
<Radio value={"ByOnce"}>一次</Radio>
<Radio value={"BYLOOP"}>循环</Radio>
<Radio value={"ByDay"}>每天</Radio>
<Radio value={"ByWeek"}>每周</Radio>
</Radio.Group>
</Item>
<Item
label="开始时间"
name="start_time"
>
<DatePicker showTime />
</Item>
{
isEndTimeShow && (
<Item
label="结束时间"
name="end_time"
>
<DatePicker showTime />
</Item>
)
}
{
isLoopShow && (
<div>
<Item
label="循环周期"
name="interval"
>
<Input placeholder="请输入循环周期" />
</Item>
<Item
label="循环单位"
name="loop_unit"
>
<Input placeholder="请输入循环单位" />
</Item>
</div>
)
}
{
isDayLoopShow && (
<Item
label="日循环"
name="hour_of_day"
>
<HourOfDaySelect />
</Item>
)
}
{
isWeekLoopShow && (
<Item
label="周循环"
name="day_of_week"
>
<DayOfWeekSelect />
</Item>
)
}
<Item
label="超时时间"
name="time_out"
>
<Input />
</Item>
<Item
label="POST状态"
name="post_state"
>
<Switch checkedChildren="开启" unCheckedChildren="关闭" onChange={onPostChange} checked={postCheck} />
</Item>
<Item
label="允许重入"
name="reentrant"
>
<Switch checkedChildren="开启" unCheckedChildren="关闭" onChange={onReenChange} disabled={isReentrant} checked={reenCheck} />
</Item>
<Item
label="开启日志"
name="enable_log"
>
<Switch checkedChildren="开启" unCheckedChildren="关闭" onChange={onLogChange} checked={logCheck} />
</Item>
</Form>
</div>
</SiteModal>
</div>
)
}
export default VisibleIISAgentConfig;