From e125a5f39c73748e87d924a1e5cde7fcae18895d Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Thu, 7 May 2026 15:43:57 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=95=BF=E6=8C=89=E8=8F=9C=E5=8D=95=E8=AF=AD=E6=B3=95=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/fix-longpress-syntax.js | 119 ++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 scripts/fix-longpress-syntax.js diff --git a/scripts/fix-longpress-syntax.js b/scripts/fix-longpress-syntax.js new file mode 100644 index 0000000..37d0ee5 --- /dev/null +++ b/scripts/fix-longpress-syntax.js @@ -0,0 +1,119 @@ +/** + * 修复 show-menu-by-longpress 的错误用法 + * 将 :show-menu-by-longpress="true" 替换为 show-menu-by-longpress + * 使用方法:node scripts/fix-longpress-syntax.js + */ + +const fs = require('fs') +const path = require('path') + +// 需要处理的目录 +const dirs = [ + 'components', + 'components-diy', + 'pages', + 'pages_goods', + 'pages_order', + 'pages_promotion', + 'pages_tool', + 'uni_modules' +] + +// 排除的目录 +const excludeDirs = [ + 'node_modules', + '.git', + 'unpackage', + 'dist' +] + +/** + * 检查是否应该排除 + */ +function shouldExclude(filePath) { + return excludeDirs.some(dir => filePath.includes(dir)) +} + +/** + * 修复单个文件 + */ +function fixFile(filePath) { + let content = fs.readFileSync(filePath, 'utf-8') + let modified = false + + // 错误的写法1: :show-menu-by-longpress="true" + // 错误的写法2: :show-menu-by-longpress='true' + const wrongPatterns = [ + /:show-menu-by-longpress\s*=\s*["']true["']/gi, + /:show-menu-by-longpress\s*=\s*\{true\}/gi + ] + + wrongPatterns.forEach(pattern => { + if (pattern.test(content)) { + content = content.replace(pattern, 'show-menu-by-longpress') + modified = true + } + }) + + // 确保属性后有空格或结束符 + content = content.replace(/show-menu-by-longpress\/>/g, 'show-menu-by-longpress />') + content = content.replace(/show-menu-by-longpress>/g, 'show-menu-by-longpress >') + + if (modified) { + fs.writeFileSync(filePath, content, 'utf-8') + console.log(`✓ 已修复: ${filePath}`) + return 1 + } + + return 0 +} + +/** + * 递归遍历目录 + */ +function walkDir(dir, callback) { + if (shouldExclude(dir)) return + + try { + const files = fs.readdirSync(dir) + + files.forEach(file => { + const filePath = path.join(dir, file) + + if (shouldExclude(filePath)) return + + const stat = fs.statSync(filePath) + + if (stat.isDirectory()) { + walkDir(filePath, callback) + } else if (file.endsWith('.vue')) { + callback(filePath) + } + }) + } catch (err) { + console.error(`✗ 无法读取目录: ${dir}`) + } +} + +// 主程序 +let totalFiles = 0 +let fixedFiles = 0 + +console.log('开始修复 show-menu-by-longpress 语法...\n') + +dirs.forEach(dir => { + const fullPath = path.join(__dirname, '..', dir) + if (fs.existsSync(fullPath)) { + walkDir(fullPath, (filePath) => { + totalFiles++ + fixedFiles += fixFile(filePath) + }) + } +}) + +console.log(`\n修复完成!`) +console.log(`总共扫描: ${totalFiles} 个文件`) +console.log(`成功修复: ${fixedFiles} 个文件`) +console.log(`\n正确的用法:`); +console.log(` `); +console.log(` (如果需要动态控制)`);