From 349019863b8b69ecf16a9d652d93f89802679d4d Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Thu, 13 Aug 2026 11:31:14 +0800 Subject: [PATCH] feat(mobile-h5): add formatCornerIndex for OA list corner badges. Co-authored-by: Cursor --- mobile-h5/utils/oa-corner-index.js | 12 ++++++++++++ mobile-h5/utils/oa-corner-index.test.js | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 mobile-h5/utils/oa-corner-index.js create mode 100644 mobile-h5/utils/oa-corner-index.test.js diff --git a/mobile-h5/utils/oa-corner-index.js b/mobile-h5/utils/oa-corner-index.js new file mode 100644 index 00000000..85738352 --- /dev/null +++ b/mobile-h5/utils/oa-corner-index.js @@ -0,0 +1,12 @@ +// mobile-h5/utils/oa-corner-index.js +/** + * @param {number} n 从 1 起的序号 + * @returns {string} + */ +export function formatCornerIndex(n) { + const num = Number(n) + if (!Number.isFinite(num) || num < 1) return '01' + const i = Math.floor(num) + if (i < 10) return '0' + i + return String(i) +} diff --git a/mobile-h5/utils/oa-corner-index.test.js b/mobile-h5/utils/oa-corner-index.test.js new file mode 100644 index 00000000..6b73f7d7 --- /dev/null +++ b/mobile-h5/utils/oa-corner-index.test.js @@ -0,0 +1,12 @@ +// mobile-h5/utils/oa-corner-index.test.js +import assert from 'node:assert/strict' +import { formatCornerIndex } from './oa-corner-index.js' + +assert.equal(formatCornerIndex(1), '01') +assert.equal(formatCornerIndex(9), '09') +assert.equal(formatCornerIndex(10), '10') +assert.equal(formatCornerIndex(11), '11') +assert.equal(formatCornerIndex(99), '99') +assert.equal(formatCornerIndex(100), '100') + +console.log('oa-corner-index: ok')