fix(site): 官网 401 自动用 refresh_token 续签重试;资产加构建版本号破缓存
- 新增共享 auth.js(jiuAuth):access token 60 分钟过期后,checkout 提交/ 结果页轮询遇 401 自动 POST /auth/refresh 换新 token 并重试一次,仍失败 才跳登录——修复「已登录点提交订单却被踢回登录页」 - 登录判定放宽为 access 或 refresh token 任一存在(refresh 7 天有效) - 所有 JS/CSS 引用加 ?v=构建版本号:修复旧版 nav.js 被浏览器缓存后在新 页面执行(右上角错位的旧用户面板、带引号的 "张三" 显示) - nav.js 改经 jiuAuth 读 localStorage(JSON 解码,去掉引号显示) - 登录页回填上次的门店编号与账号 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
This commit is contained in:
+5
-8
@@ -68,13 +68,9 @@ permalink: /checkout/
|
||||
(function () {
|
||||
var API = '{{ site.appBaseUrl }}';
|
||||
function $(id) { return document.getElementById(id); }
|
||||
function token() {
|
||||
var raw = localStorage.getItem('flutter.access_token');
|
||||
if (!raw) return null;
|
||||
try { return JSON.parse(raw); } catch (e) { return raw; }
|
||||
}
|
||||
function gotoLogin() { location.href = '/login/?next=' + encodeURIComponent('/checkout/' + location.search); }
|
||||
if (!token()) { gotoLogin(); return; }
|
||||
// access token 只有 60 分钟,只要 refresh token(7 天)还在就算登录,请求时自动续签
|
||||
if (!jiuAuth.loggedIn()) { gotoLogin(); return; }
|
||||
|
||||
/* 套餐目录:价格仅前端展示,实付金额以 pay 套餐表为准(下单响应回传) */
|
||||
var PLANS = {
|
||||
@@ -123,12 +119,13 @@ permalink: /checkout/
|
||||
$('coBtn').addEventListener('click', function () {
|
||||
$('coErr').classList.remove('show');
|
||||
var btn = $('coBtn'); btn.disabled = true; btn.textContent = '正在创建订单…';
|
||||
fetch(API + '/api/v1/license/purchase', {
|
||||
jiuAuth.authFetch(API, '/api/v1/license/purchase', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token() },
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ biz_code: PLANS[plan][cycle].biz }),
|
||||
})
|
||||
.then(function (r) {
|
||||
// authFetch 已自动用 refresh_token 续签重试过,仍 401 才是真过期
|
||||
if (r.status === 401) { gotoLogin(); throw new Error('登录已过期'); }
|
||||
return r.json().then(function (j) { return { ok: r.ok, j: j }; });
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user