From 1cf6d1e5883cca7793884ca4151c70049cded9f0 Mon Sep 17 00:00:00 2001
From: 13404089107 <puwei@sinata.cn>
Date: 星期四, 30 四月 2026 19:12:56 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/tcm-training
---
traditionalApp/utils/utils.js | 52 +++++++++++++++++++++++++++++++++++++---------------
1 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/traditionalApp/utils/utils.js b/traditionalApp/utils/utils.js
index 7032f75..ba40388 100644
--- a/traditionalApp/utils/utils.js
+++ b/traditionalApp/utils/utils.js
@@ -258,6 +258,10 @@
* 从 URL、纯文本、对象或扫码内容中提取 6 位邀请码。
*/
export const extractInviteCode = (value) => {
+ const directInviteCode = extractObjectFieldFromAny(value, 'inviteCode')
+ if (directInviteCode) {
+ return normalizeInviteCodeText(directInviteCode)
+ }
const normalizedValue = normalizeInvitePayloadText(value)
if (!normalizedValue) {
return ''
@@ -270,8 +274,7 @@
if (queryMatchedInviteCode && queryMatchedInviteCode[1]) {
return normalizeInviteCodeText(decodeURIComponent(queryMatchedInviteCode[1]))
}
- const matchedInviteCode = normalizedValue.toUpperCase().match(/[A-Z0-9]{6}/)
- return matchedInviteCode ? matchedInviteCode[0] : ''
+ return normalizeInviteCodeText(normalizedValue)
}
/**
@@ -294,26 +297,45 @@
}
/**
+ * 从对象或 JSON 字符串中读取指定字段。
+ */
+const extractObjectFieldFromAny = (value, fieldName) => {
+ if (!value) {
+ return ''
+ }
+ if (typeof value === 'string') {
+ return extractObjectField(value, fieldName)
+ }
+ if (typeof value !== 'object') {
+ return ''
+ }
+ const directValue = value[fieldName]
+ if (typeof directValue === 'string') {
+ return directValue
+ }
+ const candidateKeys = ['bindData', 'data', 'channelData', 'params', 'wakeUpData']
+ for (const key of candidateKeys) {
+ const nestedValue = value[key]
+ if (!nestedValue || nestedValue === value) {
+ continue
+ }
+ const nestedFieldValue = extractObjectFieldFromAny(nestedValue, fieldName)
+ if (nestedFieldValue) {
+ return nestedFieldValue
+ }
+ }
+ return ''
+}
+
+/**
* 从 JSON 字符串中读取指定字段。
*/
const extractObjectField = (value, fieldName) => {
try {
- const parsedValue = JSON.parse(value)
- if (!parsedValue || typeof parsedValue !== 'object') {
- return ''
- }
- const directValue = parsedValue[fieldName]
- if (typeof directValue === 'string') {
- return directValue
- }
- const bindDataValue = parsedValue.bindData || parsedValue.data || parsedValue.params
- if (bindDataValue && bindDataValue !== value) {
- return extractObjectField(normalizeInvitePayloadText(bindDataValue), fieldName)
- }
+ return extractObjectFieldFromAny(JSON.parse(value), fieldName)
} catch {
return ''
}
- return ''
}
/**
--
Gitblit v1.7.1