|
@@ -1,18 +1,13 @@
|
|
|
import React from 'react'
|
|
|
-import { Button, Input, Table, Badge, Popconfirm } from 'antd'
|
|
|
+import { Button, Table, Badge, Popconfirm, Checkbox, Switch } from 'antd'
|
|
|
import AddTaskModal from './components/addTask'
|
|
|
import StartTaskModal from './components/startTask'
|
|
|
import router from 'umi/router'
|
|
|
-
|
|
|
-import {
|
|
|
- taskBegin,
|
|
|
- taskStop,
|
|
|
- taskUpdate,
|
|
|
- taskAdd,
|
|
|
- taskCopy,
|
|
|
- taskList
|
|
|
-} from './service'
|
|
|
-const { Search } = Input
|
|
|
+import { FilterTable } from 'wptpc-design'
|
|
|
+import { yc } from '@/conf/config'
|
|
|
+import Style from './index.less'
|
|
|
+import { taskBegin, taskStop, taskUpdate, taskAdd, taskCopy, caseAdd, caseDel } from './service'
|
|
|
+const apiUrl = `${yc}/schedule/task/list`
|
|
|
|
|
|
const scheduleState = {
|
|
|
0: {
|
|
@@ -40,9 +35,14 @@ class Halberd extends React.PureComponent {
|
|
|
addFormVisible: false,
|
|
|
updateFormVisible: false,
|
|
|
startTaskVisible: false,
|
|
|
- params: { detail: [] }
|
|
|
+ params: { detail: [] },
|
|
|
+ copyNeedCase: false,
|
|
|
+ copyNeedNew: false,
|
|
|
+ refreshChecked: false
|
|
|
};
|
|
|
|
|
|
+ refreshTime = 0;
|
|
|
+
|
|
|
columns = [
|
|
|
{
|
|
|
title: '压测任务',
|
|
@@ -67,11 +67,45 @@ class Halberd extends React.PureComponent {
|
|
|
title: '操作',
|
|
|
key: '_id',
|
|
|
render: value => {
|
|
|
+ const { copyNeedCase, copyNeedNew } = this.state
|
|
|
+ const titleNode = (
|
|
|
+ <div>
|
|
|
+ 确定要复制吗?
|
|
|
+ <div>
|
|
|
+ <Checkbox
|
|
|
+ checked={copyNeedCase}
|
|
|
+ onChange={e => {
|
|
|
+ this.setState({
|
|
|
+ copyNeedCase: e.target.checked
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 复制 case
|
|
|
+ </Checkbox>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <Checkbox
|
|
|
+ checked={copyNeedNew}
|
|
|
+ onChange={e => {
|
|
|
+ this.setState({
|
|
|
+ copyNeedNew: e.target.checked
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 重新构造数据
|
|
|
+ </Checkbox>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
return (
|
|
|
<div>
|
|
|
<Popconfirm
|
|
|
- title="确定复制吗?"
|
|
|
- onConfirm={() => this.copyTask(value._id)}
|
|
|
+ title={titleNode}
|
|
|
+ onConfirm={() => {
|
|
|
+ this.copyTask(value._id, copyNeedCase, copyNeedNew)
|
|
|
+ this.clearCopyState()
|
|
|
+ }}
|
|
|
+ onCancel={this.clearCopyState}
|
|
|
okText="确定"
|
|
|
cancelText="取消"
|
|
|
>
|
|
@@ -93,13 +127,12 @@ class Halberd extends React.PureComponent {
|
|
|
<Button
|
|
|
type="primary"
|
|
|
size={'small'}
|
|
|
- disabled={value.state !== 1 && value.state !== 3}
|
|
|
style={{ margin: '0 5px' }}
|
|
|
onClick={() => {
|
|
|
this.showStartTaskModal(value._id)
|
|
|
}}
|
|
|
>
|
|
|
- 开始压测
|
|
|
+ 添加 case
|
|
|
</Button>
|
|
|
<Popconfirm
|
|
|
title="确定停止吗?"
|
|
@@ -127,40 +160,20 @@ class Halberd extends React.PureComponent {
|
|
|
}
|
|
|
];
|
|
|
|
|
|
- componentDidMount () {
|
|
|
- this.getTackList()
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取压测任务列表
|
|
|
- * @param {*} name
|
|
|
- */
|
|
|
- getTackList = (name = '') => {
|
|
|
- taskList({
|
|
|
- page: 1, // 页数
|
|
|
- pageNum: 10000, // 一页展示数量
|
|
|
- taskName: name // 任务名称
|
|
|
- }).then(res => {
|
|
|
- const { code, data } = res
|
|
|
- if (code === 0) {
|
|
|
- this.setState({
|
|
|
- data: data.list || []
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- };
|
|
|
-
|
|
|
/**
|
|
|
* 复制任务
|
|
|
* @param {*} id
|
|
|
*/
|
|
|
- copyTask = id => {
|
|
|
+ copyTask = (id, needCase, needNew) => {
|
|
|
+ console.log('copy', id, needCase, needNew)
|
|
|
taskCopy({
|
|
|
- id // 需要复制的任务id
|
|
|
+ id, // 需要复制的任务id
|
|
|
+ needCase: Number(needCase), // 是否需要复制case,0不需要 1需要
|
|
|
+ needNew: Number(needNew) // 是否更新数据,0不需要 1需要
|
|
|
}).then(res => {
|
|
|
const { code } = res
|
|
|
if (code === 0) {
|
|
|
- this.getTackList()
|
|
|
+ this.refresh()
|
|
|
}
|
|
|
})
|
|
|
};
|
|
@@ -175,35 +188,25 @@ class Halberd extends React.PureComponent {
|
|
|
}).then(res => {
|
|
|
const { code } = res
|
|
|
if (code === 0) {
|
|
|
- this.getTackList()
|
|
|
+ this.refresh()
|
|
|
}
|
|
|
})
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
|
* 打开查看详情弹窗
|
|
|
* @param {*} id
|
|
|
*/
|
|
|
viewTaskDetail = value => {
|
|
|
- const { data } = this.state
|
|
|
// eslint-disable-next-line camelcase
|
|
|
const { _id: id, name, get_token_url } = value
|
|
|
- let detail = ''
|
|
|
-
|
|
|
- data.forEach(item => {
|
|
|
- if (item._id === id) {
|
|
|
- console.log('item.detail', value, data)
|
|
|
-
|
|
|
- detail = item.detail
|
|
|
- }
|
|
|
- })
|
|
|
this.setState({
|
|
|
updateFormVisible: true,
|
|
|
params: {
|
|
|
id,
|
|
|
name: name,
|
|
|
getTokenUrl: get_token_url,
|
|
|
- detail: JSON.parse(detail)
|
|
|
+ detail: JSON.parse(value.detail)
|
|
|
}
|
|
|
})
|
|
|
};
|
|
@@ -227,7 +230,7 @@ class Halberd extends React.PureComponent {
|
|
|
*/
|
|
|
showViewReport = id => {
|
|
|
router.push(`/halberd/viewReport?id=${id}`)
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
|
* 打开添加弹窗
|
|
@@ -258,17 +261,19 @@ class Halberd extends React.PureComponent {
|
|
|
taskAdd({
|
|
|
name,
|
|
|
getTokenUrl: getTokenUrl,
|
|
|
- detail: JSON.stringify(detail.map(item => {
|
|
|
- return {
|
|
|
- ...item,
|
|
|
- rate: Number(item.rate)
|
|
|
- }
|
|
|
- }))
|
|
|
+ detail: JSON.stringify(
|
|
|
+ detail.map(item => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ rate: Number(item.rate)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ )
|
|
|
}).then(res => {
|
|
|
const { code } = res
|
|
|
if (code === 0) {
|
|
|
this.hidden()
|
|
|
- this.getTackList()
|
|
|
+ this.refresh()
|
|
|
}
|
|
|
})
|
|
|
};
|
|
@@ -279,7 +284,6 @@ class Halberd extends React.PureComponent {
|
|
|
*/
|
|
|
updateTask = data => {
|
|
|
const { name = '', getTokenUrl, detail = [] } = data
|
|
|
-
|
|
|
taskUpdate({
|
|
|
id: data.id,
|
|
|
name,
|
|
@@ -295,14 +299,13 @@ class Halberd extends React.PureComponent {
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * 开始压测任务
|
|
|
+ * 添加 case
|
|
|
* @param {*} data
|
|
|
*/
|
|
|
- startTask = data => {
|
|
|
- console.log(data)
|
|
|
+ taskCaseAdd = data => {
|
|
|
const { id, connects, threads, timeout, duration } = data
|
|
|
- taskBegin({
|
|
|
- id,
|
|
|
+ caseAdd({
|
|
|
+ TaskId: id,
|
|
|
connects: Number(connects),
|
|
|
threads: Number(threads),
|
|
|
timeout: Number(timeout),
|
|
@@ -311,28 +314,205 @@ class Halberd extends React.PureComponent {
|
|
|
const { code } = res
|
|
|
if (code === 0) {
|
|
|
this.hidden()
|
|
|
- this.getTackList()
|
|
|
+ this.refresh()
|
|
|
}
|
|
|
})
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * 开始压测 case 任务
|
|
|
+ * @param {*} data
|
|
|
+ */
|
|
|
+ startTask = (record, data) => {
|
|
|
+ const { _id: id } = record
|
|
|
+ const { _id } = data
|
|
|
+ taskBegin({
|
|
|
+ id,
|
|
|
+ caseId: _id
|
|
|
+ }).then(() => {
|
|
|
+ this.refresh()
|
|
|
+ })
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除压测 case 任务
|
|
|
+ * @param {*} data
|
|
|
+ */
|
|
|
+ delTask = data => {
|
|
|
+ const { _id } = data
|
|
|
+ caseDel({
|
|
|
+ caseId: _id
|
|
|
+ }).then(() => {
|
|
|
+ this.refresh()
|
|
|
+ })
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清空拷贝状态
|
|
|
+ */
|
|
|
+ clearCopyState = () => {
|
|
|
+ this.setState({
|
|
|
+ copyNeedCase: false,
|
|
|
+ copyNeedNew: false
|
|
|
+ })
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始轮训
|
|
|
+ */
|
|
|
+ startRefreshState = () => {
|
|
|
+ this.refresh()
|
|
|
+ this.refreshTime = setInterval(() => {
|
|
|
+ this.refresh()
|
|
|
+ }, 5000)
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结束轮训
|
|
|
+ */
|
|
|
+ stopRefreshState = () => {
|
|
|
+ clearInterval(this.refreshTime)
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 展开行-获取压测case列表
|
|
|
+ */
|
|
|
+ onExpandGetCaseList = record => {
|
|
|
+ if (record.cases && record.cases.length) {
|
|
|
+ const columns = [
|
|
|
+ {
|
|
|
+ title: '线程数',
|
|
|
+ dataIndex: 'threads',
|
|
|
+ key: 'threads',
|
|
|
+ align: 'center',
|
|
|
+ width: 200
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '链接数',
|
|
|
+ dataIndex: 'connects',
|
|
|
+ key: 'connects',
|
|
|
+ align: 'center',
|
|
|
+ width: 200
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '接口超时时间',
|
|
|
+ dataIndex: 'timeout',
|
|
|
+ key: 'timeout',
|
|
|
+ align: 'center',
|
|
|
+ width: 200
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '压测持续时间',
|
|
|
+ dataIndex: 'duration',
|
|
|
+ key: 'duration',
|
|
|
+ align: 'center',
|
|
|
+ width: 200
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ align: 'center',
|
|
|
+ key: '_id',
|
|
|
+ render: cases => {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ {record.state === 1 || record.state === 3 ? (
|
|
|
+ <React.Fragment>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定开始压测吗?"
|
|
|
+ onConfirm={() => this.startTask(record, cases)}
|
|
|
+ okText="确定"
|
|
|
+ cancelText="取消"
|
|
|
+ >
|
|
|
+ <a>开始</a>
|
|
|
+ </Popconfirm>
|
|
|
+
|
|
|
+ <Popconfirm
|
|
|
+ title="确定删除该 case 吗?"
|
|
|
+ onConfirm={() => this.delTask(cases)}
|
|
|
+ okText="确定"
|
|
|
+ cancelText="取消"
|
|
|
+ >
|
|
|
+ <a>删除</a>
|
|
|
+ </Popconfirm>
|
|
|
+ </React.Fragment>
|
|
|
+ ) : (
|
|
|
+ <React.Fragment>
|
|
|
+ <span style={{ color: 'gray' }}>开始</span>
|
|
|
+ <span style={{ color: 'gray' }}>删除</span>
|
|
|
+ </React.Fragment>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <Table
|
|
|
+ rowKey="_id"
|
|
|
+ bordered
|
|
|
+ rowClassName={() => Style.rowClass}
|
|
|
+ columns={columns}
|
|
|
+ dataSource={record.cases}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return <div>当前任务没有 case</div>
|
|
|
+ };
|
|
|
+
|
|
|
render () {
|
|
|
- const { data, addFormVisible, updateFormVisible, startTaskVisible, params } = this.state
|
|
|
+ const { addFormVisible, updateFormVisible, startTaskVisible, params, refreshChecked } = this.state
|
|
|
+ // filtertable的搜索项配置
|
|
|
+ const filterSetting = {
|
|
|
+ isClearSearch: true,
|
|
|
+ // 这个数组里面的每一个元素就是一个搜索项
|
|
|
+ formFields: [
|
|
|
+ {
|
|
|
+ type: 'input',
|
|
|
+ key: 'taskName',
|
|
|
+ placeholder: '请输入压测任务名进行搜索',
|
|
|
+ style: { width: 400 }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ // 在接口请求前,可以修改给接口的入参
|
|
|
+ beforeSearchFunc: params => {
|
|
|
+ params.pageSize = params.pageNum
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // filtertable的列表配置
|
|
|
+ const tableSetting = {
|
|
|
+ rowKey: '_id',
|
|
|
+ pagination: {
|
|
|
+ pageSize: 10
|
|
|
+ },
|
|
|
+ rowClassName: Style.filterRow,
|
|
|
+ expandedRowRender: this.onExpandGetCaseList,
|
|
|
+ columnConfig: this.columns,
|
|
|
+ getRefresh: refresh => {
|
|
|
+ this.refresh = refresh
|
|
|
+ }
|
|
|
+ }
|
|
|
return (
|
|
|
<div style={{ margin: '0 auto' }}>
|
|
|
- <Search
|
|
|
- placeholder="请输入压测任务名进行搜索"
|
|
|
- enterButton="搜索"
|
|
|
- onSearch={value => this.getTackList(value)}
|
|
|
- style={{ width: 400 }}
|
|
|
- />
|
|
|
-
|
|
|
<div style={{ margin: '20px 0' }}>
|
|
|
<Button type="primary" onClick={this.showAddTask}>
|
|
|
- 添加
|
|
|
+ 添加压测任务
|
|
|
</Button>
|
|
|
+ <span style={{ float: 'right', marginRight: '120px' }}>定时刷新: <Switch checked={refreshChecked} onChange={(checked) => {
|
|
|
+ if (checked) {
|
|
|
+ this.startRefreshState()
|
|
|
+ } else {
|
|
|
+ this.stopRefreshState()
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ refreshChecked: checked
|
|
|
+ })
|
|
|
+ }}/></span>
|
|
|
</div>
|
|
|
- <Table dataSource={data} columns={this.columns} rowKey="_id" />
|
|
|
+ <FilterTable filterSetting={filterSetting} tableSetting={tableSetting} apiUrl={apiUrl} />
|
|
|
+
|
|
|
{addFormVisible && (
|
|
|
<AddTaskModal showModal={addFormVisible} onOk={this.addTask} onCancel={this.hidden} />
|
|
|
)}
|
|
@@ -348,7 +528,7 @@ class Halberd extends React.PureComponent {
|
|
|
{startTaskVisible && (
|
|
|
<StartTaskModal
|
|
|
showModal={startTaskVisible}
|
|
|
- onOk={this.startTask}
|
|
|
+ onOk={this.taskCaseAdd}
|
|
|
onCancel={this.hidden}
|
|
|
params={params}
|
|
|
/>
|