From 6979e523f1b3df559718958cb45fd0118b313a18 Mon Sep 17 00:00:00 2001 From: zypo Date: Sat, 28 Jul 2018 22:37:55 +0800 Subject: [PATCH] =?UTF-8?q?U=20-=20=E4=B8=BB=E6=9C=BA=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?-=20=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=EF=BC=8C=E9=80=89=E6=8B=A9=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=90=9C=E7=B4=A2=E6=9D=A1=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/assets/host.py | 20 +++---- spug_web/src/components/assets/Host.vue | 27 +++++++--- spug_web/src/components/assets/HostExec.vue | 60 ++++++++++++++++----- 3 files changed, 77 insertions(+), 30 deletions(-) diff --git a/spug_api/apps/assets/host.py b/spug_api/apps/assets/host.py index 740fa98..33123f0 100644 --- a/spug_api/apps/assets/host.py +++ b/spug_api/apps/assets/host.py @@ -19,17 +19,19 @@ blueprint = Blueprint(__name__, __name__) def get(): form, error = JsonParser(Argument('page', type=int, default=1, required=False), Argument('pagesize', type=int, default=10, required=False), - Argument('host_zone', type=str, required=False),).parse(request.args) + Argument('host_query', type=dict, required=False), ).parse(request.args) if error is None: + print('host_ng', form) + host_data = Host.query if form.page == -1: - hosts_data = Host.query.all() - return json_response({'data': [x.to_json() for x in hosts_data], 'total': -1}) - elif form.host_zone: - hosts = Host.query.filter_by(zone=form.host_zone) - else: - hosts = Host.query - hosts_data = hosts.limit(form.pagesize).offset((form.page - 1) * form.pagesize).all() - return json_response({'data': [x.to_json() for x in hosts_data], 'total': hosts.count()}) + return json_response({'data': [x.to_json() for x in host_data.all()], 'total': -1}) + if form.host_query.get('name_field'): + host_data = host_data.filter(Host.name.like('%{}%'.format(form.host_query['name_field']))) + if form.host_query.get('zone_field'): + host_data = host_data.filter_by(zone=form.host_query['zone_field']) + + result = host_data.limit(form.pagesize).offset((form.page - 1) * form.pagesize).all() + return json_response({'data': [x.to_json() for x in result], 'total': host_data.count()}) return json_response(message=error) diff --git a/spug_web/src/components/assets/Host.vue b/spug_web/src/components/assets/Host.vue index a8ddbed..53b4c4d 100644 --- a/spug_web/src/components/assets/Host.vue +++ b/spug_web/src/components/assets/Host.vue @@ -1,13 +1,20 @@