@@ -65,37 +65,126 @@ export class WAUser extends LitElement {
65
65
right: 10px;
66
66
cursor: pointer;
67
67
}
68
+
69
+ /* 新增的彈出窗口樣式 */
70
+ .popup-overlay {
71
+ position: fixed;
72
+ top: 0;
73
+ left: 0;
74
+ width: 100%;
75
+ height: 100%;
76
+ background: rgba(0, 0, 0, 0.5);
77
+ display: flex;
78
+ align-items: center;
79
+ justify-content: center;
80
+ z-index: 1001;
81
+ }
82
+ .popup {
83
+ width: 480px;
84
+ height: 80px;
85
+ background: #fff;
86
+ padding: 20px;
87
+ color: #000;
88
+ box-sizing: border-box;
89
+ border-radius: 8px;
90
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
91
+ display: flex;
92
+ align-items: center;
93
+ justify-content: space-between;
94
+ }
95
+ .popup input {
96
+ flex: 1;
97
+ margin-left: 10px;
98
+ padding: 5px;
99
+ font-size: 16px;
100
+ }
101
+ .popup button {
102
+ padding: 5px 10px;
103
+ font-size: 16px;
104
+ cursor: pointer;
105
+ }
106
+
107
+ /* 新增的啟動註冊碼按鈕樣式 */
108
+ .activate-button {
109
+ display: inline-block;
110
+ outline: 0;
111
+ cursor: pointer;
112
+ border: 2px solid #000;
113
+ border-radius: 3px;
114
+ color: #fff;
115
+ background: #000;
116
+ font-size: 16px;
117
+ font-weight: 600;
118
+ line-height: 16px;
119
+ padding: 2px;
120
+ text-align: center;
121
+ transition-duration: 0.15s;
122
+ transition-property: all;
123
+ margin-left: 0px;
124
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
125
+ }
126
+
127
+ .activate-button:hover {
128
+ color: #000;
129
+ background: rgb(255, 218, 87);
130
+ }
68
131
` ;
69
132
70
133
static properties = {
71
134
isOpen : { type : Boolean } ,
72
135
userInfo : { type : Object } ,
136
+ isPopupOpen : { type : Boolean } ,
137
+ registrationCode : { type : String } ,
73
138
} ;
74
139
140
+ constructor ( ) {
141
+ super ( ) ;
142
+ this . userInfo = {
143
+ name : "---" ,
144
+ email : "---" ,
145
+ role : "---" ,
146
+ } ;
147
+ this . isPopupOpen = false ;
148
+ this . registrationCode = "" ;
149
+ }
150
+
75
151
check ( ) {
76
152
this . isOpen = false ;
77
153
if ( window . user ) {
78
154
this . userInfo = {
79
155
name : window . user . name || "匿名" ,
80
156
email : window . user . email || "---" ,
81
- role : window . user . role || ' ---' ,
157
+ role : window . user . role || " ---" ,
82
158
} ;
159
+ this . requestUpdate ( ) ; // 添加這行來觸發重新渲染
83
160
}
84
161
}
85
162
86
- constructor ( ) {
87
- super ( ) ;
88
- this . userInfo = {
89
- name : "---" ,
90
- email : "---" ,
91
- role : "---" ,
92
- } ;
93
- }
94
-
95
163
togglePanel ( ) {
96
164
this . isOpen = ! this . isOpen ;
97
165
}
98
166
167
+ openRegistrationPopup ( ) {
168
+ this . togglePanel ( ) ;
169
+ this . isPopupOpen = true ;
170
+ }
171
+
172
+ closeRegistrationPopup ( ) {
173
+ this . isPopupOpen = false ;
174
+ this . registrationCode = "" ;
175
+ }
176
+
177
+ handleInputChange ( e ) {
178
+ this . registrationCode = e . target . value ;
179
+ this . requestUpdate ( ) ;
180
+ }
181
+
182
+ activateRegistration ( ) {
183
+ console . log ( `註冊碼: ${ this . registrationCode } ` ) ;
184
+ // 在这里添加激活逻辑
185
+ this . closeRegistrationPopup ( ) ;
186
+ }
187
+
99
188
render ( ) {
100
189
return html `
101
190
< button @click ="${ this . togglePanel } ">
@@ -116,9 +205,42 @@ export class WAUser extends LitElement {
116
205
< div class ="user-info-panel ${ this . isOpen ? "open" : "" } ">
117
206
< div class ="close-button " @click ="${ this . togglePanel } "> X</ div >
118
207
< h2 > < span > ${ this . userInfo . role } </ span > </ h2 >
119
- 姓名:${ this . userInfo . name } </ p >
120
- EMail: ${ this . userInfo . email } </ p >
208
+ < p > 姓名:${ this . userInfo . name } </ p >
209
+ < p > EMail: ${ this . userInfo . email } </ p >
210
+ ${ this . userInfo . role === "user"
211
+ ? html `
212
+ < button
213
+ class ="activate-button "
214
+ @click ="${ this . openRegistrationPopup } "
215
+ >
216
+ 啟動註冊碼
217
+ </ button >
218
+ `
219
+ : "" }
121
220
</ div >
221
+
222
+ ${ this . isPopupOpen
223
+ ? html `
224
+ < div class ="popup-overlay ">
225
+ < div class ="popup ">
226
+ < label >
227
+ 請輸入啟動註冊碼:
228
+ < input
229
+ type ="text "
230
+ .value ="${ this . registrationCode } "
231
+ @input ="${ this . handleInputChange } "
232
+ />
233
+ </ label >
234
+ < button
235
+ class ="activate-button "
236
+ @click ="${ this . activateRegistration } "
237
+ >
238
+ 啟動
239
+ </ button >
240
+ </ div >
241
+ </ div >
242
+ `
243
+ : "" }
122
244
` ;
123
245
}
124
246
}
0 commit comments