-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteam_match.html
More file actions
440 lines (371 loc) · 14.2 KB
/
Copy pathteam_match.html
File metadata and controls
440 lines (371 loc) · 14.2 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>자동 매치 페이지</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython_stdlib.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
background-color: #f2f2f2;
}
/* HEADER */
.header {
background-color: #ffffff;
height: 50px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
box-shadow: 0 1px 4px rgba(0,0,0,0.1);
position: fixed;
top: 0;
width: 100%;
z-index: 10;
}
.menu-button {
width: 24px;
height: 18px;
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.menu-button div {
background-color: #333;
height: 3px;
border-radius: 2px;
}
.menu {
background-color: white;
width: 100%;
position: fixed;
top: 50px;
left: 0;
z-index: 9;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.menu.show {
max-height: 300px;
}
.menu-item {
padding: 16px;
border-bottom: 1px solid #ddd;
text-decoration: none;
color: black;
display: block;
}
.header-title {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-weight: bold;
font-size: 14px;
}
.header-title a {
text-decoration: none;
color: #000;
}
.container {
max-width: 480px;
margin: 50px auto 0 auto; /* header 높이 고려 */
padding: 20px;
background-color: white;
min-height: calc(100vh - 50px);
box-sizing: border-box;
}
h2 {
text-align: center;
margin-bottom: 30px;
}
label {
display: block;
margin-top: 16px;
font-weight: bold;
}
input[type="text"],
input[type="url"] {
width: 100%;
padding: 10px;
margin-top: 6px;
border-radius: 6px;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
margin-top: 24px;
width: 100%;
padding: 12px;
background-color: #555;
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
}
button:hover {
background-color: #333;
}
#team-result {
padding: 15px;
border-radius: 6px;
background-color: #f9f9f9;
border: 1px solid #ddd;
}
/* 각 팀 카드 박스 */
.box-2 {
width: 100%;
max-width: 500px;
margin: 20px auto;
background-color: #fff;
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
overflow: hidden;
cursor: pointer;
transition: transform 0.2s ease;
}
.box-2:hover {
transform: translateY(-5px);
}
/* 이미지 감싸는 wrapper */
.image-wrapper-2 {
position: relative;
width: 100%;
height: 280px;
overflow: hidden;
}
.image-wrapper-2 img {
width: 100%;
height: 100%;
object-fit: cover;
}
/* 이미지 위 팀 이름 (흰 글씨, 중앙 하단) */
.team-title-2 {
position: absolute;
bottom: 16px;
left: 16px;
color: white;
font-size: 24px;
font-weight: bold;
text-shadow: 1px 1px 3px rgba(0,0,0,0.6);
}
/* 태그 컨테이너 */
.tag-container-2 {
padding: 16px;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
/* 개별 태그 */
.tag-2 {
background-color: #007bff;
color: white;
padding: 8px 12px;
border-radius: 20px;
font-size: 14px;
}
</style>
</head>
<body onload="brython()">
<!-- HEADER -->
<div class="header">
<div class="menu-button" id="hamburger">
<div></div>
<div></div>
<div></div>
</div>
<div class="header-title">
<a href="index.html">성격기반 랜덤여행</a>
</div>
</div>
<!-- DROPDOWN MENU -->
<div class="menu" id="menu">
<!-- 여기에 Brython이 동적으로 삽입할 내용이 들어감 -->
</div>
<!-- FORM -->
<div class="container">
<h2>내 성격과 유사한 팀 찾기</h2>
<button id="match-button">랜덤 팀 찾기</button>
<div id="team-result" style="margin-top:20px; display:none;"></div>
<div class="scroll-container-2" id="team-list-container">
<!-- 여기에 Brython으로 팀 박스들을 동적으로 삽입 -->
</div>
</div>
<script type="text/python">
from browser import window, alert, document, html
import random
import json
def setup_menu():
menu = document["menu"]
menu.clear()
user_info_str = window.sessionStorage.getItem("userInfo")
if user_info_str is None:
# 로그인 안 된 경우
menu <= html.A("회원가입", href="signup.html", Class="menu-item")
menu <= html.A("로그인", href="login.html", Class="menu-item")
else:
try:
user_info = json.loads(user_info_str)
name = user_info.get("name", "회원")
# 인사말 (텍스트만, 클릭 안 됨)
greet = html.SPAN(f"{name}님 반가워요", Class="menu-item")
greet.style.cursor = "default"
greet.style.marginRight = "10px"
menu <= greet
# 로그아웃 버튼
logout = html.A("로그아웃", href="#", Class="menu-item")
logout.bind("click", on_logout)
menu <= logout
except:
# 파싱 실패 시 강제 로그아웃
on_logout(None)
def on_logout(ev):
if ev:
ev.preventDefault()
window.sessionStorage.removeItem("userInfo")
window.location.href = "index.html" # 메인 페이지로 이동
def toggle_menu(event):
menu = document["menu"]
menu.classList.toggle("show")
def get_user_info():
user_info_str = window.sessionStorage.getItem("userInfo")
if user_info_str:
try:
return json.loads(user_info_str)
except:
return {}
return {}
def get_team_list():
try:
cookies = window.document.cookie.split("; ")
for cookie in cookies:
if cookie.startswith("team-list="):
value = cookie[len("team-list="):]
decoded = window.decodeURIComponent(value)
return json.loads(decoded)
except:
pass
return []
def save_team_list(team_list):
try:
new_cookie = json.dumps(team_list)
window.document.cookie = f"team-list={window.encodeURIComponent(new_cookie)}; path=/;"
except Exception as e:
console.log(f"팀 리스트 저장 실패: {e}")
# MBTI 궁합 정보 (완전한 매핑)
mbti_compatibility = {
"ENFP": {"최고": ["INFJ", "INTJ"], "잘 맞는": ["INFP", "ENFJ", "ENTP", "ENFP"]},
"INFP": {"최고": ["ENFJ", "ENTJ"], "잘 맞는": ["INFJ", "ENFP", "INFP", "ISFP"]},
"ENFJ": {"최고": ["INFP", "ISFP"], "잘 맞는": ["ENFP", "INFJ", "ENFJ", "ESFJ"]},
"INFJ": {"최고": ["ENFP", "ENTP"], "잘 맞는": ["INFP", "ENFJ", "INFJ", "INTJ"]},
"ENTP": {"최고": ["INFJ", "INTJ"], "잘 맞는": ["ENFP", "INTP", "ENTP", "ENTJ"]},
"INTP": {"최고": ["ENTJ", "ESTJ"], "잘 맞는": ["ENTP", "INTJ", "INTP", "ISTP"]},
"ENTJ": {"최고": ["INFP", "INTP"], "잘 맞는": ["ENTP", "INTJ", "ENTJ", "ESTJ"]},
"INTJ": {"최고": ["ENFP", "ENTP"], "잘 맞는": ["INFJ", "ENTJ", "INTJ", "ISTJ"]},
"ESFP": {"최고": ["ISFJ", "ISTJ"], "잘 맞는": ["ESTP", "ESFJ", "ESFP", "ISFP"]},
"ISFP": {"최고": ["ENFJ", "ESFJ"], "잘 맞는": ["INFP", "ESFP", "ISFP", "ISTP"]},
"ESFJ": {"최고": ["ISFP", "ISTP"], "잘 맞는": ["ENFJ", "ESFP", "ESFJ", "ISFJ"]},
"ISFJ": {"최고": ["ESFP", "ESTP"], "잘 맞는": ["ESFJ", "ISFP", "ISFJ", "ISTJ"]},
"ESTP": {"최고": ["ISFJ", "ISTJ"], "잘 맞는": ["ESFP", "ESTP", "ISTP", "ESTP"]},
"ISTP": {"최고": ["ESFJ", "ESTJ"], "잘 맞는": ["ESTP", "ISFP", "ISTP", "INTP"]},
"ESTJ": {"최고": ["INTP", "ISTP"], "잘 맞는": ["ENTJ", "ESTP", "ESTJ", "ISTJ"]},
"ISTJ": {"최고": ["ESFP", "ESTP"], "잘 맞는": ["ESTJ", "ISFJ", "ISTJ", "INTJ"]}
}
def is_compatible(user_mbti, team_mbti_list):
if user_mbti not in mbti_compatibility:
return False
if not team_mbti_list:
return True
best = mbti_compatibility[user_mbti]["최고"]
good = mbti_compatibility[user_mbti]["잘 맞는"]
# 모든 팀 멤버와 궁합이 맞아야 함 (최고 또는 잘 맞는 관계)
for mbti in team_mbti_list:
if mbti not in best and mbti not in good:
return False
return True
def display_team_result(team_info):
result_div = document["team-result"]
load_team_list(team_info)
def match_user_to_team(event):
user = get_user_info()
user_mbti = user['mbti'] if user['mbti'] is not None else "null"
window.console.log(user_mbti);
# 사용자 정보 확인
if not user:
alert("로그인이 필요합니다.")
return
if not user_mbti:
alert("사용자 MBTI 정보가 없습니다. 프로필을 완성해주세요.")
return
team_list = get_team_list()
if not team_list:
alert("현재 생성된 팀이 없습니다.")
return
compatible_teams = []
for team in team_list:
members = team.get("userInfo", {})
# 각 멤버가 딕셔너리인지 확인하고 MBTI 수집
member_mbtis = []
for m in members.values():
if isinstance(m, dict):
mbti = m.get("mbti")
if mbti:
member_mbtis.append(mbti)
# MBTI 궁합이 맞는지 검사
if is_compatible(user_mbti, member_mbtis):
compatible_teams.append(team)
window.console.log(compatible_teams)
if not compatible_teams:
alert("현재 궁합이 맞는 팀이 없습니다. 나중에 다시 시도해보세요.")
return
# 랜덤으로 팀 선택
selected_team = random.choice(compatible_teams)
window.console.log(selected_team)
# 결과 표시
display_team_result(selected_team)
def load_team_list(team):
team_list = [team]
window.console.log(team_list);
container = document["team-list-container"]
container.clear()
for team in team_list:
box = html.DIV(Class="box-2")
# ✅ 클릭 핸들러 생성
def make_click_handler(team_info):
def on_click(ev):
kakao_link = team_info.get("userInfo", {}).get("kakaoProfileLink", "")
if kakao_link:
window.open(kakao_link)
else:
window.alert("카카오 링크가 없습니다.")
return on_click
box.bind("click", make_click_handler(team))
# ✅ 이미지 영역
image_wrapper = html.DIV(Class="image-wrapper-2")
if team.get("imgSrc", ""):
image_tag = html.IMG(src=team["imgSrc"])
image_wrapper <= image_tag
# ✅ 팀 제목 (이미지 안쪽에 흰색으로 표시)
title = html.DIV(team["teamName"], Class="team-title-2")
image_wrapper <= title
box <= image_wrapper
# ✅ 태그 표시
tag_container = html.DIV(Class="tag-container-2")
for tag in team.get("tag", []):
tag_div = html.DIV(f"#{tag}", Class="tag-2")
tag_container <= tag_div
box <= tag_container
# ✅ 삽입
container <= box
document["hamburger"].bind("click", toggle_menu)
document["match-button"].bind("click", match_user_to_team)
setup_menu()
</script>
</body>
</html>