From cfb653796ca5764170a255ddbddab86873beb336 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 15 Mar 2024 10:58:19 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=A2=84=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/SystemController.php | 32 +++++++++++++------ .../assets/js/components/RightBottom.vue | 3 -- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 5bdfafc1c..72e1dad70 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -1322,21 +1322,35 @@ class SystemController extends AbstractController */ public function prefetch() { - $file = base_path('.prefetch'); - if (!file_exists($file)) { - return []; + $userAgent = strtolower(Request::server('HTTP_USER_AGENT')); + $isMain = str_contains($userAgent, 'maintaskwindow'); + $isApp = str_contains($userAgent, 'kuaifan_eeui'); + $version = Base::getVersion(); + $array = []; + + if ($isMain || $isApp) { + $path = 'js/build/'; + $list = Base::readDir(public_path($path), false); + foreach ($list as $item) { + if (is_file($item) && filesize($item) > 50 * 1024) { + $array[] = $path . basename($item); + } + } } - $version = Base::getVersion(); - $content = file_get_contents($file); - - $array = explode("\n", $content); - $array = array_values(array_filter($array)); + if ($isMain) { + $file = base_path('.prefetch'); + if (file_exists($file)) { + $content = file_get_contents($file); + $items = explode("\n", $content); + $array = array_merge($array, $items); + } + } return array_map(function($item) use ($version) { $url = trim($item); $url = str_replace('{version}', $version, $url); return url($url); - }, $array); + }, array_values(array_filter($array))); } } diff --git a/resources/assets/js/components/RightBottom.vue b/resources/assets/js/components/RightBottom.vue index 13841b27d..61e3011d9 100644 --- a/resources/assets/js/components/RightBottom.vue +++ b/resources/assets/js/components/RightBottom.vue @@ -125,9 +125,6 @@ export default { if (this.$Electron && $A.$isSubElectron) { return; // 客户端子窗口 不预加载 } - if (this.$isEEUiApp) { - return; // 移动端 不预加载 - } axios.get($A.apiUrl('system/prefetch')).then(({status, data}) => { if (status === 200) { data.forEach(url => {