perf : 优化处理岗位信息中,对薪资区间测处理(之前语音播放会有问题)

This commit is contained in:
2025-12-25 16:14:11 +08:00
parent 3065618610
commit 0704896694
3 changed files with 68 additions and 33 deletions

View File

@@ -468,6 +468,7 @@ export const useAudioSpeak = (config = {}) => {
let match; let match;
let lastJobEndIndex = 0; let lastJobEndIndex = 0;
let firstJobStartIndex = -1; let firstJobStartIndex = -1;
while ((match = jobRegex.exec(markdown)) !== null) { while ((match = jobRegex.exec(markdown)) !== null) {
const jobStr = match[1]; const jobStr = match[1];
try { try {
@@ -481,17 +482,28 @@ export const useAudioSpeak = (config = {}) => {
console.warn('JSON 解析失败', e); console.warn('JSON 解析失败', e);
} }
} }
const guideText = firstJobStartIndex > 0 ? const guideText = firstJobStartIndex > 0 ?
markdown.slice(0, firstJobStartIndex).trim() : ''; markdown.slice(0, firstJobStartIndex).trim() : '';
const endingText = lastJobEndIndex < markdown.length ? const endingText = lastJobEndIndex < markdown.length ?
markdown.slice(lastJobEndIndex).trim() : ''; markdown.slice(lastJobEndIndex).trim() : '';
const jobTexts = jobs.map((job, index) => { const jobTexts = jobs.map((job, index) => {
return `${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${job.salary},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}`; // 处理薪资格式:将 "数字-数字" 中的 '-' 替换为 '到'
let salaryText = job.salary;
if (salaryText) {
// 匹配 "数字-数字" 的格式15000-18000元/月)
salaryText = salaryText.replace(/(\d+)-(\d+)/g, '$1到$2');
}
return `${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${salaryText},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}`;
}); });
const finalTextParts = []; const finalTextParts = [];
if (guideText) finalTextParts.push(guideText); if (guideText) finalTextParts.push(guideText);
finalTextParts.push(...jobTexts); finalTextParts.push(...jobTexts);
if (endingText) finalTextParts.push(endingText); if (endingText) finalTextParts.push(endingText);
return finalTextParts.join('\n'); return finalTextParts.join('\n');
} }

View File

@@ -222,8 +222,7 @@ export function useTTSPlayer() {
* 文本提取工具函数 (保持不变) * 文本提取工具函数 (保持不变)
*/ */
function extractSpeechText(markdown) { function extractSpeechText(markdown) {
if (!markdown || typeof markdown !== 'string') return ''; // 增加类型安全检查 if (!markdown || markdown.indexOf('job-json') === -1) {
if (markdown.indexOf('job-json') === -1) {
return markdown; return markdown;
} }
const jobRegex = /``` job-json\s*({[\s\S]*?})\s*```/g; const jobRegex = /``` job-json\s*({[\s\S]*?})\s*```/g;
@@ -231,6 +230,7 @@ function extractSpeechText(markdown) {
let match; let match;
let lastJobEndIndex = 0; let lastJobEndIndex = 0;
let firstJobStartIndex = -1; let firstJobStartIndex = -1;
while ((match = jobRegex.exec(markdown)) !== null) { while ((match = jobRegex.exec(markdown)) !== null) {
const jobStr = match[1]; const jobStr = match[1];
try { try {
@@ -244,17 +244,28 @@ function extractSpeechText(markdown) {
console.warn('JSON 解析失败', e); console.warn('JSON 解析失败', e);
} }
} }
const guideText = firstJobStartIndex > 0 ? const guideText = firstJobStartIndex > 0 ?
markdown.slice(0, firstJobStartIndex).trim() : ''; markdown.slice(0, firstJobStartIndex).trim() : '';
const endingText = lastJobEndIndex < markdown.length ? const endingText = lastJobEndIndex < markdown.length ?
markdown.slice(lastJobEndIndex).trim() : ''; markdown.slice(lastJobEndIndex).trim() : '';
const jobTexts = jobs.map((job, index) => { const jobTexts = jobs.map((job, index) => {
return `${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${job.salary},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}`; // 处理薪资格式:将 "数字-数字" 中的 '-' 替换为 '到'
let salaryText = job.salary;
if (salaryText) {
// 匹配 "数字-数字" 的格式15000-18000元/月)
salaryText = salaryText.replace(/(\d+)-(\d+)/g, '$1到$2');
}
return `${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${salaryText},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}`;
}); });
const finalTextParts = []; const finalTextParts = [];
if (guideText) finalTextParts.push(guideText); if (guideText) finalTextParts.push(guideText);
finalTextParts.push(...jobTexts); finalTextParts.push(...jobTexts);
if (endingText) finalTextParts.push(endingText); if (endingText) finalTextParts.push(endingText);
return finalTextParts.join('\n'); return finalTextParts.join('\n');
} }

View File

@@ -216,6 +216,7 @@ function extractSpeechText(markdown) {
let match; let match;
let lastJobEndIndex = 0; let lastJobEndIndex = 0;
let firstJobStartIndex = -1; let firstJobStartIndex = -1;
while ((match = jobRegex.exec(markdown)) !== null) { while ((match = jobRegex.exec(markdown)) !== null) {
const jobStr = match[1]; const jobStr = match[1];
try { try {
@@ -229,16 +230,27 @@ function extractSpeechText(markdown) {
console.warn('JSON 解析失败', e); console.warn('JSON 解析失败', e);
} }
} }
const guideText = firstJobStartIndex > 0 ? const guideText = firstJobStartIndex > 0 ?
markdown.slice(0, firstJobStartIndex).trim() : ''; markdown.slice(0, firstJobStartIndex).trim() : '';
const endingText = lastJobEndIndex < markdown.length ? const endingText = lastJobEndIndex < markdown.length ?
markdown.slice(lastJobEndIndex).trim() : ''; markdown.slice(lastJobEndIndex).trim() : '';
const jobTexts = jobs.map((job, index) => { const jobTexts = jobs.map((job, index) => {
return `${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${job.salary},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}`; // 处理薪资格式:将 "数字-数字" 中的 '-' 替换为 '到'
let salaryText = job.salary;
if (salaryText) {
// 匹配 "数字-数字" 的格式15000-18000元/月)
salaryText = salaryText.replace(/(\d+)-(\d+)/g, '$1到$2');
}
return `${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${salaryText},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}`;
}); });
const finalTextParts = []; const finalTextParts = [];
if (guideText) finalTextParts.push(guideText); if (guideText) finalTextParts.push(guideText);
finalTextParts.push(...jobTexts); finalTextParts.push(...jobTexts);
if (endingText) finalTextParts.push(endingText); if (endingText) finalTextParts.push(endingText);
return finalTextParts.join('\n'); return finalTextParts.join('\n');
} }