From 0b870654d1aed80f40db5b4d9a0452f454afca05 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 13 May 2020 13:03:56 +0800 Subject: [PATCH] =?UTF-8?q?A=20=E6=B7=BB=E5=8A=A0=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/deploy/urls.py | 1 - spug_api/apps/deploy/views.py | 21 +++---- spug_web/src/components/AuthButton.js | 2 +- spug_web/src/pages/deploy/request/Table.js | 9 ++- spug_web/src/pages/deploy/request/index.js | 64 +++++++++++++++++++--- spug_web/src/pages/deploy/request/store.js | 16 ++++++ 6 files changed, 89 insertions(+), 24 deletions(-) diff --git a/spug_api/apps/deploy/urls.py b/spug_api/apps/deploy/urls.py index df2b80c..c4d38d6 100644 --- a/spug_api/apps/deploy/urls.py +++ b/spug_api/apps/deploy/urls.py @@ -8,5 +8,4 @@ from .views import * urlpatterns = [ path('request/', RequestView.as_view()), path('request//', RequestDetailView.as_view()), - path('request/batch', RequestBatchView.as_view()), ] diff --git a/spug_api/apps/deploy/views.py b/spug_api/apps/deploy/views.py index abe41f4..5a0024f 100644 --- a/spug_api/apps/deploy/views.py +++ b/spug_api/apps/deploy/views.py @@ -108,10 +108,15 @@ class RequestView(View): def delete(self, request): form, error = JsonParser( - Argument('id', type=int, help='缺少必要参数') + Argument('id', type=int, required=False), + Argument('expire', required=False) ).parse(request.GET) if error is None: - DeployRequest.objects.filter(pk=form.id, status__in=('0', '1', '-1')).delete() + if form.id: + DeployRequest.objects.filter(pk=form.id, status__in=('0', '1', '-1')).delete() + if form.expire: + count, _ = DeployRequest.objects.filter(created_at__lt=form.expire).delete() + return json_response(count) return json_response(error=error) @@ -186,15 +191,3 @@ class RequestDetailView(View): req.reason = form.reason req.save() return json_response(error=error) - - -class RequestBatchView(View): - - def delete(self, request): - form, error = JsonParser( - Argument('expire_time', type=str, help="缺少必要参赛"), - ).parse(request.body) - if error is None: - DeployRequest.objects.filter(created_at__lt=form.expire_time).delete() - return json_response(error=error) - \ No newline at end of file diff --git a/spug_web/src/components/AuthButton.js b/spug_web/src/components/AuthButton.js index 58a678f..d9d0e4d 100644 --- a/spug_web/src/components/AuthButton.js +++ b/spug_web/src/components/AuthButton.js @@ -13,5 +13,5 @@ export default function AuthButton(props) { if (props.auth && !hasPermission(props.auth)) { disabled = true; } - return + return props.hide && disabled ? null : } diff --git a/spug_web/src/pages/deploy/request/Table.js b/spug_web/src/pages/deploy/request/Table.js index 9f3b4f7..ca76146 100644 --- a/spug_web/src/pages/deploy/request/Table.js +++ b/spug_web/src/pages/deploy/request/Table.js @@ -70,7 +70,7 @@ class ComTable extends React.Component { } else if (info.status === '-3') { return {info['status_alias']} } else { - return info['status_alias'] + return {info['status_alias']} } } }, { @@ -182,6 +182,13 @@ class ComTable extends React.Component { return date >= store.f_s_date && date <= store.f_e_date }) } + if (store.f_status !== 'all') { + if (store.f_status === '99') { + data = data.filter(item => ['-1', '2'].includes(item['status'])) + } else { + data = data.filter(item => item['status'] === store.f_status) + } + } return ( ) diff --git a/spug_web/src/pages/deploy/request/index.js b/spug_web/src/pages/deploy/request/index.js index 23a714c..6b7ffb7 100644 --- a/spug_web/src/pages/deploy/request/index.js +++ b/spug_web/src/pages/deploy/request/index.js @@ -5,19 +5,27 @@ */ import React from 'react'; import { observer } from 'mobx-react'; -import { Button, Select, DatePicker } from 'antd'; -import { SearchForm, AuthDiv, AuthCard } from 'components'; +import { Button, Select, DatePicker, Radio, Row, Col, Modal, Form, message } from 'antd'; +import { SearchForm, AuthButton, AuthCard } from 'components'; import SelectApp from './SelectApp'; import Ext1Form from './Ext1Form'; import Ext2Form from './Ext2Form'; import Approve from './Approve'; import ComTable from './Table'; +import http from 'libs/http'; import envStore from 'pages/config/environment/store'; import appStore from 'pages/config/app/store' import store from './store'; @observer class Index extends React.Component { + constructor(props) { + super(props); + this.state = { + expire: undefined + } + } + componentDidMount() { if (envStore.records.length === 0) { envStore.fetchRecords() @@ -27,6 +35,25 @@ class Index extends React.Component { } } + handleBatchDel = () => { + Modal.confirm({ + icon: 'exclamation-circle', + title: '批量删除发布申请', + content: ( + + 将删除截止日期之前的所有发布申请记录。}> + this.setState({expire: val.format('YYYY-MM-DD')})}/> + + + ), + onOk: () => http.delete(`/api/deploy/request/?expire=${this.state.expire}`) + .then(res => { + message.success(`成功删除${res}条记录`); + store.fetchRecords() + }), + }) + }; + render() { return ( @@ -46,15 +73,38 @@ class Index extends React.Component { - + - + - - - + + + store.f_status = e.target.value}> + 全部({store.counter['all'] || 0}) + 待审核({store.counter['0'] || 0}) + 待发布({store.counter['1'] || 0}) + 发布成功({store.counter['3'] || 0}) + 发布异常({store.counter['-3'] || 0}) + 其他({store.counter['99'] || 0}) + + + + 批量删除 + store.addVisible = true}>新建发布申请 + + {store.addVisible && } {store.ext1Visible && } diff --git a/spug_web/src/pages/deploy/request/store.js b/spug_web/src/pages/deploy/request/store.js index 75a0191..5f5f66f 100644 --- a/spug_web/src/pages/deploy/request/store.js +++ b/spug_web/src/pages/deploy/request/store.js @@ -12,6 +12,7 @@ class Store { @observable types = []; @observable record = {}; @observable refs = {}; + @observable counter = {}; @observable isLoading = false; @observable isFetching = false; @observable addVisible = false; @@ -19,6 +20,7 @@ class Store { @observable ext2Visible = false; @observable approveVisible = false; + @observable f_status = 'all'; @observable f_app_id; @observable f_env_id; @observable f_s_date; @@ -28,9 +30,23 @@ class Store { this.isFetching = true; http.get('/api/deploy/request/') .then(res => this.records = res) + .then(this._updateCounter) .finally(() => this.isFetching = false) }; + _updateCounter = () => { + const counter = {'all': 0, '-3': 0, '-1': 0, '0': 0, '1': 0, '2': 0, '3': 0}; + for (let item of this.records) { + counter['all'] += 1; + if (['-1', '2'].includes(item['status'])) { + counter['99'] += 1 + } else { + counter[item['status']] += 1 + } + } + this.counter = counter + }; + loadDeploys = () => { this.isLoading = true; http.get('/api/app/deploy/')