Skip to content

Commit c48a7d2

Browse files
committed
add activation code flow
1 parent 1e03270 commit c48a7d2

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

prod/coms/wa-user.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ export class WAUser extends LitElement {
3838
width: 40px;
3939
margin-left: -5px;
4040
display: inline-block;
41+
transition: color 0.3s ease; /* 添加颜色过渡效果 */
4142
}
43+
44+
#msg.loading {
45+
color: #777; /* 加载时的灰色 */
46+
}
47+
4248
.user-info-panel {
4349
position: fixed;
4450
top: 50px;
@@ -135,6 +141,7 @@ export class WAUser extends LitElement {
135141
userInfo: { type: Object },
136142
isPopupOpen: { type: Boolean },
137143
registrationCode: { type: String },
144+
isLoading: { type: Boolean }, // 新增加载状态属性
138145
};
139146

140147
constructor() {
@@ -146,6 +153,7 @@ export class WAUser extends LitElement {
146153
};
147154
this.isPopupOpen = false;
148155
this.registrationCode = "";
156+
this.isLoading = true; // 初始化为加载状态
149157
}
150158

151159
firstUpdated() {
@@ -159,8 +167,9 @@ export class WAUser extends LitElement {
159167
email: window.user.email,
160168
role: window.user.role,
161169
};
170+
this.isLoading = false; // 加载完成,更新状态
162171
this.requestUpdate();
163-
console.log("userInfo:", this.userInfo);
172+
//console.log("userInfo:", this.userInfo);
164173
clearInterval(intervalId);
165174
}
166175
}, 250);
@@ -187,6 +196,29 @@ export class WAUser extends LitElement {
187196

188197
activateRegistration() {
189198
console.log(`註冊碼: ${this.registrationCode}`);
199+
var requestData = JSON.parse(JSON.stringify(this.userInfo));
200+
requestData.activationCode = this.registrationCode;
201+
// 使用 fetch API 發送 POST 請求
202+
fetch("https://chat.nodered.vip/api/activation", {
203+
method: "POST",
204+
headers: {
205+
"Content-Type": "application/json",
206+
},
207+
body: JSON.stringify(requestData),
208+
})
209+
.then((response) => {
210+
// 檢查回應是否成功
211+
if (!response.ok) {
212+
throw new Error("Network response was not ok");
213+
}
214+
return response.json();
215+
})
216+
.then((data) => {
217+
console.log("data:", data);
218+
})
219+
.catch((error) => {
220+
console.log("error:", error);
221+
});
190222
// 在这里添加激活逻辑
191223
this.closeRegistrationPopup();
192224
}
@@ -205,7 +237,7 @@ export class WAUser extends LitElement {
205237
d="M480-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM160-160v-112q0-34 17.5-62.5T224-378q62-31 126-46.5T480-440q66 0 130 15.5T736-378q29 15 46.5 43.5T800-272v112H160Z"
206238
/>
207239
</svg>
208-
<span id="msg"> 帳號</span>
240+
<span id="msg" class="${this.isLoading ? "loading" : ""}">帳號</span>
209241
</button>
210242
211243
<div class="user-info-panel ${this.isOpen ? "open" : ""}">

0 commit comments

Comments
 (0)