进行了一些小修复
This commit is contained in:
1 parent
b77926388f
commit
af3539914d
9 files changed
+956
-135
No files matched your search
+197
-135
@@ -15,6 +15,7 @@
|
||||
|
||||
if (!window.aksrtData) return;
|
||||
const REST_BASE = window.aksrtData.siteUrl ? window.aksrtData.siteUrl.replace(/\/$/, '') + '/wp-json/aksrt/v1' : '/wp-json/aksrt/v1';
|
||||
const PAY_CONTENT_PATH = '/pay/content/';
|
||||
|
||||
function tt(key, zh) { return zh; }
|
||||
|
||||
@@ -75,14 +76,16 @@
|
||||
modal.setAttribute('aria-labelledby', 'aksrt-dl-modal-title');
|
||||
modal.innerHTML =
|
||||
'<div class="aksrt-dl-modal__backdrop" data-close></div>' +
|
||||
'<div class="aksrt-dl-modal__panel" role="document" tabindex="-1">' +
|
||||
' <button type="button" class="aksrt-dl-modal__close" aria-label="' + tt('close', '关闭') + '" data-close>×</button>' +
|
||||
' <div class="aksrt-dl-modal__body" data-body></div>' +
|
||||
'<div class="aksrt-dl-modal__dialog modal-mini">' +
|
||||
' <div class="aksrt-dl-modal__panel modal-content" role="document" tabindex="-1">' +
|
||||
' <button type="button" class="aksrt-dl-modal__close" aria-label="' + tt('close', '关闭') + '" data-close>×</button>' +
|
||||
' <div class="aksrt-dl-modal__body" data-body></div>' +
|
||||
' </div>' +
|
||||
'</div>';
|
||||
document.body.appendChild(modal);
|
||||
|
||||
modal.addEventListener('click', function (e) {
|
||||
if (e.target.matches('[data-close]')) close();
|
||||
if (e.target.closest('[data-close]')) close();
|
||||
});
|
||||
modal.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape' && modal.classList.contains('is-open')) {
|
||||
@@ -95,14 +98,16 @@
|
||||
return modal;
|
||||
}
|
||||
|
||||
function open(html, returnFocusEl) {
|
||||
function open(html, returnFocusEl, variant) {
|
||||
// 记录调用方按钮以便关闭后回焦
|
||||
lastFocusedElement = returnFocusEl || document.activeElement;
|
||||
|
||||
const modal = buildModal();
|
||||
const body = modal.querySelector('[data-body]');
|
||||
// 给标题加 id,与 aria-labelledby 联动
|
||||
body.innerHTML = html.replace(/aksrt-dl-modal__title/, 'aksrt-dl-modal__title" id="aksrt-dl-modal-title');
|
||||
modal.classList.toggle('is-cashier', variant === 'cashier');
|
||||
body.innerHTML = html;
|
||||
const title = body.querySelector('.aksrt-dl-modal__title, .aksrt-cashier__title');
|
||||
if (title) title.id = 'aksrt-dl-modal-title';
|
||||
modal.classList.add('is-open');
|
||||
modal.setAttribute('aria-hidden', 'false');
|
||||
document.body.classList.add('aksrt-dl-modal-open');
|
||||
@@ -252,6 +257,25 @@
|
||||
return card.getAttribute('data-captcha') === '1';
|
||||
}
|
||||
|
||||
function cashierHeader() {
|
||||
return '<div class="modal-colorful-header colorful-bg jb-blue">' +
|
||||
'<button type="button" class="close aksrt-cashier__close" aria-label="' + tt('close', '关闭') + '" data-close>×</button>' +
|
||||
'<div class="colorful-make"></div>' +
|
||||
'<div class="text-center">' +
|
||||
' <div class="em2x"><i class="fa fas fa-cart-plus" aria-hidden="true"></i></div>' +
|
||||
' <div class="aksrt-cashier__title mt10 em12 padding-w10">' + tt('confirm_buy', '确认购买') + '</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
function openCashierContent(content, returnFocusEl) {
|
||||
open(
|
||||
cashierHeader() + '<div class="modal-pay-body box-body">' + content + '</div>',
|
||||
returnFocusEl,
|
||||
'cashier'
|
||||
);
|
||||
}
|
||||
|
||||
function ensureCaptchaThen(sourceEl, callback) {
|
||||
if (!isCaptchaActive(sourceEl)) { callback(); return; }
|
||||
const state = window.AKSRTCaptchaState;
|
||||
@@ -362,13 +386,8 @@
|
||||
return headers;
|
||||
}
|
||||
|
||||
function payApiBase(apiKind) {
|
||||
return '/pay/content/';
|
||||
}
|
||||
|
||||
function buildPreviewUrl(postId, priceType, couponCode, apiKind) {
|
||||
apiKind = apiKind || 'content';
|
||||
var previewUrl = REST_BASE + payApiBase(apiKind) + postId;
|
||||
function buildPreviewUrl(postId, priceType, couponCode) {
|
||||
var previewUrl = REST_BASE + PAY_CONTENT_PATH + postId;
|
||||
var qs = [];
|
||||
if (priceType) qs.push('price_type=' + encodeURIComponent(priceType));
|
||||
if (couponCode) qs.push('coupon_code=' + encodeURIComponent(couponCode));
|
||||
@@ -376,8 +395,8 @@
|
||||
return previewUrl;
|
||||
}
|
||||
|
||||
function fetchPreview(postId, priceType, couponCode, apiKind) {
|
||||
return fetch(buildPreviewUrl(postId, priceType, couponCode, apiKind), {
|
||||
function fetchPreview(postId, priceType, couponCode) {
|
||||
return fetch(buildPreviewUrl(postId, priceType, couponCode), {
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
headers: restHeaders(),
|
||||
@@ -386,18 +405,16 @@
|
||||
});
|
||||
}
|
||||
|
||||
function openCashier(postId, returnFocusEl, priceType, couponCode, apiKind) {
|
||||
function openCashier(postId, returnFocusEl, priceType, couponCode) {
|
||||
if (!postId) return;
|
||||
priceType = priceType || '';
|
||||
couponCode = couponCode || '';
|
||||
apiKind = apiKind || 'content';
|
||||
open(
|
||||
'<h3 class="aksrt-dl-modal__title">' + tt('cashier_loading', '确认购买') + '</h3>' +
|
||||
'<p class="aksrt-dl-modal__msg">' + tt('loading', '加载中…') + '</p>',
|
||||
openCashierContent(
|
||||
'<p class="aksrt-cashier__loading muted-2-color">' + tt('loading', '加载中…') + '</p>',
|
||||
returnFocusEl
|
||||
);
|
||||
|
||||
fetchPreview(postId, priceType, couponCode, apiKind)
|
||||
fetchPreview(postId, priceType, couponCode)
|
||||
.then(function (r) {
|
||||
if (!r.ok || (r.json && r.json.code)) {
|
||||
const code = r.json && r.json.code ? r.json.code : '';
|
||||
@@ -420,7 +437,6 @@
|
||||
var prev = r.json || {};
|
||||
if (priceType) prev._price_type = priceType;
|
||||
if (couponCode) prev._coupon_code = couponCode;
|
||||
prev._api_kind = apiKind;
|
||||
renderCashier(prev, returnFocusEl);
|
||||
})
|
||||
.catch(function () {
|
||||
@@ -428,6 +444,35 @@
|
||||
});
|
||||
}
|
||||
|
||||
function formatAssetLabel(preview, value) {
|
||||
const currency = escapeHtml(preview.currency || (preview.pay_modo === 'points' ? '积分' : '¥'));
|
||||
const amount = escapeHtml(value == null ? '' : value);
|
||||
return preview.pay_modo === 'points' ? amount + currency : currency + amount;
|
||||
}
|
||||
|
||||
function paymentMethodLogo(methodId) {
|
||||
const logoNames = {
|
||||
balance: 'pay-balance-logo.svg',
|
||||
alipay: 'pay-alipay-logo.svg',
|
||||
epay_alipay: 'pay-alipay-logo.svg',
|
||||
wechatpay: 'pay-wechat-logo.svg',
|
||||
epay_wxpay: 'pay-wechat-logo.svg',
|
||||
paypal: 'pay-paypal-logo.svg',
|
||||
stripe: 'pay-stripe-logo.svg',
|
||||
};
|
||||
const logo = logoNames[methodId];
|
||||
if (!logo) return '';
|
||||
const themeUrl = String(window.aksrtData.themeUrl || '').replace(/\/$/, '');
|
||||
return '<img src="' + escapeAttr(themeUrl + '/assets/img/' + logo) + '" alt="">';
|
||||
}
|
||||
|
||||
function cashierPriceRow(label, value, className) {
|
||||
return '<div class="flex jsb ab aksrt-cashier__price-row">' +
|
||||
'<span class="muted-2-color">' + label + '</span>' +
|
||||
'<div class="' + (className || '') + '">' + value + '</div>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
function renderCashier(preview, returnFocusEl) {
|
||||
if (!preview) return;
|
||||
if (preview.need_login && !preview.allow_guest) {
|
||||
@@ -450,7 +495,6 @@
|
||||
|
||||
const isPoints = preview.pay_modo === 'points';
|
||||
const priceType = (preview._price_type || preview.price_type || '');
|
||||
const apiKind = preview._api_kind || 'content';
|
||||
|
||||
let amountLabel = escapeHtml(preview.amount_label || '');
|
||||
let baseLabel = escapeHtml(preview.base_label || '');
|
||||
@@ -470,51 +514,78 @@
|
||||
|
||||
let priceRows = '';
|
||||
if (!preview.pay_limit) {
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('price', '价格') + '</span><b>' + baseLabel + '</b></div>';
|
||||
let regularPrice = '<span class="em14">' + baseLabel + '</span>';
|
||||
if (!isPoints && Number(preview.original) > Number(preview.base)) {
|
||||
regularPrice = '<span class="original-price">' + formatAssetLabel(preview, preview.original) + '</span>' + regularPrice;
|
||||
}
|
||||
priceRows += cashierPriceRow(tt('price', '价格'), regularPrice, 'aksrt-cashier__regular-price');
|
||||
}
|
||||
// VIP list price row when VIP reduced list amount.
|
||||
if (preview.list_amount !== preview.base) {
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('vip_price', '会员价') + '</span><b class="is-sale">' + listLabel + '</b></div>';
|
||||
priceRows += cashierPriceRow(
|
||||
tt('vip_price', '会员价') + '<span class="aksrt-cashier__vip-mark">VIP' + escapeHtml(preview.vip_level || '') + '</span>',
|
||||
'<span class="em14">' + listLabel + '</span>',
|
||||
'c-red'
|
||||
);
|
||||
} else if (preview.amount !== preview.base && !preview.rebate_discount && !preview.coupon_discount) {
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('vip_price', '会员价') + '</span><b class="is-sale">' + amountLabel + '</b></div>';
|
||||
priceRows += cashierPriceRow(
|
||||
tt('vip_price', '会员价') + '<span class="aksrt-cashier__vip-mark">VIP' + escapeHtml(preview.vip_level || '') + '</span>',
|
||||
'<span class="em14">' + amountLabel + '</span>',
|
||||
'c-red'
|
||||
);
|
||||
}
|
||||
if (preview.rebate_discount > 0) {
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('rebate_discount', '推广折扣') + '</span><b class="is-sale">' + escapeHtml(preview.rebate_discount_label || ('-' + preview.rebate_discount)) + '</b></div>';
|
||||
priceRows += cashierPriceRow(
|
||||
tt('rebate_discount', '推广折扣'),
|
||||
'<span class="em14">' + escapeHtml(preview.rebate_discount_label || ('-' + preview.rebate_discount)) + '</span>'
|
||||
);
|
||||
}
|
||||
if (preview.coupon_discount > 0) {
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('coupon_discount', '优惠码') + '</span><b class="is-sale">' + escapeHtml(preview.coupon_discount_label || ('-' + preview.coupon_discount)) + '</b></div>';
|
||||
priceRows += cashierPriceRow(
|
||||
tt('coupon_discount', '优惠码'),
|
||||
'<span class="em14">' + escapeHtml(preview.coupon_discount_label || ('-' + preview.coupon_discount)) + '</span>'
|
||||
);
|
||||
}
|
||||
if (preview.amount !== preview.base || preview.rebate_discount > 0 || preview.coupon_discount > 0) {
|
||||
priceRows += cashierPriceRow(
|
||||
tt('pay_amount', '支付金额'),
|
||||
'<span class="em14">' + amountLabel + '</span>',
|
||||
'font-bold c-red'
|
||||
);
|
||||
}
|
||||
priceRows += '<div class="aksrt-cashier__row"><span>' + tt('pay_amount', '支付金额') + '</span><b class="is-sale">' + amountLabel + '</b></div>';
|
||||
|
||||
let body = '';
|
||||
body += '<div class="aksrt-cashier__product"><span class="aksrt-cashier__tag">' + typeLabel + '</span><span>' + title + '</span></div>';
|
||||
body += '<div class="aksrt-cashier__box">' + priceRows + '</div>';
|
||||
body += '<div class="mb10 order-type-' + escapeAttr(preview.pay_type || '') + '">' +
|
||||
'<span class="pay-tag badg badg-sm mr6">' + typeLabel + '</span><span>' + title + '</span>' +
|
||||
'</div>';
|
||||
body += '<div class="mb10 muted-box padding-h6 line-16">' + priceRows + '</div>';
|
||||
|
||||
if (isPoints) {
|
||||
body += '<div class="aksrt-cashier__box"><div class="aksrt-cashier__row"><span>' + tt('my_points', '我的积分') + '</span><b class="is-ok">' + balance + '</b></div></div>';
|
||||
body += '<div class="mb10 muted-box padding-h10">' +
|
||||
'<div class="flex jsb ac"><span class="muted-2-color">' +
|
||||
'<i class="fa fas fa-database aksrt-cashier__asset-icon" aria-hidden="true"></i>' + tt('my_points', '我的积分') +
|
||||
'</span><div class="c-green"><span class="em14">' + balance + '</span></div></div></div>';
|
||||
if (!preview.balance_enough) {
|
||||
body += '<div class="aksrt-cashier__warn">' + tt('points_short', '抱歉,您的积分不足,暂时无法支付') + '</div>';
|
||||
body += '<div class="aksrt-dl-modal__actions">';
|
||||
body += '<div class="badg c-red btn-block mb20 aksrt-cashier__warn">' + tt('points_short', '抱歉,您的积分不足,暂时无法支付') + '</div>';
|
||||
body += '<div class="modal-buts but-average">';
|
||||
if (preview.credits_url) {
|
||||
body += '<a class="btn-primary btn-sm" href="' + escapeAttr(preview.credits_url) + '">' + tt('my_points', '我的积分') + '</a>';
|
||||
body += '<a class="but padding-lg" href="' + escapeAttr(preview.credits_url) + '">' + tt('my_points', '我的积分') + '</a>';
|
||||
}
|
||||
body += '</div>';
|
||||
open('<h3 class="aksrt-dl-modal__title">' + tt('confirm_buy', '确认购买') + '</h3>' + body, returnFocusEl);
|
||||
openCashierContent(body, returnFocusEl);
|
||||
return;
|
||||
}
|
||||
body += '<div class="aksrt-dl-modal__actions">';
|
||||
body += '<button type="button" class="btn-primary aksrt-dl-modal__download" data-aksrt-pay-submit data-mode="points" data-price-type="' + escapeAttr(priceType) + '">' + tt('pay_now', '立即支付') + ' ' + amountLabel + '</button>';
|
||||
body += '</div>';
|
||||
body += '<button type="button" class="mt6 but jb-red initiate-pay btn-block radius" data-aksrt-pay-submit data-mode="points" data-price-type="' + escapeAttr(priceType) + '">' +
|
||||
tt('pay_now', '立即支付') + '<span class="pay-price-text ml10">' + amountLabel + '</span></button>';
|
||||
} else {
|
||||
if (couponAllowed) {
|
||||
body += '<div class="aksrt-cashier__coupon">';
|
||||
body += '<div class="aksrt-cashier__methods-title">' + tt('use_coupon', '使用优惠码') + '</div>';
|
||||
body += '<div class="aksrt-cashier__coupon-row">';
|
||||
body += '<input type="text" class="aksrt-cashier__coupon-input" name="aksrt_coupon_code" value="' + couponCodeVal + '" placeholder="' + escapeAttr(tt('enter_coupon', '请输入优惠码')) + '" autocomplete="off">';
|
||||
body += '<button type="button" class="btn-sm" data-aksrt-check-coupon>' + tt('check_coupon', '检查优惠码') + '</button>';
|
||||
body += '<div class="mb10 coupon-input-box">';
|
||||
body += '<div class="muted-2-color em09 mb6">' + tt('use_coupon', '使用优惠码') + '</div>';
|
||||
body += '<div class="relative">';
|
||||
body += '<input type="text" class="form-control coupon-input" name="aksrt_coupon_code" value="' + couponCodeVal + '" placeholder="' + escapeAttr(tt('enter_coupon', '请输入优惠码')) + '" autocomplete="off">';
|
||||
body += '<span class="abs-right"><button type="button" class="but c-blue coupon-submit" data-aksrt-check-coupon>' + tt('check_coupon', '检查优惠码') + '</button></span>';
|
||||
body += '</div>';
|
||||
if (preview.coupon_desc) {
|
||||
body += '<div class="aksrt-cashier__coupon-desc">' + escapeHtml(preview.coupon_desc) + '</div>';
|
||||
body += '<div class="muted-3-color px12 mt6 aksrt-cashier__coupon-desc">' + escapeHtml(preview.coupon_desc) + '</div>';
|
||||
}
|
||||
if (preview.coupon_error) {
|
||||
body += '<div class="aksrt-cashier__warn">' + escapeHtml(preview.coupon_error) + '</div>';
|
||||
@@ -524,42 +595,56 @@
|
||||
body += '</div>';
|
||||
}
|
||||
const walletBal = typeof preview.wallet_balance === 'string'
|
||||
? preview.wallet_balance
|
||||
: (typeof preview.balance === 'string' ? preview.balance : '0.00');
|
||||
const hasBalanceMethod = methods.some(function (m) { return (m && m.id) === 'balance'; });
|
||||
if (hasBalanceMethod) {
|
||||
body += '<div class="aksrt-cashier__box"><div class="aksrt-cashier__row"><span>' + tt('my_wallet', '我的余额') + '</span><b class="is-ok">¥' + escapeHtml(walletBal) + '</b></div></div>';
|
||||
if (preview.balance_enough === false) {
|
||||
body += '<div class="aksrt-cashier__warn">' + tt('wallet_short', '余额不足,请先充值或选择其他支付方式') + '</div>';
|
||||
if (preview.credits_url) {
|
||||
body += '<div class="aksrt-dl-modal__actions"><a class="btn-sm" href="' + escapeAttr(preview.credits_url) + '">' + tt('go_recharge', '去充值') + '</a></div>';
|
||||
}
|
||||
? preview.wallet_balance
|
||||
: (typeof preview.balance === 'string' ? preview.balance : '0.00');
|
||||
const hasBalanceMethod = methods.some(function (m) { return (m && m.id) === 'balance'; });
|
||||
let methodHtml = '';
|
||||
methods.forEach(function (m, idx) {
|
||||
const rawId = String((m && m.id) || '');
|
||||
const id = escapeAttr(rawId);
|
||||
const name = escapeHtml((m && m.name) || rawId);
|
||||
methodHtml += '<div class="flex jc hh payment-method-radio hollow-radio flex-auto pointer' + (idx === 0 ? ' active' : '') + '"' +
|
||||
' role="radio" aria-checked="' + (idx === 0 ? 'true' : 'false') + '" tabindex="0" data-aksrt-payment-method="' + id + '">' +
|
||||
paymentMethodLogo(rawId) + '<div>' + name + '</div></div>';
|
||||
});
|
||||
if (methods.length > 1) {
|
||||
body += '<div class="muted-2-color em09 mb6">' + tt('pay_method', '请选择支付方式') + '</div>' +
|
||||
'<div class="flex mb10 aksrt-cashier__methods" role="radiogroup">' + methodHtml + '</div>';
|
||||
}
|
||||
if (methods.length) {
|
||||
body += '<input type="hidden" name="aksrt_pay_method" value="' + escapeAttr(methods[0].id || '') + '">';
|
||||
}
|
||||
if (hasBalanceMethod) {
|
||||
const balanceSelected = methods[0] && methods[0].id === 'balance';
|
||||
body += '<div class="mb10 muted-box padding-h10 aksrt-cashier__balance" data-aksrt-balance-box' + (balanceSelected ? '' : ' hidden') + '>' +
|
||||
'<div class="flex jsb ac"><span class="muted-2-color">' +
|
||||
'<i class="fa fas fa-wallet aksrt-cashier__asset-icon" aria-hidden="true"></i>' + tt('my_wallet', '我的余额') +
|
||||
'</span><div class="c-blue-2"><span class="em14">¥' + escapeHtml(walletBal) + '</span></div></div>';
|
||||
if (preview.balance_enough === false) {
|
||||
if (preview.credits_url) {
|
||||
body += '<a class="but c-red block mt6 aksrt-cashier__recharge" href="' + escapeAttr(preview.credits_url) + '">' +
|
||||
tt('wallet_short', '抱歉!余额不足,请先充值') + ' <i class="ml6 fa fa-angle-right em12" aria-hidden="true"></i></a>';
|
||||
} else {
|
||||
body += '<div class="c-red mt6 aksrt-cashier__recharge">' + tt('wallet_short', '抱歉!余额不足,请先充值') + '</div>';
|
||||
}
|
||||
}
|
||||
let methodHtml = '';
|
||||
methods.forEach(function (m, idx) {
|
||||
const id = escapeAttr(m.id || '');
|
||||
const name = escapeHtml(m.name || id);
|
||||
methodHtml += '<label class="aksrt-cashier__method"><input type="radio" name="aksrt_pay_method" value="' + id + '"' + (idx === 0 ? ' checked' : '') + '> <span>' + name + '</span></label>';
|
||||
});
|
||||
if (methodHtml) {
|
||||
body += '<div class="aksrt-cashier__methods"><div class="aksrt-cashier__methods-title">' + tt('pay_method', '支付方式') + '</div>' + methodHtml + '</div>';
|
||||
} else {
|
||||
body += '<div class="aksrt-cashier__warn">' + tt('no_pay_method', '暂无可用支付方式,请联系站长配置收款接口') + '</div>';
|
||||
}
|
||||
body += '<div class="aksrt-dl-modal__actions">';
|
||||
if (methodHtml) {
|
||||
body += '<button type="button" class="btn-primary aksrt-dl-modal__download" data-aksrt-pay-submit data-mode="cash" data-price-type="' + escapeAttr(priceType) + '">' + tt('pay_now', '立即支付') + ' ' + amountLabel + '</button>';
|
||||
}
|
||||
body += '</div>';
|
||||
}
|
||||
if (methods.length) {
|
||||
body += '<button type="button" class="mt6 but jb-red initiate-pay btn-block radius" data-aksrt-pay-submit data-mode="cash" data-price-type="' + escapeAttr(priceType) + '">' +
|
||||
tt('pay_now', '立即支付') + '<span class="pay-price-text ml10">' + amountLabel + '</span></button>';
|
||||
} else {
|
||||
body += '<div class="badg c-red btn-block aksrt-cashier__warn">' + tt('no_pay_method', '暂无可用支付方式,请联系站长配置收款接口') + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
open('<h3 class="aksrt-dl-modal__title">' + tt('confirm_buy', '确认购买') + '</h3>' + body, returnFocusEl);
|
||||
openCashierContent(body, returnFocusEl);
|
||||
const modal = document.getElementById('aksrt-dl-modal');
|
||||
|
||||
const checkBtn = document.querySelector('[data-aksrt-check-coupon]');
|
||||
const checkBtn = modal && modal.querySelector('[data-aksrt-check-coupon]');
|
||||
if (checkBtn) {
|
||||
checkBtn.addEventListener('click', function () {
|
||||
const input = document.querySelector('input[name="aksrt_coupon_code"]');
|
||||
const input = modal.querySelector('input[name="aksrt_coupon_code"]');
|
||||
const code = input ? String(input.value || '').trim() : '';
|
||||
if (!code) {
|
||||
if (input) input.focus();
|
||||
@@ -568,7 +653,7 @@
|
||||
checkBtn.disabled = true;
|
||||
const old = checkBtn.innerHTML;
|
||||
checkBtn.innerHTML = tt('checking', '检查中…');
|
||||
fetchPreview(preview.post_id, priceType, code, apiKind)
|
||||
fetchPreview(preview.post_id, priceType, code)
|
||||
.then(function (r) {
|
||||
checkBtn.disabled = false;
|
||||
checkBtn.innerHTML = old;
|
||||
@@ -579,7 +664,6 @@
|
||||
var prev = r.json || {};
|
||||
if (priceType) prev._price_type = priceType;
|
||||
prev._coupon_code = code;
|
||||
prev._api_kind = apiKind;
|
||||
renderCashier(prev, returnFocusEl);
|
||||
})
|
||||
.catch(function () {
|
||||
@@ -590,23 +674,47 @@
|
||||
});
|
||||
}
|
||||
|
||||
const submitBtn = document.querySelector('[data-aksrt-pay-submit]');
|
||||
if (modal) {
|
||||
const methodCards = modal.querySelectorAll('[data-aksrt-payment-method]');
|
||||
const methodInput = modal.querySelector('input[name="aksrt_pay_method"]');
|
||||
const balanceBox = modal.querySelector('[data-aksrt-balance-box]');
|
||||
const selectMethod = function (card) {
|
||||
const method = card.getAttribute('data-aksrt-payment-method') || '';
|
||||
methodCards.forEach(function (item) {
|
||||
const active = item === card;
|
||||
item.classList.toggle('active', active);
|
||||
item.setAttribute('aria-checked', active ? 'true' : 'false');
|
||||
});
|
||||
if (methodInput) methodInput.value = method;
|
||||
if (balanceBox) balanceBox.hidden = method !== 'balance';
|
||||
};
|
||||
methodCards.forEach(function (card) {
|
||||
card.addEventListener('click', function () { selectMethod(card); });
|
||||
card.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault();
|
||||
selectMethod(card);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const submitBtn = modal && modal.querySelector('[data-aksrt-pay-submit]');
|
||||
if (submitBtn) {
|
||||
submitBtn.addEventListener('click', function () {
|
||||
const mode = submitBtn.getAttribute('data-mode') || (isPoints ? 'points' : 'cash');
|
||||
let paymentMethod = 'balance';
|
||||
const checked = document.querySelector('input[name="aksrt_pay_method"]:checked');
|
||||
if (checked) paymentMethod = checked.value;
|
||||
const input = document.querySelector('input[name="aksrt_coupon_code"]');
|
||||
const selected = modal.querySelector('input[name="aksrt_pay_method"]');
|
||||
if (selected) paymentMethod = selected.value;
|
||||
const input = modal.querySelector('input[name="aksrt_coupon_code"]');
|
||||
const code = input ? String(input.value || '').trim() : (preview.coupon_code || preview._coupon_code || '');
|
||||
submitPurchase(preview.post_id, mode, paymentMethod, submitBtn, returnFocusEl, code, apiKind);
|
||||
submitPurchase(preview.post_id, mode, paymentMethod, submitBtn, returnFocusEl, code);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function submitPurchase(postId, mode, paymentMethod, button, returnFocusEl, couponCode, apiKind) {
|
||||
function submitPurchase(postId, mode, paymentMethod, button, returnFocusEl, couponCode) {
|
||||
if (!postId) return;
|
||||
apiKind = apiKind || 'content';
|
||||
const original = button.innerHTML;
|
||||
button.disabled = true;
|
||||
button.innerHTML = tt('processing', '处理中…');
|
||||
@@ -620,7 +728,7 @@
|
||||
if (!button.dataset.aksrtOperationKey) {
|
||||
button.dataset.aksrtOperationKey = window.AksrtRequest.createIdempotencyKey();
|
||||
}
|
||||
fetch(REST_BASE + payApiBase(apiKind) + postId, {
|
||||
fetch(REST_BASE + PAY_CONTENT_PATH + postId, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: restHeaders(button.dataset.aksrtOperationKey),
|
||||
@@ -687,7 +795,7 @@
|
||||
10
|
||||
);
|
||||
const priceType = buyBtn.getAttribute('data-price-type') || '';
|
||||
if (postId) openCashier(postId, buyBtn, priceType, '', 'content');
|
||||
if (postId) openCashier(postId, buyBtn, priceType);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -695,7 +803,7 @@
|
||||
if (cashierLink && cashierLink.hasAttribute('data-aksrt-pay-content')) {
|
||||
e.preventDefault();
|
||||
const postId = parseInt(cashierLink.getAttribute('data-aksrt-pay-content') || '0', 10);
|
||||
if (postId) openCashier(postId, cashierLink, '', '', 'content');
|
||||
if (postId) openCashier(postId, cashierLink);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -707,54 +815,8 @@
|
||||
});
|
||||
|
||||
// Public cashier bridge (content pay).
|
||||
window.aksrtOpenCashier = function (postId, returnFocusEl, priceType, couponCode, apiKind) {
|
||||
openCashier(postId, returnFocusEl || null, priceType || '', couponCode || '', apiKind || 'content');
|
||||
window.aksrtOpenCashier = function (postId, returnFocusEl, priceType, couponCode) {
|
||||
openCashier(postId, returnFocusEl || null, priceType || '', couponCode || '');
|
||||
};
|
||||
|
||||
// ===== 注入 modal 基础样式(避免必须额外加载 CSS)=====
|
||||
const style = document.createElement('style');
|
||||
style.textContent =
|
||||
'.aksrt-dl-modal{position:fixed;inset:0;z-index:10000;display:none;}' +
|
||||
'.aksrt-dl-modal.is-open{display:flex;align-items:center;justify-content:center;}' +
|
||||
'.aksrt-dl-modal__backdrop{position:absolute;inset:0;background:rgba(0,0,0,.55);}' +
|
||||
'.aksrt-dl-modal__panel{position:relative;background:#fff;border-radius:14px;padding:26px 28px 24px;width:min(420px,calc(100vw - 32px));box-shadow:0 24px 56px rgba(15,23,42,.24);color:#111827;}' +
|
||||
'.aksrt-dl-modal__close{position:absolute;top:10px;right:12px;background:transparent;border:0;font-size:24px;line-height:1;cursor:pointer;color:#6b7280;}' +
|
||||
'.aksrt-dl-modal__title{font:700 20px/1.3 inherit;margin:0 28px 18px 0;color:#111827;}' +
|
||||
'.aksrt-dl-modal__msg{margin:0 0 18px;color:#4b5563;font-size:14px;line-height:1.65;}' +
|
||||
'.aksrt-dl-modal__msg--warn{color:#92400e;background:transparent;border:0;border-top:1px solid #fde68a;border-bottom:1px solid #fde68a;padding:12px 0;}' +
|
||||
'.aksrt-dl-modal__row{display:grid;grid-template-columns:64px minmax(0,1fr) 72px;align-items:center;gap:12px;margin:0 0 18px;padding:12px 0;border-top:1px solid #e5e7eb;border-bottom:1px solid #e5e7eb;}' +
|
||||
'.aksrt-dl-modal__label{font-size:13px;font-weight:600;color:#6b7280;white-space:nowrap;}' +
|
||||
'.aksrt-dl-modal__code{display:block;min-width:0;color:#111827;font:800 18px/1.25 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;letter-spacing:.06em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}' +
|
||||
'.aksrt-dl-modal__copy{appearance:none!important;display:inline-flex!important;align-items:center!important;justify-content:center!important;width:72px!important;height:32px!important;background:#eff6ff!important;border:1px solid #bfdbfe!important;border-radius:8px!important;padding:0!important;cursor:pointer!important;color:#2563eb!important;-webkit-text-fill-color:#2563eb!important;font-size:0!important;font-weight:700!important;line-height:1!important;font-family:inherit!important;text-indent:0!important;opacity:1!important;visibility:visible!important;white-space:nowrap!important;overflow:visible!important;}' +
|
||||
'.aksrt-dl-modal__copy::before,.aksrt-dl-modal__copy::after{content:none!important;display:none!important;}' +
|
||||
'.aksrt-dl-modal__copy:hover{background:#dbeafe!important;border-color:#93c5fd!important;color:#1d4ed8!important;-webkit-text-fill-color:#1d4ed8!important;}' +
|
||||
'.aksrt-dl-modal__copy-text{display:inline-flex!important;align-items:center!important;justify-content:center!important;position:relative!important;z-index:2!important;color:#2563eb!important;-webkit-text-fill-color:#2563eb!important;font-size:13px!important;font-weight:700!important;line-height:1!important;font-family:inherit!important;text-indent:0!important;opacity:1!important;visibility:visible!important;white-space:nowrap!important;}' +
|
||||
'.aksrt-dl-modal__copy:hover .aksrt-dl-modal__copy-text{color:#1d4ed8!important;-webkit-text-fill-color:#1d4ed8!important;}' +
|
||||
'.aksrt-dl-modal__actions{display:flex;align-items:center;gap:12px;padding-top:4px;flex-wrap:wrap;}' +
|
||||
'.aksrt-dl-modal__download{min-height:40px;padding:0 18px;border-radius:9px;display:inline-flex;align-items:center;justify-content:center;text-decoration:none;border:0;cursor:pointer;}' +
|
||||
'.aksrt-dl-modal__balance{font-size:13px;color:#6b7280;margin-left:auto;white-space:nowrap;}' +
|
||||
'.aksrt-cashier__product{margin:0 0 12px;font-size:14px;line-height:1.5;}' +
|
||||
'.aksrt-cashier__tag{display:inline-block;margin-right:8px;padding:2px 8px;border-radius:6px;background:#eff6ff;color:#1d4ed8;font-size:12px;font-weight:700;}' +
|
||||
'.aksrt-cashier__box{background:#f8fafc;border:1px solid #e5e7eb;border-radius:10px;padding:10px 12px;margin:0 0 12px;}' +
|
||||
'.aksrt-cashier__row{display:flex;justify-content:space-between;align-items:center;gap:12px;font-size:13px;color:#6b7280;padding:4px 0;}' +
|
||||
'.aksrt-cashier__row b{color:#111827;font-size:15px;}' +
|
||||
'.aksrt-cashier__row b.is-sale{color:#dc2626;}' +
|
||||
'.aksrt-cashier__row b.is-ok{color:#059669;}' +
|
||||
'.aksrt-cashier__warn{background:#fef2f2;color:#b91c1c;border-radius:8px;padding:10px 12px;margin:0 0 12px;font-size:13px;}' +
|
||||
'.aksrt-cashier__methods{margin:0 0 14px;}' +
|
||||
'.aksrt-cashier__methods-title{font-size:13px;font-weight:600;color:#374151;margin:0 0 8px;}' +
|
||||
'.aksrt-cashier__method{display:flex;align-items:center;gap:8px;padding:8px 10px;border:1px solid #e5e7eb;border-radius:8px;margin:0 0 6px;cursor:pointer;font-size:13px;}' +
|
||||
'.aksrt-cashier__coupon{margin:0 0 14px;}' +
|
||||
'.aksrt-cashier__coupon-row{display:flex;gap:8px;align-items:center;}' +
|
||||
'.aksrt-cashier__coupon-input{flex:1;min-width:0;padding:8px 10px;border:1px solid #e5e7eb;border-radius:8px;font-size:13px;}' +
|
||||
'.aksrt-cashier__coupon-desc{margin-top:6px;font-size:12px;color:#9ca3af;line-height:1.5;}' +
|
||||
'.aksrt-cashier__coupon-ok{margin-top:6px;font-size:12px;color:#059669;}' +
|
||||
'.resource-download-box__attrs{list-style:none;margin:10px 0 0;padding:0;display:grid;gap:6px;}' +
|
||||
'.resource-download-box__attrs-item{display:flex;justify-content:space-between;gap:12px;font-size:12px;color:#6b7280;}' +
|
||||
'.resource-download-box__attrs-name{flex:0 0 auto;}' +
|
||||
'.resource-download-box__attrs-value{color:#111827;text-align:right;}' +
|
||||
'.resource-download-box__paid-badge{background:#ecfdf5!important;color:#047857!important;}.resource-download-box__paid-meta{display:grid;gap:4px;margin:8px 0 12px;padding:10px 12px;background:#f0fdf4;border:1px solid #bbf7d0;border-radius:10px;font-size:12px;color:#166534;}' +
|
||||
'@media(max-width:480px){.aksrt-dl-modal__panel{padding:24px 20px 22px;}.aksrt-dl-modal__row{grid-template-columns:1fr 72px;gap:8px 12px;}.aksrt-dl-modal__label{grid-column:1 / -1;}.aksrt-dl-modal__code{font-size:17px;}.aksrt-dl-modal__actions{align-items:flex-start;flex-direction:column;}.aksrt-dl-modal__download{width:100%;}.aksrt-dl-modal__balance{margin-left:0;}}' +
|
||||
'body.aksrt-dl-modal-open{overflow:hidden;}';
|
||||
document.head.appendChild(style);
|
||||
})();
|
||||
Reference in new issue
Block a user