Skip to content

Commit e98b163

Browse files
committed
fix(view): dashboard
1 parent e5b1955 commit e98b163

File tree

3 files changed

+178
-11
lines changed

3 files changed

+178
-11
lines changed

admin/src/store/getters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const getters = {
33
device: state => state.app.device,
44
token: state => state.user.token,
55
avatar: state => state.user.avatar,
6-
name: state => state.user.name
6+
name: state => state.user.name,
7+
roles: state => state.user.roles,
8+
// permission_routers: state => state.user.routers,
9+
addRouters: state => state.user.addRouters
710
}
811
export default getters

admin/src/store/modules/user.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ const mutations = {
1616
},
1717
SET_AVATAR: (state, avatar) => {
1818
state.avatar = avatar
19+
},
20+
SET_ROLES: (state, roles) => {
21+
state.roles = roles
22+
},
23+
SET_ROUTERS: (state, routers) => {
24+
state.addRouters = routers
1925
}
2026
}
2127

admin/src/views/dashboard/index.vue

Lines changed: 168 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,188 @@
11
<template>
22
<div class="dashboard-container">
3-
<div class="dashboard-text">name: {{ name }}</div>
3+
4+
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
5+
<legend>服务器信息</legend>
6+
</fieldset>
7+
<el-card class="box-card">
8+
<el-collapse v-model="activeNames" @change="handleChange">
9+
<el-collapse-item title="服务器配置" name="1">
10+
<el-table :data="serve" style="width: 100%">
11+
<el-table-column prop="name" label="名称" width="" />
12+
<el-table-column prop="value" label="数值" width="" />
13+
</el-table>
14+
</el-collapse-item>
15+
</el-collapse>
16+
</el-card>
17+
18+
<el-card class="box-card">
19+
<el-collapse v-model="activeNames" @change="handleChange">
20+
<el-collapse-item title="服务器配置" name="2">
21+
<el-table :data="php" style="width: 100%">
22+
<el-table-column prop="name" label="名称" width="" />
23+
<el-table-column prop="value" label="数值" width="" />
24+
</el-table>
25+
</el-collapse-item>
26+
</el-collapse>
27+
</el-card>
28+
29+
<div class="clearfix" />
30+
<fieldset class="clearfix layui-elem-field layui-field-title" style="margin-top: 20px;">
31+
<legend>管理员信息</legend>
32+
</fieldset>
33+
<el-card class="box-card">
34+
<div class="dashboard-text">name:{{ name }}</div>
35+
<div class="dashboard-text">roles:<span v-for="role in roles" :key="role">{{ role }}</span></div>
36+
</el-card>
37+
<el-card class="box-card">
38+
<div id="chartLine" style="width:100%; height:400px;" />
39+
</el-card>
40+
<div class="clearfix" />
441
</div>
542
</template>
643

744
<script>
845
import { mapGetters } from 'vuex'
46+
import { getList, report } from '../../api/dashboard'
47+
import echarts from 'echarts'
948
1049
export default {
1150
name: 'Dashboard',
51+
data() {
52+
return {
53+
loading: false,
54+
is_serve: true,
55+
is_php: true,
56+
serve: [],
57+
php: [],
58+
activeNames: ['1', '2'],
59+
chartLine: null,
60+
xData: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
61+
}
62+
},
1263
computed: {
1364
...mapGetters([
14-
'name'
65+
'name',
66+
'roles'
1567
])
68+
},
69+
created() {
70+
this.init()
71+
},
72+
mounted() {
73+
// this.drawLineChart()
74+
},
75+
updated() {
76+
// this.drawLineChart()
77+
},
78+
methods: {
79+
init() {
80+
this.loading = true
81+
getList().then(response => {
82+
this.loading = false
83+
this.serve = response.data.serve
84+
this.php = response.data.php
85+
})
86+
report({ section: 7 }).then(res => {
87+
this.xData = res.data.date
88+
this.yData = res.data.success_slide
89+
this.drawLineChart()
90+
}).catch(err => {
91+
console.log(err)
92+
this.drawLineChart()
93+
})
94+
},
95+
closeServe() {
96+
this.is_serve = false
97+
},
98+
closePhp() {
99+
this.is_php = false
100+
},
101+
handleChange(val) {
102+
console.log(val)
103+
},
104+
drawLineChart() {
105+
this.chartLine = echarts.init(document.getElementById('chartLine'))
106+
this.chartLine.setOption({
107+
color: ['#3398DB'],
108+
title: {
109+
text: '登录日志数据'
110+
},
111+
tooltip: {
112+
trigger: 'axis',
113+
axisPointer: { // 坐标轴指示器,坐标轴触发有效
114+
type: 'shadow' // 默认直线,可选 'line'|'shadow'
115+
}
116+
},
117+
legend: {
118+
data: ['登录成功']
119+
},
120+
grid: {
121+
left: '3%',
122+
right: '4%',
123+
bottom: '3%',
124+
containLabel: true
125+
},
126+
xAxis: {
127+
type: 'category',
128+
boundaryGap: false,
129+
data: this.xData,
130+
axisTick: {
131+
alignWithLabel: true
132+
}
133+
},
134+
yAxis: {
135+
type: 'value'
136+
},
137+
series: [
138+
{
139+
barWidth: '60%',
140+
name: '登录成功',
141+
type: 'line', // 'bar','line'
142+
stack: '总量',
143+
data: this.yData,
144+
smooth: true
145+
}
146+
]
147+
})
148+
}
16149
}
17150
}
18151
</script>
19152

20-
<style lang="scss" scoped>
21-
.dashboard {
22-
&-container {
23-
margin: 30px;
153+
<style rel="stylesheet/scss" lang="scss" scoped>
154+
.dashboard {
155+
&-container {
156+
margin: 30px;
157+
}
158+
159+
&-text {
160+
font-size: 30px;
161+
line-height: 46px;
162+
}
24163
}
25-
&-text {
26-
font-size: 30px;
27-
line-height: 46px;
164+
165+
.text {
166+
font-size: 14px;
167+
}
168+
169+
.item {
170+
margin-bottom: 18px;
171+
}
172+
173+
.clearfix:before,
174+
.clearfix:after {
175+
display: table;
176+
content: "";
177+
}
178+
179+
.clearfix:after {
180+
clear: both
181+
}
182+
183+
.box-card {
184+
width: 40%;
185+
float: left;
186+
margin: 0 2%;
28187
}
29-
}
30188
</style>

0 commit comments

Comments
 (0)