diff --git a/welcome.html b/welcome.html index 04a8a2e..b017c77 100644 --- a/welcome.html +++ b/welcome.html @@ -98,7 +98,8 @@ var token = localStorage.getItem('pxh_token'); async function api(method, path, body) { var opts = { method: method, headers: {'Content-Type': 'application/json'} }; - if (token) opts.headers['Authorization'] = 'Bearer ' + token; + var t = token || localStorage.getItem('pxh_token'); + if (t) opts.headers['Authorization'] = 'Bearer ' + t; if (body) opts.body = JSON.stringify(body); var r = await fetch(API + path, opts); return r; @@ -244,6 +245,7 @@ async function loadDevices() { document.getElementById('sys-status').textContent = '运行中'; var names = { 'zone.home': '家庭区域', 'person.admin': '管理员' }; try { + if (!token) token = localStorage.getItem('pxh_token'); if (!token) { document.getElementById('sys-status').textContent = '未登录 (无token)'; return; } var r = await api('GET', '/api/states'); if (!r.ok) throw new Error('HTTP ' + r.status + ' ' + r.statusText);