feat(mobile-oa-h5): add payment-entry helpers for readonly protocol view

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-10-17 10:53:11 +08:00
1 parent 526c9029c8
commit 80d238d31d
2 files changed
+46

No files matched your search

+18
View File
@@ -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))
)
}
@@ -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' }]
)
})