Files
2026-05-08 03:06:24 +08:00

100 lines
3.1 KiB
JavaScript

const fs = require('fs');
// 所有需要修复的文件
const files = [
'src/views/order/OrderList.vue',
'src/views/order/OrderFollow.vue',
'src/views/order/OrderRecheck.vue',
'src/views/order/OrderTracking.vue',
'src/views/quote/QuoteGenerate.vue'
];
// 中文文本修复映射
const textReplacements = {
'报价表管': '报价表管理',
'新建报价': '新建报价表',
'标签页导': '标签页导航',
'报价表生': '报价表生成',
'搜索报价单号、客户名': '搜索报价单号、客户名称',
'全部状': '全部状态',
'已发': '已发送',
'已接': '已接受',
'已拒': '已拒绝',
'已过': '已过期',
'方案A (标准': '方案A (标准型)',
'方案B (升级': '方案B (升级型)'
};
let totalFixed = 0;
files.forEach(file => {
try {
let content = fs.readFileSync(file, 'utf8');
let modified = false;
// 修复破碎的 HTML 标签
const tagPatterns = [
{ regex: />([^<]+)\/option>/g, replace: '>$1</option>' },
{ regex: />([^<]+)\/th>/g, replace: '>$1</th>' },
{ regex: />([^<]+)\/td>/g, replace: '>$1</td>' },
{ regex: />([^<]+)\/button>/g, replace: '>$1</button>' },
{ regex: />([^<]+)\/label>/g, replace: '>$1</label>' },
{ regex: />([^<]+)\/span>/g, replace: '>$1</span>' },
{ regex: />([^<]+)\/p>/g, replace: '>$1</p>' },
{ regex: />([^<]+)\/h[1-6]>/g, replace: '>$1</h$2>' },
{ regex: />([^<]+)\/li>/g, replace: '>$1</li>' },
{ regex: />([^<]+)\/a>/g, replace: '>$1</a>' },
{ regex: />([^<]+)\/div>/g, replace: '>$1</div>' },
{ regex: /title="([^"]+)>/g, replace: 'title="$1">' }
];
tagPatterns.forEach(pattern => {
const matches = content.match(pattern.regex);
if (matches) {
matches.forEach(match => {
const fixed = match.replace(pattern.regex, pattern.replace);
if (fixed !== match) {
content = content.split(match).join(fixed);
modified = true;
}
});
}
});
// 修复破碎的 Vue 插值表达式
const interpolationMatches = content.match(/\{\{[^}]*\?[^}]*'[^']*'/g);
if (interpolationMatches) {
interpolationMatches.forEach(match => {
// 检查是否缺少闭合的引号
const singleQuotes = (match.match(/'/g) || []).length;
if (singleQuotes % 2 !== 0) {
// 找到缺失的位置并修复
const fixed = match + "'";
content = content.split(match).join(fixed);
modified = true;
}
});
}
// 修复中文文本
Object.keys(textReplacements).forEach(broken => {
if (content.includes(broken)) {
content = content.split(broken).join(textReplacements[broken]);
modified = true;
}
});
if (modified) {
fs.writeFileSync(file, content, 'utf8');
console.log('Fixed: ' + file);
totalFixed++;
} else {
console.log('No changes: ' + file);
}
} catch(e) {
console.log('Error fixing ' + file + ': ' + e.message);
}
});
console.log('\nTotal fixed: ' + totalFixed + ' files');