diff --git a/assets/js/credits.js b/assets/js/credits.js index ff11bdfe..d23d02ae 100644 --- a/assets/js/credits.js +++ b/assets/js/credits.js @@ -392,26 +392,6 @@ }); applyMethodVisibility((modal.querySelector('input[name="payment_method"]') || {}).value || ''); if (!form) return; - // 收款渠道由后台拖拽结构定义:切换时同步收款信息提示与渠道说明。 - var methodField = form.querySelector('[data-jio-withdraw-method]'); - var accountField = form.querySelector('[data-jio-withdraw-account]'); - var noteField = form.querySelector('[data-jio-withdraw-note]'); - function syncChannelHint() { - if (!methodField) return; - var option = methodField.options[methodField.selectedIndex]; - if (!option) return; - var hint = option.getAttribute('data-hint') || ''; - var note = option.getAttribute('data-note') || ''; - if (accountField) accountField.setAttribute('placeholder', hint || '姓名 + 账户 / 卡号'); - if (noteField) { - noteField.textContent = note; - noteField.hidden = note === ''; - } - } - if (methodField) { - methodField.addEventListener('change', syncChannelHint); - syncChannelHint(); - } resetOperationKeyOnChange(form); form.addEventListener('submit', function (e) { e.preventDefault(); @@ -826,6 +806,26 @@ btn.addEventListener('click', function () { closeModal(modal); }); }); if (!form) return; + // 收款渠道由后台拖拽结构定义:切换时同步收款信息提示与渠道说明。 + var methodField = form.querySelector('[data-jio-withdraw-method]'); + var accountField = form.querySelector('[data-jio-withdraw-account]'); + var noteField = form.querySelector('[data-jio-withdraw-note]'); + function syncChannelHint() { + if (!methodField) return; + var option = methodField.options[methodField.selectedIndex]; + if (!option) return; + var hint = option.getAttribute('data-hint') || ''; + var note = option.getAttribute('data-note') || ''; + if (accountField) accountField.setAttribute('placeholder', hint || '姓名 + 账户 / 卡号'); + if (noteField) { + noteField.textContent = note; + noteField.hidden = note === ''; + } + } + if (methodField) { + methodField.addEventListener('change', syncChannelHint); + syncChannelHint(); + } resetOperationKeyOnChange(form); form.addEventListener('submit', function (e) { e.preventDefault(); diff --git a/tests/widget-system/payment-withdrawal-channels-contract.test.cjs b/tests/widget-system/payment-withdrawal-channels-contract.test.cjs index 9c3fedb7..ef8f2989 100644 --- a/tests/widget-system/payment-withdrawal-channels-contract.test.cjs +++ b/tests/widget-system/payment-withdrawal-channels-contract.test.cjs @@ -58,8 +58,14 @@ test('前台弹窗与后端校验都按渠道 key 工作', () => { assert.match(modal, /data-note="<\?php echo esc_attr/); assert.match(modal, /data-jio-withdraw-note/); - // 切换渠道时同步提示文案。 - assert.match(client, /function syncChannelHint\(\)/); + // 切换渠道时同步提示文案,且必须挂在提现弹窗的初始化里 + // (同一文件还有充值弹窗,挂错块会让整段逻辑变成死代码)。 + assert.equal((client.match(/function syncChannelHint\(\)/g) || []).length, 1); + const initAt = client.indexOf('function initWithdraw()'); + const syncAt = client.indexOf('function syncChannelHint()'); + const nextFnAt = client.indexOf(String.fromCharCode(10) + String.fromCharCode(9) + 'function ', syncAt + 1); + assert.ok(initAt >= 0 && syncAt > initAt, 'syncChannelHint must live inside initWithdraw()'); + assert.ok(nextFnAt === -1 || syncAt < nextFnAt, 'syncChannelHint must not leak past initWithdraw()'); assert.match(client, /methodField\.addEventListener\('change', syncChannelHint\)/); // 后端只校验渠道存在且启用,不再限定内置两项。