zjk
2026-07-17 4ce2fc03645cd439955c0a16293f33d727fdb94e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('fs');
const path = require('path');
 
function findVueFiles(dir, fileList = []) {
  const files = fs.readdirSync(dir);
  files.forEach((file) => {
    const filePath = path.join(dir, file);
    if (fs.statSync(filePath).isDirectory()) {
      findVueFiles(filePath, fileList);
    } else if (filePath.endsWith('.vue')) {
      fileList.push(filePath);
    }
  });
  return fileList;
}
 
const allVueFiles = findVueFiles(path.join(__dirname, 'src'));
let modifiedCount = 0;
 
allVueFiles.forEach((file) => {
  let content = fs.readFileSync(file, 'utf8');
  
  if (content.includes('src="/src/assets/element-img/no-data.png"')) {
    // 1. Replace all occurrences
    content = content.replace(/src="\/src\/assets\/element-img\/no-data\.png"/g, ':src="noDataImg"');
    
    // 2. Check if already imported
    if (!content.includes('noDataImg') || !content.includes('@/assets/element-img/no-data.png')) {
      const scriptSetupMatch = content.match(/<script\s+setup[^>]*>/);
      if (scriptSetupMatch) {
        const insertIndex = scriptSetupMatch.index + scriptSetupMatch[0].length;
        const importStr = `\nimport noDataImg from '@/assets/element-img/no-data.png'`;
        content = content.slice(0, insertIndex) + importStr + content.slice(insertIndex);
      } else {
        console.log(`Warning: No <script setup> found in ${file}`);
      }
    }
    
    fs.writeFileSync(file, content, 'utf8');
    modifiedCount++;
    console.log(`Modified: ${file}`);
  }
});
 
console.log(`Total files modified: ${modifiedCount}`);