1
1
<template >
2
2
<div >
3
3
<div >主页</div >
4
+ <div >
5
+ <el-select class =" input" v-model =" timeRange" placeholder =" 请选择" @change =" load()" >
6
+ <el-option
7
+ v-for =" item in options"
8
+ :key =" item.value"
9
+ :label =" item.label"
10
+ :value =" item.value" >
11
+ </el-option >
12
+ </el-select >
13
+ </div >
4
14
<el-card >
5
15
<div id =" line" style =" width :100% ;height : 400px ;" ></div >
6
16
</el-card >
17
+
18
+ <el-table
19
+ :data =" tableData"
20
+ style =" width : 100% " >
21
+ <el-table-column
22
+ prop =" date"
23
+ label =" 日期"
24
+ width =" 180" >
25
+ </el-table-column >
26
+ <el-table-column
27
+ prop =" name"
28
+ label =" 姓名"
29
+ width =" 180" >
30
+ </el-table-column >
31
+ <el-table-column
32
+ prop =" address"
33
+ label =" 地址" >
34
+ </el-table-column >
35
+ </el-table >
7
36
</div >
8
37
</template >
9
38
10
39
<script >
11
40
import * as echarts from ' echarts' ;
12
41
import request from ' @/utils/request' ;
13
- export default {
14
- name: " HomeView" ,
15
- components: {
16
- },
17
- data (){
18
- return {
19
- lineBox: null ,
20
- timeRange: ' week' ,
21
- options: [
22
- {label: ' 最近一周' ,value: ' week' },
23
- {label: ' 最近一个月' ,value: ' month' },
24
- {label: ' 最近两个月' ,value: ' month2' },
25
- {label: ' 最近三个月' ,value: ' month3' },
26
- ]
27
- }
28
- },
29
- // 初始化完后执行
30
- mounted (){
31
- this .load ()
32
- },
33
- methods: {
34
- load (){
35
- if (! this .lineBox0 ){
36
- this .lineBox = echarts .init (document .getElementById (' line' ))// 初始化容器
37
- }
38
- // 从后台获取数据
39
- request .get (' /borrow.lineCharts/' + this ,timeRange).then (res => {
40
- option .xAxis [0 ].data = res .data .borrow
41
- option .series [1 ].data = res .data .return
42
- this .lineBox .setOption (option)// 设置容器属性值
43
- })
44
-
45
- }
46
- }
47
- };
48
-
49
- option = {
42
+ import Cookies from ' js-cookie'
43
+ const option = {
50
44
title: {
51
45
text: ' 借还书'
52
46
},
53
47
tooltip: {
54
48
trigger: ' axis'
55
49
},
56
50
legend: {
57
- data: [' 借书 ' , ' 还书 ' ]
51
+ data: [' 借书数量 ' , ' 还书数量 ' ]
58
52
},
59
53
grid: {
60
54
left: ' 3%' ,
@@ -68,7 +62,7 @@ option = {
68
62
}
69
63
},
70
64
xAxis: {
71
- type: ' 日期 ' ,
65
+ type: ' category ' ,
72
66
boundaryGap: false ,
73
67
data: []
74
68
},
@@ -84,7 +78,7 @@ option = {
84
78
data: []
85
79
},
86
80
{
87
- name: ' 还数数量 ' ,
81
+ name: ' 还书数量 ' ,
88
82
type: ' line' ,
89
83
stack: ' Total' ,
90
84
smooth: true ,
@@ -93,5 +87,65 @@ option = {
93
87
]
94
88
};
95
89
90
+ export default {
91
+ name: " HomeView" ,
92
+ data (){
93
+ return {
94
+ admin: Cookies .get (' admin' ) ? JSON .parse (Cookies .get (' admin' )) : {},
95
+ lineBox: null ,
96
+ timeRange: ' week' ,// 时间范围
97
+ options: [
98
+ {label: ' 最近一周' ,value: ' week' },
99
+ {label: ' 最近一个月' ,value: ' month' },
100
+ {label: ' 最近两个月' ,value: ' month2' },
101
+ {label: ' 最近三个月' ,value: ' month3' },
102
+ ],
103
+ tableData: [{
104
+ date: ' 2016-05-02' ,
105
+ name: ' 王小虎' ,
106
+ address: ' 上海市普陀区金沙江路 1518 弄'
107
+ }, {
108
+ date: ' 2016-05-04' ,
109
+ name: ' 王小虎' ,
110
+ address: ' 上海市普陀区金沙江路 1517 弄'
111
+ }, {
112
+ date: ' 2016-05-01' ,
113
+ name: ' 王小虎' ,
114
+ address: ' 上海市普陀区金沙江路 1519 弄'
115
+ }, {
116
+ date: ' 2016-05-03' ,
117
+ name: ' 王小虎' ,
118
+ address: ' 上海市普陀区金沙江路 1516 弄'
119
+ }]
120
+ }
121
+ },
122
+ // 初始化完后执行
123
+ mounted (){
124
+ this .load ()
125
+ },
126
+ methods: {
127
+ load (){
128
+ if (! this .lineBox ){
129
+ this .lineBox = echarts .init (document .getElementById (' line' ))// 初始化容器
130
+ }
131
+ // 从后台获取数据
132
+ request .get (' /borrow/lineCharts/' + this .timeRange ).then (res => {
133
+ option .xAxis .data = res .data .date
134
+ option .series [0 ].data = res .data .borrow
135
+ option .series [1 ].data = res .data .retur
136
+ this .lineBox .setOption (option)// 设置容器属性值
137
+ })
138
+
139
+ }
140
+ }
141
+ };
142
+
143
+
144
+
96
145
97
146
</script >
147
+ <style >
148
+ .input {
149
+ width : 300px ;
150
+ }
151
+ </style >
0 commit comments