Просмотр исходного кода

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

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu 2 недель назад
Родитель
Сommit
80d238d31d

+ 18 - 0
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))
+  )
+}

+ 28 - 0
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' }]
+  )
+})