From 80d238d31dea38df1f8daa7e8206549a78e61df1 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Sat, 17 Oct 2026 10:53:11 +0800 Subject: [PATCH] feat(mobile-oa-h5): add payment-entry helpers for readonly protocol view Co-authored-by: Cursor --- mobile-oa-h5/src/market/payment-entry.js | 18 ++++++++++++ mobile-oa-h5/src/market/payment-entry.test.js | 28 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 mobile-oa-h5/src/market/payment-entry.js create mode 100644 mobile-oa-h5/src/market/payment-entry.test.js diff --git a/mobile-oa-h5/src/market/payment-entry.js b/mobile-oa-h5/src/market/payment-entry.js new file mode 100644 index 00000000..b261a1e6 --- /dev/null +++ b/mobile-oa-h5/src/market/payment-entry.js @@ -0,0 +1,18 @@ +/** 缴费信息入口进入协议详情时的只读压制 */ +const PROTOCOL_WRITE_CODES = new Set(['edit', 'delete', 'create']) + +export function isPaymentEntryView(query) { + return String(query?.from || '') === 'payment' +} + +function actionCode(action) { + return typeof action === 'string' + ? action + : String(action?.code || action?.action || action?.key || '').trim() +} + +export function filterProtocolActionsForPaymentEntry(actions) { + return (Array.isArray(actions) ? actions : []).filter( + (action) => !PROTOCOL_WRITE_CODES.has(actionCode(action)) + ) +} diff --git a/mobile-oa-h5/src/market/payment-entry.test.js b/mobile-oa-h5/src/market/payment-entry.test.js new file mode 100644 index 00000000..02e08c3f --- /dev/null +++ b/mobile-oa-h5/src/market/payment-entry.test.js @@ -0,0 +1,28 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import { + isPaymentEntryView, + filterProtocolActionsForPaymentEntry +} from './payment-entry.js' + +test('isPaymentEntryView detects from=payment', () => { + assert.equal(isPaymentEntryView({ from: 'payment' }), true) + assert.equal(isPaymentEntryView({ from: 'Payment' }), false) + assert.equal(isPaymentEntryView({}), false) + assert.equal(isPaymentEntryView(null), false) +}) + +test('filterProtocolActionsForPaymentEntry hides edit and delete', () => { + assert.deepEqual( + filterProtocolActionsForPaymentEntry(['view', 'edit', 'delete', 'create']), + ['view'] + ) + assert.deepEqual( + filterProtocolActionsForPaymentEntry([ + { code: 'edit' }, + { code: 'delete' }, + { code: 'view' } + ]), + [{ code: 'view' }] + ) +})