From 29ab45033df0134be8035de34164538d8aef5528 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 9 Jun 2026 10:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TUICallKit-Vue3/pages.json | 10 +++++++++- TUICallKit-Vue3/tongji/utils/voiceParse.js | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/TUICallKit-Vue3/pages.json b/TUICallKit-Vue3/pages.json index 7e29b5ae..0ab33978 100644 --- a/TUICallKit-Vue3/pages.json +++ b/TUICallKit-Vue3/pages.json @@ -204,7 +204,15 @@ "navigationStyle": "custom", "navigationBarTitleText": "日常护理", "backgroundColor": "#f4fbf4", - "enablePullDownRefresh": true + "enablePullDownRefresh": true, + "mp-weixin": { + "usingPlugins": { + "WechatSI": { + "version": "0.3.5", + "provider": "wx069ba97219f66d99" + } + } + } } }, { diff --git a/TUICallKit-Vue3/tongji/utils/voiceParse.js b/TUICallKit-Vue3/tongji/utils/voiceParse.js index 95daec44..d0c3339a 100644 --- a/TUICallKit-Vue3/tongji/utils/voiceParse.js +++ b/TUICallKit-Vue3/tongji/utils/voiceParse.js @@ -7,7 +7,7 @@ * - 饮食(早 / 午 / 晚餐 + 备注) * - 运动(类型 / 时长 / 强度) * - * 兼容中文数字(六点五 / 一百二十)与阿拉伯数字(6.5 / 120)。 + * 兼容中文数字(六点五 / 一百二十 / 一百二)与阿拉伯数字(6.5 / 120)。 * 纯前端解析,无网络依赖,识别失败时返回空对象。 */ @@ -18,18 +18,23 @@ const CN_DIGIT = { } const CN_UNIT = { 十: 10, 拾: 10, 百: 100, 佰: 100, 千: 1000, 仟: 1000, 万: 10000, 亿: 100000000 } -/** 中文整数串 → 数字,例如 "一百二十" → 120、"八十" → 80、"十" → 10 */ +/** 中文整数串 → 数字,例如 "一百二十" → 120、"八十" → 80、"十" → 10、"一百二" → 120 */ function cnIntToNumber(s) { let total = 0 let section = 0 let number = 0 let hadUnit = false + let lastUnit = 0 + let sawZeroAfterUnit = false for (const ch of s) { if (CN_DIGIT[ch] !== undefined) { number = CN_DIGIT[ch] + if (number === 0) sawZeroAfterUnit = true } else if (CN_UNIT[ch] !== undefined) { hadUnit = true const unit = CN_UNIT[ch] + lastUnit = unit + sawZeroAfterUnit = false if (unit >= 10000) { section = (section + number) * unit total += section @@ -41,7 +46,6 @@ function cnIntToNumber(s) { number = 0 } } - const val = total + section + number // 没有任何单位且为纯数字串(如 "一二零")时按位拼接更符合口语 if (!hadUnit && s.length > 1) { let joined = '' @@ -50,7 +54,11 @@ function cnIntToNumber(s) { } if (joined) return Number(joined) } - return val + // 口语省略尾部单位:"一百二" → 120、"一千五" → 1500(避开 "一百零五" 这类带零的) + if (number > 0 && lastUnit >= 100 && !sawZeroAfterUnit) { + number = number * (lastUnit / 10) + } + return total + section + number } /** 中文数字串(含小数点)→ 数字,例如 "六点五" → 6.5 */ @@ -110,8 +118,7 @@ function textAfter(text, keys, stopKeys = []) { // 去掉口语连接词 rest = rest.replace(/^[是为吃了喝了吃的喝的有打了用了::,,、。\s]+/, '') let end = rest.length - const stopRe = /[,,。.;;!!??\n]/ - const mStop = rest.match(stopRe) + const mStop = rest.match(/[,,。.;;!!??\n]/) if (mStop && mStop.index < end) end = mStop.index for (const sk of stopKeys) { const si = rest.indexOf(sk) @@ -242,7 +249,7 @@ export function parseExercise(raw) { const t = normalizeNumbers(raw) const result = {} - let durMatch = t.match(/(\d+(?:\.\d+)?)\s*(个小时|小时|钟头|时|分钟|分)/) + const durMatch = t.match(/(\d+(?:\.\d+)?)\s*(个小时|小时|钟头|时|分钟|分)/) if (durMatch) { const val = parseFloat(durMatch[1]) const isHour = /个小时|小时|钟头|时/.test(durMatch[2])