@@ -68,7 +68,8 @@ async function startAlicloud2Login() {
6868 // console.log(`会话将在 ${expireMinutes} 分钟后过期`);
6969 }
7070
71- startStatusCheck ( ) ;
71+ checkQRStatus = checkAlicloud2Status ;
72+ startAliQRStatusCheck ( ) ;
7273 } else {
7374 setQRStatus ( result . error || '生成二维码失败' , 'error' ) ;
7475 document . getElementById ( 'refresh-qr-btn' ) . style . display = 'inline-block' ;
@@ -80,29 +81,14 @@ async function startAlicloud2Login() {
8081 }
8182}
8283
83- // 显示二维码
84- function showQRCode ( qrUrl ) {
85- const qrApiUrl = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${ encodeURIComponent ( qrUrl ) } ` ;
86- document . getElementById ( 'qr-code-display' ) . innerHTML = `<img src="${ qrApiUrl } " alt="二维码" class="qr-code-img">` ;
87- document . getElementById ( 'qr-code-container' ) . style . display = 'block' ;
88- }
89-
90- // 设置状态
91- function setQRStatus ( message , type ) {
92- const statusEl = document . getElementById ( 'qr-status' ) ;
93- statusEl . textContent = message ;
94- statusEl . className = `qr-status ${ type } ` ;
95- statusEl . style . display = 'block' ;
96- }
97-
9884// 开始状态检查
99- function startStatusCheck ( ) {
100- stopStatusCheck ( ) ;
85+ function startAliQRStatusCheck ( ) {
86+ stopAliQRStatusCheck ( ) ;
10187 alicloud2CheckInterval = setInterval ( checkAlicloud2Status , 2000 ) ;
10288}
10389
10490// 停止状态检查
105- function stopStatusCheck ( ) {
91+ function stopAliQRStatusCheck ( ) {
10692 if ( alicloud2CheckInterval ) {
10793 clearInterval ( alicloud2CheckInterval ) ;
10894 alicloud2CheckInterval = null ;
@@ -118,7 +104,7 @@ async function checkAlicloud2Status() {
118104 if ( elapsed > 180000 ) { // 3分钟
119105 setQRStatus ( '二维码可能已过期,建议点击刷新重新生成' , 'error' ) ;
120106 document . getElementById ( 'refresh-qr-btn' ) . style . display = 'inline-block' ;
121- stopStatusCheck ( ) ;
107+ stopAliQRStatusCheck ( ) ;
122108 return ;
123109 }
124110
@@ -138,15 +124,15 @@ async function checkAlicloud2Status() {
138124 break ;
139125 case 'CONFIRMED' :
140126 setQRStatus ( '登录成功!正在获取用户信息...' , 'success' ) ;
141- stopStatusCheck ( ) ;
127+ stopAliQRStatusCheck ( ) ;
142128 // 稍等一下确保token已保存
143129 setTimeout ( async ( ) => {
144130 await getAlicloud2UserInfo ( ) ;
145131 } , 1000 ) ;
146132 break ;
147133 case 'EXPIRED' :
148134 setQRStatus ( '二维码已过期,请点击刷新重新生成' , 'error' ) ;
149- stopStatusCheck ( ) ;
135+ stopAliQRStatusCheck ( ) ;
150136 document . getElementById ( 'refresh-qr-btn' ) . style . display = 'inline-block' ;
151137 break ;
152138 }
@@ -155,7 +141,7 @@ async function checkAlicloud2Status() {
155141 if ( response . status === 403 ) {
156142 setQRStatus ( '会话验证失败,请重新生成二维码' , 'error' ) ;
157143 document . getElementById ( 'refresh-qr-btn' ) . style . display = 'inline-block' ;
158- stopStatusCheck ( ) ;
144+ stopAliQRStatusCheck ( ) ;
159145 } else {
160146 setQRStatus ( '检查状态失败: ' + ( result . error || '未知错误' ) , 'error' ) ;
161147 document . getElementById ( 'refresh-qr-btn' ) . style . display = 'inline-block' ;
@@ -215,35 +201,3 @@ async function getAlicloud2UserInfo() {
215201 }
216202}
217203
218- // 刷新二维码
219- async function refreshQRCode ( ) {
220- document . getElementById ( 'refresh-qr-btn' ) . style . display = 'none' ;
221- // 清理旧会话
222- if ( alicloud2SessionId ) {
223- try {
224- await fetchWithFingerprint ( `/alicloud2/logout?session_id=${ alicloud2SessionId } ` ) ;
225- } catch ( e ) {
226- // console.log('清理旧会话失败:', e);
227- }
228- alicloud2SessionId = null ;
229- }
230- await startAlicloud2Login ( ) ;
231- }
232-
233- // 关闭模态框
234- function closeQRModal ( ) {
235- document . getElementById ( 'qr-modal' ) . style . display = 'none' ;
236- stopStatusCheck ( ) ;
237-
238- // 清理会话
239- if ( alicloud2SessionId ) {
240- fetchWithFingerprint ( `/alicloud2/logout?session_id=${ alicloud2SessionId } ` ) ;
241- alicloud2SessionId = null ;
242- }
243-
244- // 重置界面
245- document . getElementById ( 'qr-code-container' ) . style . display = 'none' ;
246- document . getElementById ( 'qr-status' ) . style . display = 'none' ;
247- document . getElementById ( 'refresh-qr-btn' ) . style . display = 'none' ;
248- }
249-
0 commit comments