From 03167ec81343fb8bf8967da13768a1137c89b24d Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期三, 01 四月 2026 08:48:46 +0800
Subject: [PATCH] #前端
---
rsf-design/src/router/core/ComponentLoader.js | 39 ++++++++++++++++++++++++++++++++++++---
1 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/rsf-design/src/router/core/ComponentLoader.js b/rsf-design/src/router/core/ComponentLoader.js
index eaf91b0..55f1490 100644
--- a/rsf-design/src/router/core/ComponentLoader.js
+++ b/rsf-design/src/router/core/ComponentLoader.js
@@ -2,6 +2,15 @@
class ComponentLoader {
constructor() {
this.modules = import.meta.glob('../../views/**/*.vue')
+ this.warmPromises = new Map()
+ }
+ resolveModule(componentPath) {
+ if (!componentPath) {
+ return null
+ }
+ const fullPath = `../../views${componentPath}.vue`
+ const fullPathWithIndex = `../../views${componentPath}/index.vue`
+ return this.modules[fullPath] || this.modules[fullPathWithIndex] || null
}
/**
* 鍔犺浇缁勪欢
@@ -10,10 +19,10 @@
if (!componentPath) {
return this.createEmptyComponent()
}
- const fullPath = `../../views${componentPath}.vue`
- const fullPathWithIndex = `../../views${componentPath}/index.vue`
- const module = this.modules[fullPath] || this.modules[fullPathWithIndex]
+ const module = this.resolveModule(componentPath)
if (!module) {
+ const fullPath = `../../views${componentPath}.vue`
+ const fullPathWithIndex = `../../views${componentPath}/index.vue`
console.error(
`[ComponentLoader] 鏈壘鍒扮粍浠�: ${componentPath}锛屽皾璇曡繃鐨勮矾寰�: ${fullPath} 鍜� ${fullPathWithIndex}`
)
@@ -22,6 +31,30 @@
return module
}
/**
+ * 棰勭儹缁勪欢妯″潡锛岄伩鍏嶉娆$偣鍑婚〉闈㈡椂鍐嶈Е鍙戝喎鍔犺浇銆�
+ */
+ warm(componentPath) {
+ const normalizedPath = typeof componentPath === 'string' ? componentPath.trim() : ''
+ if (!normalizedPath) {
+ return Promise.resolve(false)
+ }
+ if (this.warmPromises.has(normalizedPath)) {
+ return this.warmPromises.get(normalizedPath)
+ }
+ const module = this.resolveModule(normalizedPath)
+ if (!module) {
+ return Promise.resolve(false)
+ }
+ const warmTask = module()
+ .then(() => true)
+ .catch((error) => {
+ console.warn(`[ComponentLoader] 缁勪欢棰勭儹澶辫触: ${normalizedPath}`, error)
+ return false
+ })
+ this.warmPromises.set(normalizedPath, warmTask)
+ return warmTask
+ }
+ /**
* 鍔犺浇甯冨眬缁勪欢
*/
loadLayout() {
--
Gitblit v1.9.1