修改功能

This commit is contained in:
2026-08-29 19:06:07 +08:00
parent f94c652c7c
commit aaed0584b1
142 changed files with 6176 additions and 869 deletions
+114 -16
View File
@@ -13,6 +13,13 @@
})(typeof globalThis !== 'undefined' ? globalThis : window, function (root) {
'use strict';
function confirmAction(message) {
if (root.ProfileUI && typeof root.ProfileUI.confirmAction === 'function') {
return root.ProfileUI.confirmAction(message);
}
return Promise.resolve(!root['confirm'] || root['confirm'](message));
}
var PACKAGE_TYPES = {
vip: '会员套餐',
storage: '存储扩容'
@@ -138,13 +145,11 @@
var body = {};
var packageId = normalizeId(source.packageId);
var genealogyId = normalizeId(source.genealogyId);
var payType = optionalText(source.payType);
if (packageId) body.packageId = packageId;
else if (source.packageId !== undefined) body.invalidPackageId = true;
if (genealogyId) body.genealogyId = genealogyId;
else if (source.genealogyId) body.invalidGenealogyId = true;
if (payType) body.payType = payType;
return body;
}
@@ -155,10 +160,20 @@
String(body.genealogyId).trim() !== '' && !normalizeId(body.genealogyId))) {
return '家谱选项无效';
}
if (body.payType && body.payType !== 'wechat') return '支付方式无效';
return '';
}
function normalizeVipCapability(value) {
var source = value || {};
var methods = Array.isArray(source.paymentMethods) ? source.paymentMethods : [];
var wechat = methods.find(function (item) { return item && item.paymentMethod === 'WECHAT'; });
return {
enabled: source.enabled === true && !!wechat && wechat.enabled === true,
disabledReason: optionalText(source.disabledReason || wechat && wechat.disabledReason)
};
}
function normalizeVipOrder(item) {
var source = item || {};
var orderId = normalizeId(source.orderId);
@@ -176,7 +191,8 @@
(source.genealogyId !== undefined && source.genealogyId !== null && !genealogyId) ||
orderAmount === null || payAmount === null ||
!Object.prototype.hasOwnProperty.call(PAY_STATUS, payStatus) ||
['0', '1'].indexOf(status) < 0) {
['0', '1'].indexOf(status) < 0 ||
(source.transactionId !== undefined && source.transactionId !== null && !normalizeId(source.transactionId))) {
return null;
}
return {
@@ -194,10 +210,38 @@
payTime: optionalText(source.payTime),
expireTime: optionalText(source.expireTime),
status: status,
remark: optionalText(source.remark)
remark: optionalText(source.remark),
transactionId: source.transactionId === undefined || source.transactionId === null ? '' : normalizeId(source.transactionId),
canRefreshPayment: source.canRefreshPayment === true,
canClose: source.canClose === true
};
}
function normalizePaymentOrder(value) {
var source = value || {};
var order = normalizeVipOrder(source.order);
var transactionId = normalizeId(source.transactionId);
var codeUrl = optionalText(source.codeUrl);
if (!order || !transactionId || !codeUrl || source.tradeType !== 'NATIVE' || source.paymentMethod !== 'WECHAT') return null;
return {
order: order,
transactionId: transactionId,
codeUrl: codeUrl,
expiresAt: optionalText(source.expiresAt),
completed: source.completed === true
};
}
function normalizePaymentStatus(value) {
var source = value || {};
var transactionId = normalizeId(source.transactionId);
var status = optionalText(source.status);
if (!transactionId || ['CREATED', 'PAYING', 'SUCCESS', 'CLOSED', 'REFUNDING', 'REFUNDED'].indexOf(status) < 0) return null;
return { transactionId: transactionId, status: status, paidAt: optionalText(source.paidAt) };
}
function normalizeVipOrders(data) {
if (!Array.isArray(data)) return [];
return data.map(normalizeVipOrder).filter(Boolean);
@@ -255,7 +299,9 @@
return '<article class="module-row"><div><h3>' + escapeHtml(item.packageName) +
'</h3><p>' + escapeHtml(details) + '</p></div><span class="pill">' +
PAY_STATUS[item.payStatus] + '</span></article>';
PAY_STATUS[item.payStatus] + '</span>' +
(item.canRefreshPayment && item.transactionId ? '<button class="btn outline" type="button" data-vip-payment-refresh="' + escapeHtml(item.transactionId) + '">查询支付</button>' : '') +
(item.canClose && item.transactionId ? '<button class="btn outline" type="button" data-vip-payment-close="' + escapeHtml(item.transactionId) + '">关闭支付</button>' : '') + '</article>';
}).join('');
}
@@ -282,6 +328,9 @@
var status = root.document && root.document.querySelector('[data-vip-order-status]');
var refresh = root.document && root.document.querySelector('[data-vip-order-refresh]');
var orderList = root.document && root.document.querySelector('[data-vip-order-list]');
var paymentPanel = root.document && root.document.querySelector('[data-vip-payment-panel]');
var paymentQr = root.document && root.document.querySelector('[data-vip-payment-qr]');
var paymentText = root.document && root.document.querySelector('[data-vip-payment-text]');
var api = root.GenealogyApi && root.GenealogyApi.defaultClient;
var packages = [];
var selectedPackageId = '';
@@ -289,6 +338,7 @@
? root.ProfileUI.getGenealogyId()
: '';
var writePending = false;
var purchaseEnabled = false;
if (!page) return;
if (shouldRedirectToLogin(api)) {
@@ -296,7 +346,7 @@
return;
}
if (!packageList || !selectedText || !genealogySelect || !form || !orderList ||
!api.vipPackages || !api.genealogiesMine || !api.vipOrders || !api.createVipOrder) {
!api.vipCapability || !api.vipPackages || !api.genealogiesMine || !api.vipOrders || !api.createVipOrder) {
setListState(packageList, 'error', '会员套餐服务初始化失败,请刷新后重试。');
setListState(orderList, 'error', '会员订单服务初始化失败,请刷新后重试。');
setStatus('error', '会员服务接口初始化失败,请刷新后重试。');
@@ -351,22 +401,38 @@
return orders;
}
function showPayment(payment) {
if (!paymentPanel || !paymentQr || !paymentText) return;
paymentPanel.hidden = false;
paymentQr.innerHTML = '';
if (typeof root.QRCode === 'function') {
new root.QRCode(paymentQr, { text: payment.codeUrl, width: 220, height: 220 });
} else {
paymentQr.textContent = payment.codeUrl;
}
paymentText.textContent = '请使用微信扫码支付' + (payment.expiresAt ? ',支付单有效期至 ' + payment.expiresAt : '');
paymentPanel.setAttribute('data-transaction-id', payment.transactionId);
}
setListState(packageList, 'loading', '正在读取会员套餐…');
setListState(orderList, 'loading', '正在读取会员订单…');
setStatus('loading', '正在读取会员服务…');
try {
var initial = await Promise.all([api.vipPackages(), api.genealogiesMine(), api.vipOrders()]);
var genealogyOptions = normalizeGenealogyOptions(initial[1]);
var initial = await Promise.all([api.vipCapability(), api.vipPackages(), api.genealogiesMine(), api.vipOrders()]);
var capability = normalizeVipCapability(initial[0]);
var genealogyOptions = normalizeGenealogyOptions(initial[2]);
var selectedContextGenealogyId = resolveContextGenealogyId(genealogyOptions, contextGenealogyId);
packages = normalizeVipPackages(initial[0]);
purchaseEnabled = capability.enabled;
packages = normalizeVipPackages(initial[1]);
renderPackages();
genealogySelect.innerHTML = renderGenealogyOptions(genealogyOptions);
if (selectedContextGenealogyId) genealogySelect.value = selectedContextGenealogyId;
renderOrders(initial[2]);
setStatus('', packages.length
renderOrders(initial[3]);
submit.disabled = !purchaseEnabled;
setStatus(purchaseEnabled ? '' : 'forbidden', purchaseEnabled && packages.length
? (selectedContextGenealogyId ? '已关联当前家谱,请选择会员套餐' : '请选择会员套餐')
: '当前没有可用会员套餐');
: (capability.disabledReason || '当前暂不能使用微信扫码支付'));
} catch (error) {
if (shouldRedirectToLogin(api, error)) {
redirectToLogin(api);
@@ -416,12 +482,14 @@
form.addEventListener('submit', async function (event) {
var body;
var validation;
var payment;
var created;
var refreshed;
var verified;
event.preventDefault();
if (writePending) return;
if (!purchaseEnabled) return setStatus('forbidden', '当前暂不能创建支付订单');
body = buildVipOrderBody({
packageId: selectedPackageId,
genealogyId: genealogySelect.value
@@ -436,13 +504,15 @@
setPendingButton(submit, true, '正在创建订单…');
setStatus('loading', '正在创建会员订单…');
try {
created = normalizeVipOrder(await api.createVipOrder(body));
if (!created) throw new Error('创建响应缺少有效会员订单信息');
payment = normalizePaymentOrder(await api.createVipOrder(body));
if (!payment) throw new Error('创建响应缺少有效微信扫码支付信息');
created = payment.order;
showPayment(payment);
refreshed = normalizeVipOrders(await api.vipOrders());
verified = refreshed.find(function (item) { return item.orderId === created.orderId; });
if (!verified) throw new Error('订单已提交,但重新读取未找到对应记录');
renderOrders(refreshed);
setStatus('', '单已创建;当前 PC 暂未开放在线支付。');
setStatus('', '支付单已创建,请使用微信扫码支付。');
} catch (error) {
if (shouldRedirectToLogin(api, error)) {
redirectToLogin(api);
@@ -454,6 +524,31 @@
setPendingButton(submit, false, '正在创建订单…');
}
});
orderList.addEventListener('click', async function (event) {
var refreshButton = event.target.closest('[data-vip-payment-refresh]');
var closeButton = event.target.closest('[data-vip-payment-close]');
var transactionId;
var paymentStatus;
if (writePending || !refreshButton && !closeButton) return;
transactionId = (refreshButton || closeButton).getAttribute(refreshButton ? 'data-vip-payment-refresh' : 'data-vip-payment-close');
writePending = true;
try {
if (closeButton) {
if (!await confirmAction('确认关闭这笔支付吗?')) return;
await api.closeVipPayment(transactionId);
setStatus('', '支付单已关闭');
} else {
paymentStatus = normalizePaymentStatus(await api.vipPaymentStatus(transactionId));
if (!paymentStatus) throw new Error('支付状态响应无效');
setStatus('', paymentStatus.status === 'SUCCESS' ? '支付成功' : '当前支付状态:' + paymentStatus.status);
}
await loadOrders();
} catch (error) {
setStatus('error', error.message || '支付状态操作失败');
} finally { writePending = false; }
});
}
return {
@@ -464,8 +559,11 @@
resolveContextGenealogyId: resolveContextGenealogyId,
buildVipOrderBody: buildVipOrderBody,
validateVipOrderBody: validateVipOrderBody,
normalizeVipCapability: normalizeVipCapability,
normalizeVipOrder: normalizeVipOrder,
normalizeVipOrders: normalizeVipOrders,
normalizePaymentOrder: normalizePaymentOrder,
normalizePaymentStatus: normalizePaymentStatus,
renderVipPackages: renderVipPackages,
renderGenealogyOptions: renderGenealogyOptions,
renderVipOrders: renderVipOrders,