home.vue 4.1 KB
Newer Older
M
maguohua 已提交
1
<template>
M
maguohua 已提交
2
    <div>
M
maguohua 已提交
3
        <head-top></head-top>
M
maguohua 已提交
4
		<section class="data_section">
M
maguohua 已提交
5 6 7 8 9 10
			<header class="section_title">数据统计</header>
			<el-row :gutter="20" style="margin-bottom: 10px;">
                <el-col :span="6"><div class="data_list today_head"><span class="data_num head">当日数据:</span></div></el-col>
				<el-col :span="6"><div class="data_list"><span class="data_num">{{apiCount}}</span> API请求量</div></el-col>
				<el-col :span="6"><div class="data_list"><span class="data_num">{{userCount}}</span> 新增用户</div></el-col>
				<el-col :span="6"><div class="data_list"><span class="data_num">{{orderCount}}</span> 新增订单</div></el-col>
M
maguohua 已提交
11
			</el-row>
M
maguohua 已提交
12 13 14 15 16 17
            <el-row :gutter="20">
                <el-col :span="6"><div class="data_list all_head"><span class="data_num head">总数据:</span></div></el-col>
                <el-col :span="6"><div class="data_list"><span class="data_num">{{allApiCount}}</span> API请求量</div></el-col>
                <el-col :span="6"><div class="data_list"><span class="data_num">{{allUserCount}}</span> 注册用户</div></el-col>
                <el-col :span="6"><div class="data_list"><span class="data_num">{{allOrderCount}}</span> 订单</div></el-col>
            </el-row>
M
maguohua 已提交
18
		</section>
M
maguohua 已提交
19
		<tendency :sevenDate='sevenDate' :sevenDay='sevenDay'></tendency>
M
maguohua 已提交
20
    </div>
M
maguohua 已提交
21 22 23
</template>

<script>
M
maguohua 已提交
24
	import headTop from '../components/headTop'
M
maguohua 已提交
25 26
	import tendency from '../components/tendency' 
	import dtime from 'time-formater'
M
maguohua 已提交
27
	import {apiCount, userCount, orderCount, apiAllCount, getUserCount, getOrderCount} from '@/api/getData'
M
maguohua 已提交
28
    export default {
M
maguohua 已提交
29 30 31 32 33
    	data(){
    		return {
    			apiCount: null,
    			userCount: null,
    			orderCount: null,
M
maguohua 已提交
34 35 36
                allApiCount: null,
                allUserCount: null,
                allOrderCount: null,
M
maguohua 已提交
37 38 39 40
    			sevenDay: [],
    			sevenDate: [[],[],[]],
    		}
    	},
M
maguohua 已提交
41 42
    	components: {
    		headTop,
M
maguohua 已提交
43 44 45 46 47 48 49 50 51
    		tendency,
    	},
    	mounted(){
    		this.initData();
    		for (let i = 6; i > -1; i--) {
    			const date = dtime(new Date().getTime() - 86400000*i).format('YYYY-MM-DD')
    			this.sevenDay.push(date)
    		}
    		this.getSevenData();
M
maguohua 已提交
52
    	},
M
maguohua 已提交
53 54 55
    	methods: {
    		async initData(){
    			const today = dtime().format('YYYY-MM-DD')
M
maguohua 已提交
56
    			Promise.all([apiCount(today), userCount(today), orderCount(today), apiAllCount(), getUserCount(), getOrderCount()])
M
maguohua 已提交
57 58 59 60
    			.then(res => {
    				this.apiCount = res[0].count;
    				this.userCount = res[1].count;
    				this.orderCount = res[2].count;
M
maguohua 已提交
61 62 63
                    this.allApiCount = res[3].count;
                    this.allUserCount = res[4].count;
                    this.allOrderCount = res[5].count;
M
maguohua 已提交
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
    			}).catch(err => {
    				console.log(err)
    			})
    		},
    		async getSevenData(){
    			const apiArr = [[],[],[]];
    			this.sevenDay.forEach(item => {
    				apiArr[0].push(apiCount(item))
    				apiArr[1].push(userCount(item))
    				apiArr[2].push(orderCount(item))
    			})
    			const promiseArr = [...apiArr[0], ...apiArr[1], ...apiArr[2]]
    			Promise.all(promiseArr).then(res => {
    				const resArr = [[],[],[]];
					res.forEach((item, index) => {
						if (item.status == 1) {
							resArr[Math.floor(index/7)].push(item.count)
						}
					})
					this.sevenDate = resArr;
    			}).catch(err => {
    				console.log(err)
    			})
    		}
    	}
M
maguohua 已提交
89 90 91
    }
</script>

M
maguohua 已提交
92 93
<style lang="less">
	@import '../style/mixin';
M
maguohua 已提交
94 95
	.data_section{
		padding: 20px;
M
maguohua 已提交
96
		margin-bottom: 40px;
M
maguohua 已提交
97 98 99 100 101 102 103 104
		.section_title{
			text-align: center;
			font-size: 30px;
			margin-bottom: 10px;
		}
		.data_list{
			text-align: center;
			font-size: 14px;
M
maguohua 已提交
105
			color: #666;
M
maguohua 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
            border-radius: 6px;
            background: #E5E9F2;
            .data_num{
                color: #333;
                font-size: 26px;

            }
            .head{
                border-radius: 6px;
                font-size: 24px;
                padding: 0 10px;
                color: #fff;
            }
        }
        .today_head{
            background: #13CE66;
        }
        .all_head{
            background: #20A0FF;
        }
M
maguohua 已提交
126
	}
M
maguohua 已提交
127
</style>