feat(modal): add cancellable shared runtime

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Fable 5 committed 2026-08-04 23:24:37 +08:00
1 parent 0647c501ba
commit d79b063bf9
12 files changed
+999 -392

No files matched your search

+21 -20
View File
@@ -8,36 +8,31 @@
(function () {
'use strict';
var aksrt = window.aksrtData || {};
var siteUrl = aksrt.siteUrl || '';
if (window.location.protocol === 'https:' && siteUrl.substring(0, 5) === 'http:') {
siteUrl = 'https:' + siteUrl.substring(5);
}
var REST = (siteUrl || '').replace(/\/$/, '') + '/wp-json/aksrt/v1';
var NONCE = aksrt.restNonce || aksrt.nonce || '';
function api(path, options) {
var opts = Object.assign({
credentials: 'same-origin',
headers: Object.assign({ 'Content-Type': 'application/json', 'X-WP-Nonce': NONCE }, (options && options.headers) || {}),
}, options || {});
return fetch(REST + path, opts).then(function (r) {
return r.json().catch(function () { return {}; }).then(function (j) {
return { ok: r.ok, status: r.status, json: j };
});
if (!window.AksrtRequest || typeof window.AksrtRequest.request !== 'function') {
return Promise.resolve({ ok: false, status: 0, json: { message: '请求适配器未加载' } });
}
return window.AksrtRequest.request(path, options || {}).then(function (response) {
return { ok: response.ok, status: response.status, json: response.json || {} };
}).catch(function (error) {
var response = error && error.response ? error.response : {};
return {
ok: false,
status: error && error.status ? error.status : (response.status || 0),
json: error && error.json ? error.json : (response.json || { message: error && error.message }),
};
});
}
function toast(msg, type) {
if (window.AksrtToast && typeof window.AksrtToast.show === 'function') {
window.AksrtToast.show(msg, type || 'info');
if (typeof window.AksrtToast === 'function') {
window.AksrtToast(msg, type || 'info');
return;
}
if (window.aksrtNotify) {
if (typeof window.aksrtNotify === 'function') {
window.aksrtNotify(msg, type || 'info');
return;
}
// fallback
try { console.log('[AKSRT badges]', msg); } catch (_) {}
}
@@ -265,6 +260,9 @@
return;
}
toast((r.json && r.json.message) || '已佩戴徽章', 'success');
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === 'function') {
window.AksrtModalRuntime.invalidate(['badges', 'identity']);
}
state.data = (r.json && r.json.data) || state.data;
renderHead();
renderGrid();
@@ -354,6 +352,9 @@
return;
}
toast((r.json && r.json.message) || '已佩戴徽章', 'success');
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === 'function') {
window.AksrtModalRuntime.invalidate(['badges', 'identity']);
}
// Re-open the refreshed single-badge modal so state stays in sync.
var refreshed = null;
try {