perf(modal): unify cancellable frontend modal flows
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -230,14 +230,18 @@
|
||||
}, 220);
|
||||
}
|
||||
|
||||
function responseData(result) {
|
||||
if (!result) return null;
|
||||
if (result.data !== undefined && result.data !== null) return result.data;
|
||||
if (result.json && result.json.data !== undefined) return result.json.data;
|
||||
return result.json;
|
||||
}
|
||||
|
||||
function responseHtml(result) {
|
||||
if (!result) return "";
|
||||
var json = result.json;
|
||||
if (json) {
|
||||
if (typeof json.html === "string") return json.html;
|
||||
if (json.data && typeof json.data.html === "string") return json.data.html;
|
||||
}
|
||||
return typeof result.text === "string" ? result.text : "";
|
||||
var data = responseData(result);
|
||||
if (data && typeof data.html === "string") return data.html;
|
||||
if (result && result.json && typeof result.json.html === "string") return result.json.html;
|
||||
return result && typeof result.text === "string" ? result.text : "";
|
||||
}
|
||||
|
||||
function errorMessage(error) {
|
||||
@@ -262,6 +266,27 @@
|
||||
|
||||
function renderResult(session, result) {
|
||||
if (!session || session.closed || active !== session) return;
|
||||
|
||||
if (session.options.responseType === "json" || typeof session.options.renderData === "function") {
|
||||
var data = responseData(result);
|
||||
if (data === null || data === undefined) {
|
||||
setState(session, "empty");
|
||||
telemetryMark(session, "first-content");
|
||||
telemetryMark(session, "ready");
|
||||
session.content.innerHTML = '<div class="aksrt-modal-runtime__error-body">暂无内容</div>';
|
||||
return;
|
||||
}
|
||||
if (typeof session.options.renderData === "function") {
|
||||
session.options.renderData(data, session, result);
|
||||
}
|
||||
setState(session, "ready");
|
||||
telemetryMark(session, "first-content");
|
||||
rehydrate(session);
|
||||
telemetryMark(session, "ready");
|
||||
if (typeof session.options.onData === "function") session.options.onData(data, session, result);
|
||||
return;
|
||||
}
|
||||
|
||||
var html = responseHtml(result);
|
||||
if (!html) {
|
||||
setState(session, "empty");
|
||||
@@ -379,6 +404,13 @@
|
||||
return window.AksrtModalCache.invalidate(tags);
|
||||
}
|
||||
|
||||
function rolloutEnabled(kind) {
|
||||
var config = window.aksrtData || window.aksrt || {};
|
||||
var rollout = config.frontendModalRollout;
|
||||
if (!rollout || typeof rollout[kind] === "undefined") return true;
|
||||
return rollout[kind] === true;
|
||||
}
|
||||
|
||||
window.AksrtModalRuntime = {
|
||||
open: open,
|
||||
openRemote: openRemote,
|
||||
@@ -387,6 +419,7 @@
|
||||
registerLoader: registerLoader,
|
||||
openLoader: openLoader,
|
||||
invalidate: invalidate,
|
||||
isRolloutEnabled: rolloutEnabled,
|
||||
getActive: function () { return active ? active.shell : null; },
|
||||
getState: function () { return active ? active.state : null; },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user