search.vue
5.35 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<template>
<div class="container">
<div class="center">
<img
src="../../public/lolinfologo.png"
alt="logo"
width="300,"
height="300"
/>
</div>
<div class="center2">
<form @submit.prevent="searchUser">
<input type="text" v-model="search" placeholder="Search" autofocus />
<b-button type="submit" variant="primary">
Search
</b-button>
</form>
</div>
<div class="user_info" v-if="user != null">
<img :src="user.c_imgtier" class="tier_emb" />
<div>
<h1>{{ user.c_summoner }}</h1>
<h2>
{{ user.c_tier + ' ' + user.c_rank + ' LP' + user.c_leaguePoint }}
</h2>
<div class="record">
{{ user.c_wins + user.c_losses }}전 {{ user.c_wins }}승
{{ user.c_losses }}패(승률: {{ winRate() }}%)
</div>
</div>
</div>
<div class="match" v-if="spectator != null && spectator.flag">
<h1>실시간 경기</h1>
<table>
<tr v-for="i in [0, 1, 2, 3, 4]" :key="i">
<td>
<img
:src="spectator.spectator.selectedChamp_image[i]"
class="champ"
/>
</td>
<td>
<img :src="spectator.spectator.spell_image[i * 2]" class="spell" />
<img
:src="spectator.spectator.spell_image[i * 2 + 1]"
class="spell"
/>
</td>
<td>{{ spectator.spectator.summonerName[i] }}</td>
<td v-if="i == 0" class="vs" rowspan="5">vs</td>
<td>
<img
:src="spectator.spectator.selectedChamp_image[i + 5]"
class="champ"
/>
</td>
<td>
<img
:src="spectator.spectator.spell_image[i * 2 + 10]"
class="spell"
/>
<img
:src="spectator.spectator.spell_image[i * 2 + 11]"
class="spell"
/>
</td>
<td>{{ spectator.spectator.summonerName[i + 5] }}</td>
</tr>
</table>
</div>
<h1 class="rec_h">대전기록</h1>
<div class="match" v-for="(m, j) in matches" :key="j">
<table>
<tr v-for="i in [0, 1, 2, 3, 4]" :key="i">
<td>
<img :src="m.selectedChamp_image[i]" class="champ" />
</td>
<td>
<img :src="m.spell_image[i * 2]" class="spell" />
<img :src="m.spell_image[i * 2 + 1]" class="spell" />
</td>
<td>{{ m.summonerName[i] }}</td>
<td>{{ m.kda[i].k }} / {{ m.kda[i].d }} / {{ m.kda[i].a }}</td>
<td v-if="i == 0" class="vs" rowspan="5">vs</td>
<td>
<img :src="m.selectedChamp_image[i + 5]" class="champ" />
</td>
<td>
<img :src="m.spell_image[i * 2 + 10]" class="spell" />
<img :src="m.spell_image[i * 2 + 11]" class="spell" />
</td>
<td>{{ m.summonerName[i + 5] }}</td>
<td>
{{ m.kda[i + 5].k }} / {{ m.kda[i + 5].d }} / {{ m.kda[i + 5].a }}
</td>
</tr>
</table>
</div>
<!--
<div id="nav">
<ul class="lot">
실시간 경기
<li
v-for="(item, index) in this.$store.getters.lotationChampList"
:key="index"
>
<img :src="item" alt="챔피언" width="50," height="50" />
</li>
</ul>
</div>-->
</div>
</template>
<script>
import { mainData, searchUser, spectatorData, matchData } from '../api/index';
export default {
data() {
return {
search: '',
user: null,
spectator: null,
matches: [],
};
},
watch: {
'$route.params.id': function() {
this.fetchdata();
},
},
created() {
this.fetchdata();
},
methods: {
async searchUser() {
this.$router.push('/search/' + this.search);
},
async fetchdata() {
try {
const response = await mainData();
this.$store.commit('setlotationChamp', response.data.c_rotation);
this.$store.commit('setbegChamp', response.data.c_rotation_newbie);
console.log(response.data);
} catch (error) {
console.log('에러');
}
try {
const userId = this.$route.params.id;
const response = await searchUser(userId);
console.log(response.data);
if (response.status == 200) {
this.user = response.data;
const response2 = await spectatorData(userId);
console.log(response2.data);
this.spectator = response2.data;
const response3 = await matchData(userId);
console.log(response3.data);
this.matches = response3.data.match;
this.$store.commit('setSpecTator', response2.data);
this.$store.commit('setMatchData', response3.data);
}
} catch (error) {
console.log('에러');
}
},
winRate() {
return Math.floor(
(this.user.c_wins / (this.user.c_wins + this.user.c_losses)) * 100,
);
},
},
};
</script>
<style scoped>
.container {
width: 100%;
margin: 0;
padding: 0;
max-width: none;
}
.center {
width: 100vw;
height: 50vh;
font-weight: bolder;
display: flex;
align-items: center;
justify-content: space-around;
}
.center2 {
width: 100vw;
height: 2vh;
display: flex;
align-items: center;
justify-content: space-around;
}
.lot {
float: left;
}
.tier_emb {
width: 200px;
height: 200px;
}
.user_info {
width: 100%;
display: flex;
justify-content: center;
}
.user_info h1 {
font-size: 32px;
font-weight: bold;
}
.user_info h2 {
font-size: 24px;
font-weight: bold;
}
.match {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
margin-bottom: 64px;
}
.match .champ {
width: 64px;
height: 64px;
}
.match .spell {
width: 30px;
height: 30px;
display: block;
}
.match .spell:nth-child(1) {
margin-bottom: 4px;
}
.vs {
font-size: 48px;
width: 300px;
text-align: center;
}
.rec_h {
text-align: center;
}
</style>