forked from stopcovid19-okayama/covid19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataTable.vue
201 lines (193 loc) · 4.88 KB
/
DataTable.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
<data-view :title="title" :title-id="titleId" :date="date">
<template v-slot:button>
<span />
</template>
<v-data-table
:ref="'displayedTable'"
:headers="chartData.headers"
:items="chartData.datasets"
:height="240"
fixed-header
:mobile-breakpoint="0"
:custom-sort="customSort"
:footer-props="{
'items-per-page-options': [15, 30, 50, 100, 200, 300, -1],
'items-per-page-text': $t('1ページ当たり')
}"
class="cardTable"
>
<template v-slot:body="{ items }">
<tbody>
<tr v-for="item in items" :key="item.text">
<th class="text-start" scope="row">{{ item['公表日'] }}</th>
<td class="text-start">{{ item['居住地'] }}</td>
<td class="text-start">{{ item['年代'] }}</td>
<td class="text-start">{{ item['性別'] }}</td>
<td class="text-center">{{ item['退院'] }}</td>
</tr>
</tbody>
</template>
<template slot="footer.page-text" slot-scope="props">
{{
$t('{itemsLength} 項目中 {pageStart} - {pageStop} ', {
itemsLength: props.itemsLength,
pageStart: props.pageStart,
pageStop: props.pageStop
})
}}
</template>
</v-data-table>
<template v-slot:additionalDescription>
<ul class="ListStyleNone">
<li>
{{ $t('※退院は、保健所から報告があり、確認ができているものを反映') }}
</li>
<li>
{{ $t('※死亡退院を含む') }}
</li>
</ul>
</template>
<template v-slot:infoPanel>
<data-view-basic-info-panel
:l-text="info.lText"
:s-text="info.sText"
:unit="info.unit"
/>
</template>
<template v-slot:footer>
<open-data-link :url="url" />
</template>
</data-view>
</template>
<style lang="scss">
.cardTable {
&.v-data-table {
th {
padding: 8px 10px;
height: auto;
border-bottom: 1px solid $gray-4;
color: $gray-2;
@include font-size(12);
&.text-center {
text-align: center;
}
}
tbody {
tr {
color: $gray-1;
th {
font-weight: normal;
}
td {
padding: 8px 10px;
height: auto;
@include font-size(12);
&.text-center {
text-align: center;
}
}
&:nth-child(odd) {
th,
td {
background: rgba($gray-4, 0.3);
}
}
}
}
.v-select {
margin-left: 10px;
}
&:focus {
outline: dotted $gray-3 1px;
}
}
.v-data-table__wrapper {
box-shadow: 0 -20px 12px -12px #0003 inset;
}
.v-data-footer {
@include font-size(12);
&__pagination {
margin-left: 0;
margin-right: 5px;
}
}
.v-data-footer__select .v-select__selections .v-select__selection--comma {
font-size: 1.2rem;
}
}
.v-menu__content {
width: 60px;
.v-list-item {
padding: 0 8px;
}
}
.v-list-item__title {
font-size: 1.5rem;
}
</style>
<script lang="ts">
import Vue from 'vue'
import DataView from '@/components/DataView.vue'
import DataViewBasicInfoPanel from '@/components/DataViewBasicInfoPanel.vue'
import OpenDataLink from '@/components/OpenDataLink.vue'
export default Vue.extend({
components: { DataView, DataViewBasicInfoPanel, OpenDataLink },
props: {
title: {
type: String,
default: ''
},
titleId: {
type: String,
default: ''
},
chartData: {
type: Object,
default: () => {}
},
date: {
type: String,
default: ''
},
info: {
type: Object,
default: () => {}
},
url: {
type: String,
default: ''
},
customSort: {
type: Function,
default(items: Object[], index: string[], isDesc: boolean[]) {
items.sort((a: any, b: any) => {
let comparison = 0
if (String(a[index[0]]) < String(b[index[0]])) {
comparison = -1
} else if (String(b[index[0]]) < String(a[index[0]])) {
comparison = 1
}
// a と b が等しい場合は上記のif文を両方とも通過するので 0 のままとなる
// 降順指定の場合は符号を反転
if (comparison !== 0) {
comparison = isDesc[0] ? comparison * -1 : comparison
}
return comparison
})
return items
}
}
},
mounted() {
const vTables = this.$refs.displayedTable as Vue
const vTableElement = vTables.$el
const tables = vTableElement.querySelectorAll('table')
// NodeListをIE11でforEachするためのワークアラウンド
const nodes = Array.prototype.slice.call(tables, 0)
nodes.forEach((table: HTMLElement) => {
table.setAttribute('tabindex', '0')
})
}
})
</script>