1+ <template >
2+ <div class =" app-container" >
3+ <div class =" filter-container" >
4+ <el-input class =" filter-item"
5+ v-model =" host"
6+ :placeholder =" $t('dashboard.hostPlaceholder')"
7+ clearable
8+ @keyup.enter.native =" queryData" >
9+ </el-input >
10+ <span class =" filter-item" >
11+ <el-date-picker v-model =" dateRange"
12+ type =" daterange"
13+ format =" yyyy/MM/dd"
14+ range-separator =" -"
15+ :picker-options =" pickerOptions"
16+ :start-placeholder =" $t('dashboard.startDate')"
17+ :end-placeholder =" $t('dashboard.endDate')" >
18+ </el-date-picker >
19+ </span >
20+ <a class =" filter-name" >{{ $t('dashboard.mergeDate') }}</a >
21+ <el-switch class =" filter-item"
22+ v-model =" mergeDate" />
23+ <a class =" filter-name" >{{ $t('dashboard.mergeDomain') }}</a >
24+ <el-switch class =" filter-item"
25+ v-model =" mergeDomain" />
26+ <a class =" filter-name" >{{ $t('dashboard.displayBySecond') }}</a >
27+ <el-switch class =" filter-item"
28+ v-model =" displayBySecond" />
29+ </div >
30+ <!-- table -->
31+ <el-table :data =" tableData"
32+ border
33+ :default-sort =" sort"
34+ @sort-change =" sortChangeHandler"
35+ style =" width : 100% " >
36+ <el-table-column prop =" date"
37+ :label =" $t('item.date')"
38+ min-width =" 100px"
39+ align =" center"
40+ :formatter =" dateFormatter"
41+ sortable =" custom"
42+ v-if =" !mergeDate" />
43+ <el-table-column prop =" host"
44+ :label =" $t('item.host')"
45+ min-width =" 170px"
46+ sortable =" custom"
47+ align =" center" />
48+ <el-table-column prop =" focus"
49+ :label =" $t('item.focus')"
50+ min-width =" 130px"
51+ sortable =" custom"
52+ align =" center"
53+ :formatter =" row => periodFormatter(row.focus)" />
54+ <el-table-column prop =" total"
55+ :label =" $t('item.total')"
56+ min-width =" 130px"
57+ sortable =" custom"
58+ align =" center"
59+ :formatter =" row => periodFormatter(row.total)" />
60+ <el-table-column prop =" time"
61+ :label =" $t('item.time')"
62+ min-width =" 80px"
63+ sortable =" custom"
64+ align =" center" />
65+ </el-table >
66+ <div class =" pagination-container" >
67+ <el-pagination @size-change =" queryData"
68+ @current-change =" queryData"
69+ :current-page.sync =" page.num"
70+ :page-sizes =" [10, 20, 50]"
71+ :page-size.sync =" page.size"
72+ layout =" total, sizes, prev, pager, next, jumper"
73+ :total =" page.total" >
74+ </el-pagination >
75+ </div >
76+ </div >
77+ </template >
78+ <script >
79+ import database , { QueryParam } from ' ../database'
80+ import { formatPeriodCommon } from ' ../util/time'
81+ const ELEMENT_SORT_2_DB = {
82+ descending: QueryParam .DESC ,
83+ ascending: QueryParam .ASC
84+ }
85+ export default {
86+ name: ' Dashboard' ,
87+ data () {
88+ return {
89+ host: ' ' ,
90+ mergeDate: false ,
91+ mergeDomain: true ,
92+ displayBySecond: false ,
93+ dateRange: [],
94+ sort: {
95+ prop: ' focus' ,
96+ order: ' descending'
97+ },
98+ page: {
99+ size: 10 ,
100+ num: 1 ,
101+ total: 0
102+ },
103+ tableData: [],
104+ pickerOptions: {
105+ disabledDate : date => date > new Date (),
106+ shortcuts: [
107+ {
108+ text: this .$t (' dashboard.latestWeek' ),
109+ onClick (picker ) {
110+ const end = new Date ()
111+ const start = new Date ()
112+ start .setTime (end .getTime () - 3600 * 1000 * 24 * 7 )
113+ picker .$emit (' pick' , [start, end])
114+ }
115+ }, {
116+ text: this .$t (' dashboard.latest30Days' ),
117+ onClick (picker ) {
118+ const end = new Date ()
119+ const start = new Date ()
120+ start .setTime (end .getTime () - 3600 * 1000 * 24 * 30 )
121+ picker .$emit (' pick' , [start, end])
122+ }
123+ }
124+ ]
125+ }
126+ }
127+ },
128+ watch: {
129+ mergeDate () {
130+ this .queryData ()
131+ },
132+ mergeDomain () {
133+ this .queryData ()
134+ },
135+ dateRange () {
136+ this .queryData ()
137+ }
138+ },
139+ created () {
140+ document .title = this .$t (' dashboard.title' )
141+ database .refresh (() => this .queryData ())
142+ },
143+ methods: {
144+ queryData () {
145+ const param = {
146+ host: this .host ,
147+ date: this .dateRange ,
148+ mergeDomain: this .mergeDomain ,
149+ mergeDate: this .mergeDate ,
150+ sort: this .sort .prop ,
151+ sortOrder: ELEMENT_SORT_2_DB [this .sort .order ]
152+ }
153+ const page = {
154+ pageSize: this .page .size ,
155+ pageNum: this .page .num
156+ }
157+ const { list , total } = database .selectByPage (param, page)
158+ this .tableData = list
159+ this .page .total = total
160+ },
161+ dateFormatter ({ date }) {
162+ if (! date) return ' -'
163+ return date .substring (0 , 4 ) + ' /' + date .substring (4 , 6 ) + ' /' + date .substring (6 , 8 )
164+ },
165+ periodFormatter (val ) {
166+ return val === undefined ? ' -' : this .displayBySecond ? (Math .floor (val / 1000 ) + ' s' ) : formatPeriodCommon (val)
167+ },
168+ sortChangeHandler ({ prop, order }) {
169+ this .sort .prop = prop
170+ this .sort .order = order
171+ this .queryData ()
172+ }
173+ }
174+ }
175+ </script >
176+ <style scoped>
177+ .app-container {
178+ width : 70% ;
179+ height : 100% ;
180+ margin : auto ;
181+ padding-top : 35px ;
182+ }
183+
184+ .filter-container {
185+ padding-bottom : 10px ;
186+ }
187+
188+ .filter-item {
189+ display : inline-block ;
190+ vertical-align : middle ;
191+ margin-bottom : 10px ;
192+ padding-right : 20px ;
193+ }
194+ .filter-name {
195+ color : #909399 ;
196+ font-weight : bold ;
197+ font-size : 14px ;
198+ }
199+ .filter-item.el-input {
200+ width : 175px ;
201+ }
202+ .pagination-container {
203+ width : 100% ;
204+ text-align : center ;
205+ margin-top : 23px ;
206+ }
207+ </style >
208+ <style >
209+ .el-input__suffix {
210+ right : 30px !important ;
211+ }
212+ </style >
0 commit comments