From 575145eae914c549bc6cacdd589544e5e7b41ae1 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Fri, 10 Jul 2026 17:45:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(pages.json&scripts):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=E5=8D=A0?= =?UTF-8?q?=E4=BD=8D=E7=AC=A6=E6=B3=A8=E5=85=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 为商品详情页添加所有diy-*组件的占位符配置 2. 重构占位符注入脚本,实现组件使用的递归检测 3. 移除原有的简单字符串匹配,改用导入链追踪准确判断组件使用情况 --- pages.json | 58 +++++++++++++++++++++++++++- scripts/inject-placeholder.js | 71 ++++++++++++++++++++++++++++++----- 2 files changed, 118 insertions(+), 11 deletions(-) diff --git a/pages.json b/pages.json index 56ff5c6..b7e8d21 100644 --- a/pages.json +++ b/pages.json @@ -218,7 +218,63 @@ { "path": "detail", "style": { - "navigationBarTitleText": "商品详情" + "navigationBarTitleText": "商品详情", + "componentPlaceholder": { + "diy-article": "view", + "diy-audio": "view", + "diy-bargain": "view", + "diy-bottom-nav": "view", + "diy-category": "view", + "diy-category-item": "view", + "diy-channel-list": "view", + "diy-channel-video": "view", + "diy-comp-extend": "view", + "diy-coupon": "view", + "diy-digit": "view", + "diy-fenxiao-goods-list": "view", + "diy-float-btn": "view", + "diy-follow-official-account": "view", + "diy-form": "view", + "diy-goods-brand": "view", + "diy-goods-list": "view", + "diy-goods-recommend": "view", + "diy-graphic-nav": "view", + "diy-group": "view", + "diy-groupbuy": "view", + "diy-horz-blank": "view", + "diy-horz-line": "view", + "diy-hot-area": "view", + "diy-icon": "view", + "diy-image-nav": "view", + "diy-img-ads": "view", + "diy-index-page": "view", + "diy-kefu": "view", + "diy-listmenu": "view", + "diy-live": "view", + "diy-many-goods-list": "view", + "diy-map": "view", + "diy-member-info": "view", + "diy-member-my-order": "view", + "diy-merch-list": "view", + "diy-notes": "view", + "diy-notice": "view", + "diy-payment-qrcode": "view", + "diy-picture": "view", + "diy-pinfan": "view", + "diy-pintuan": "view", + "diy-presale": "view", + "diy-quick-nav": "view", + "diy-rich-text": "view", + "diy-rubik-cube": "view", + "diy-search": "view", + "diy-seckill": "view", + "diy-store": "view", + "diy-store-label": "view", + "diy-tab": "view", + "diy-text": "view", + "diy-video": "view", + "diy-video-list": "view" + } } }, { diff --git a/scripts/inject-placeholder.js b/scripts/inject-placeholder.js index edc79d3..ad10a84 100644 --- a/scripts/inject-placeholder.js +++ b/scripts/inject-placeholder.js @@ -99,18 +99,69 @@ function lastMeaningfulIdx(bodyLines) { } /** - * 检查 page 的 .vue 文件是否引用了 组件. - * 简单的字符串检查, 包含 . + */ +const _usesDiyCache = new Map(); +const _importRe = /import\s+[^'"`;\n]*['"]([^'"`]+\.vue)['"]/g; + +/** + * 检查一个 .vue 文件是否(传递)使用了 组件. + * 不仅看模板里是否含 + */ +function fileUsesDiy(relVuePath) { + if (!relVuePath) return false; + if (_usesDiyCache.has(relVuePath)) return _usesDiyCache.get(relVuePath); + // 暂存 false 以打破循环引用 + _usesDiyCache.set(relVuePath, false); + const abs = path.join(PROJECT_ROOT, relVuePath + '.vue'); + let content; + try { + content = fs.readFileSync(abs, 'utf-8'); + } catch (e) { + return false; + } + if (/ 组件. + * fullPagePath 是 pages.json 中拼接的页面路径, 如 "pages_goods/detail". */ function pageUsesDiy(fullPagePath) { - if (!fullPagePath) return false; - const vuePath = path.join(PROJECT_ROOT, fullPagePath + '.vue'); - try { - const content = fs.readFileSync(vuePath, 'utf-8'); - return /