direct-fix-placeholder-issues.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const fs = require('fs');
  2. const path = require('path');
  3. // 定义需要修复的文件路径
  4. const filesToFix = [
  5. {
  6. path: path.join(__dirname, 'src', 'app', 'shared', 'components', 'designer-nav', 'designer-nav.html'),
  7. type: 'html'
  8. },
  9. {
  10. path: path.join(__dirname, 'src', 'app', 'pages', 'admin', 'admin-layout', 'admin-layout.ts'),
  11. type: 'ts'
  12. },
  13. {
  14. path: path.join(__dirname, 'src', 'app', 'pages', 'customer-service', 'customer-service-layout', 'customer-service-layout.html'),
  15. type: 'html'
  16. },
  17. {
  18. path: path.join(__dirname, 'src', 'app', 'pages', 'customer-service', 'consultation-order', 'consultation-order.ts'),
  19. type: 'ts'
  20. },
  21. {
  22. path: path.join(__dirname, 'src', 'app', 'pages', 'customer-service', 'project-detail', 'project-detail.html'),
  23. type: 'html'
  24. },
  25. {
  26. path: path.join(__dirname, 'src', 'app', 'pages', 'login', 'set-admin-role.html'),
  27. type: 'html'
  28. },
  29. {
  30. path: path.join(__dirname, 'src', 'app', 'pages', 'team-leader', 'knowledge-base', 'knowledge-base.ts'),
  31. type: 'ts'
  32. },
  33. {
  34. path: path.join(__dirname, 'src', 'app', 'services', 'auth.service.ts'),
  35. type: 'ts'
  36. }
  37. ];
  38. // 修复HTML文件
  39. function fixHtmlFile(filePath) {
  40. try {
  41. let content = fs.readFileSync(filePath, 'utf8');
  42. // 修复img标签内包含div的问题
  43. const fixedContent = content.replace(/<img\s+src="<div\s+style="([^"]*)">([^<]*)<\/div>"\s+alt="([^"]*)"\s+class="([^"]*)"\s*\/?>/g,
  44. '<div style="$1" class="$4" title="$3">$2</div>');
  45. if (content !== fixedContent) {
  46. fs.writeFileSync(filePath, fixedContent, 'utf8');
  47. console.log(`已修复HTML文件: ${filePath}`);
  48. return 1;
  49. }
  50. } catch (error) {
  51. console.error(`修复HTML文件失败: ${filePath}`, error);
  52. }
  53. return 0;
  54. }
  55. // 修复TypeScript文件
  56. function fixTsFile(filePath) {
  57. try {
  58. let content = fs.readFileSync(filePath, 'utf8');
  59. // 修复avatar属性的格式问题
  60. const fixedContent = content.replace(/avatar:\s*'\{\s*width:\s*(\d+),\s*height:\s*(\d+),\s*bgColor:\s*'(#[0-9A-Fa-f]+)',\s*textColor:\s*'(#[0-9A-Fa-f]+)',\s*text:\s*'([^']*)'\s*\}'/g,
  61. (match, width, height, bgColor, textColor, text) => {
  62. // 生成SVG data URL
  63. const svg = `data:image/svg+xml,%3Csvg width='${width}' height='${height}' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='100%25' height='100%25' fill='${encodeURIComponent(bgColor)}'/%3E%3Ctext x='50%25' y='50%25' font-family='Arial' font-size='${Math.min(parseInt(width), parseInt(height)) / 3}' font-weight='bold' text-anchor='middle' fill='${encodeURIComponent(textColor)}' dy='0.3em'%3E${encodeURIComponent(text)}%3C/text%3E%3C/svg%3E`;
  64. return `avatar: '${svg}'`;
  65. });
  66. if (content !== fixedContent) {
  67. fs.writeFileSync(filePath, fixedContent, 'utf8');
  68. console.log(`已修复TypeScript文件: ${filePath}`);
  69. return 1;
  70. }
  71. } catch (error) {
  72. console.error(`修复TypeScript文件失败: ${filePath}`, error);
  73. }
  74. return 0;
  75. }
  76. // 执行修复
  77. console.log('开始直接修复placeholder链接问题...');
  78. let totalFixed = 0;
  79. filesToFix.forEach(file => {
  80. if (file.type === 'html') {
  81. totalFixed += fixHtmlFile(file.path);
  82. } else if (file.type === 'ts') {
  83. totalFixed += fixTsFile(file.path);
  84. }
  85. });
  86. console.log(`直接修复完成!总共修复了 ${totalFixed} 个文件。`);