首页时间段查询

This commit is contained in:
caoqianming 2021-02-22 11:31:19 +08:00
parent bf1bdcae3e
commit e51fedc48e
5 changed files with 78 additions and 10 deletions

View File

@ -1,9 +1,10 @@
import request from '@/utils/request' import request from '@/utils/request'
export function getBasicCount() { export function getBasicCount(query) {
return request({ return request({
url: '/analyse/basic/', url: '/analyse/basic/',
method: 'get', method: 'get',
params:query
}) })
} }

View File

@ -8,6 +8,7 @@
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
:picker-options="pickerOptions" :picker-options="pickerOptions"
@change="change"
> >
</el-date-picker> </el-date-picker>
<el-button type="primary" icon="el-icon-query" @click="handleFilter" <el-button type="primary" icon="el-icon-query" @click="handleFilter"
@ -111,6 +112,10 @@ export default {
this.monidata = res.data; this.monidata = res.data;
}); });
}, },
change(v){
console.log(v)
if (v == null) this.daterange=["",""]
}
}, },
}; };
</script> </script>

View File

@ -62,6 +62,7 @@ export default {
components: { components: {
CountTo CountTo
}, },
props:['query'],
data() { data() {
return { return {
ret:{ ret:{
@ -81,7 +82,7 @@ export default {
}, },
getBasicCount() { getBasicCount() {
this.listLoading = true; this.listLoading = true;
getBasicCount().then(response => { getBasicCount(this.query).then(response => {
this.ret = response.data; this.ret = response.data;
}); });
}, },

View File

@ -1,6 +1,21 @@
<template> <template>
<div class="dashboard-editor-container"> <div class="dashboard-editor-container">
<panel-group @handleSetLineChartData="handleSetLineChartData" /> <div style="margin-bottom: 2px">
<el-date-picker
v-model="daterange"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
@change="change"
>
</el-date-picker>
<el-button type="primary" icon="el-icon-query" @click="handleFilter"
>确定</el-button
>
</div>
<panel-group @handleSetLineChartData="handleSetLineChartData" ref="panelg" :query="query"/>
<el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;"> <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
<bar-chart :chartData="admindata1" /> <bar-chart :chartData="admindata1" />
@ -42,21 +57,56 @@ export default {
data() { data() {
return { return {
lineChartData: lineChartData.访问用户, lineChartData: lineChartData.访问用户,
admindata1:{} admindata1:{},
daterange:[],
query: { datestart: null, dateend: null },
pickerOptions: {
shortcuts: [{
text: '2020年',
onClick(picker) {
picker.$emit('pick', ['2020-01-01','2021-01-01']);
}
},
{
text: '2021年',
onClick(picker) {
picker.$emit('pick', ['2021-01-01','2022-01-01']);
}
}]
},
} }
}, },
created() { created() {
this.getadmindata1() this.initquery()
}, },
methods: { methods: {
handleSetLineChartData(type) { handleSetLineChartData(type) {
this.lineChartData = lineChartData[type] this.lineChartData = lineChartData[type]
}, },
initquery() {
let date = new Date();
let start = date.getFullYear() + "-01-01";
let end = date.getFullYear() + 1 + "-01-01";
this.daterange = [start,end];
// this.$refs["picker"].$emit('pick', [start, end]);
this.query.datestart = this.daterange[0];
this.query.dateend = this.daterange[1];
this.getadmindata1();
},
getadmindata1(){ getadmindata1(){
getAdmindata1().then(res=>{ getAdmindata1(this.query).then(res=>{
this.admindata1 = res.data this.admindata1 = res.data
}) })
}, },
handleFilter(){
this.query.datestart = this.daterange[0];
this.query.dateend = this.daterange[1];
this.getadmindata1();
this.$refs['panelg'].getBasicCount();
},
change(v){
if (v == null) this.daterange=["",""]
}
} }
} }
</script> </script>

View File

@ -21,10 +21,21 @@ class BasicCount(APIView):
''' '''
def get(self, request, format=None): def get(self, request, format=None):
ret={} ret={}
ret['consumer1_count'] = Consumer.objects.filter(is_delete=False).count() q1 = Consumer.objects.filter(is_delete=False)
ret['consumer2_count'] = Consumer.objects.filter(is_delete=False).exclude(create_admin=None).count() q1 = q1.filter(create_time__gte = request.query_params.get('datestart')) if request.query_params.get('datestart', None) else q1
ret['test_count'] = ExamTest.objects.filter(is_delete=False).count() ret['consumer1_count'] = q1.count()
ret['question_count'] = Question.objects.filter(is_delete=False).count()
q2 = Consumer.objects.filter(is_delete=False).exclude(create_admin=None)
q2 = q2.filter(create_time__gte = request.query_params.get('datestart')) if request.query_params.get('datestart', None) else q2
ret['consumer2_count'] = q2.count()
q3 = ExamTest.objects.filter(is_delete=False)
q3 = q3.filter(create_time__gte = request.query_params.get('datestart')) if request.query_params.get('datestart', None) else q3
ret['test_count'] = q3.count()
q4 = ExamTest.objects.filter(is_delete=False)
q4 = q4.filter(create_time__gte = request.query_params.get('datestart')) if request.query_params.get('datestart', None) else q4
ret['question_count'] = q4.count()
return Response(ret) return Response(ret)
class Admindata1(APIView): class Admindata1(APIView):