feat(modal): add cancellable shared runtime
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0647c501ba
commit
d79b063bf9
12 files changed
+999
-392
No files matched your search
+24
-18
@@ -15,31 +15,31 @@
|
||||
var detailFooter = page.querySelector("[data-aksrt-order-detail-footer]");
|
||||
var detailOrderNumber = "";
|
||||
|
||||
function toast(message) {
|
||||
if (window.AksrtToast && typeof window.AksrtToast.show === "function") {
|
||||
window.AksrtToast.show(message);
|
||||
function toast(message, type) {
|
||||
if (typeof window.AksrtToast === "function") {
|
||||
window.AksrtToast(message, type || "info");
|
||||
return;
|
||||
}
|
||||
if (typeof window.aksrtNotify === "function") {
|
||||
window.aksrtNotify(message, type || "info");
|
||||
return;
|
||||
}
|
||||
window.alert(message);
|
||||
}
|
||||
|
||||
function restRoot() {
|
||||
return String(aksrtData.siteUrl || "").replace(/\/$/, "") + "/wp-json/aksrt/v1";
|
||||
}
|
||||
|
||||
function request(path, body, method) {
|
||||
var options = {
|
||||
method: method || "POST",
|
||||
credentials: "same-origin",
|
||||
headers: { "X-WP-Nonce": aksrtData.restNonce || "" }
|
||||
};
|
||||
if (body !== undefined) {
|
||||
options.headers["Content-Type"] = "application/json";
|
||||
options.body = JSON.stringify(body || {});
|
||||
if (!window.AksrtRequest || typeof window.AksrtRequest.request !== "function") {
|
||||
return Promise.resolve({ success: false, message: "请求适配器未加载" });
|
||||
}
|
||||
return fetch(restRoot() + path, options).then(function (response) {
|
||||
return response.json().catch(function () {
|
||||
return { success: false, message: "请求失败(HTTP " + response.status + ")" };
|
||||
var options = { method: method || "POST" };
|
||||
if (body !== undefined) options.body = JSON.stringify(body || {});
|
||||
return window.AksrtRequest.request(path, options).then(function (response) {
|
||||
return response.json || {};
|
||||
}).catch(function (error) {
|
||||
var response = error && error.response ? error.response : {};
|
||||
return error && error.json ? error.json : (response.json || {
|
||||
success: false,
|
||||
message: error && error.message ? error.message : "请求失败",
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -219,6 +219,9 @@
|
||||
button.disabled = true;
|
||||
request(orderPath(number, "/pay"), method ? { payment_method: method } : {}).then(function (result) {
|
||||
if (!result.success) throw new Error(result.message || "支付失败");
|
||||
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === "function") {
|
||||
window.AksrtModalRuntime.invalidate(["orders", "vip"]);
|
||||
}
|
||||
var data = result.data || {};
|
||||
if (data.redirect && data.payment_url) {
|
||||
window.location.assign(data.payment_url);
|
||||
@@ -243,6 +246,9 @@
|
||||
button.disabled = true;
|
||||
request(orderPath(number, "/cancel")).then(function (result) {
|
||||
if (!result.success) throw new Error(result.message || "关闭订单失败");
|
||||
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === "function") {
|
||||
window.AksrtModalRuntime.invalidate(["orders", "vip"]);
|
||||
}
|
||||
toast("订单已关闭");
|
||||
refreshView();
|
||||
}).catch(function (error) {
|
||||
|
||||
Reference in new issue
Block a user