From 8ffadc8604a2009171e77e7f3f4ef312e5224022 Mon Sep 17 00:00:00 2001 From: System Administrator Date: Sat, 28 Mar 2026 00:47:13 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0PWA=E6=94=AF=E6=8C=81?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E7=A6=BB=E7=BA=BF=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E5=92=8C=E6=B7=BB=E5=8A=A0=E5=88=B0=E4=B8=BB=E5=B1=8F=E5=B9=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- company-finance-system/frontend/index.html | 25 ++++++- .../frontend/public/icons/generate-icons.html | 56 +++++++++++++++ .../frontend/public/icons/icon.svg | 4 ++ .../frontend/public/manifest.json | 19 +++++ company-finance-system/frontend/public/sw.js | 70 +++++++++++++++++++ 5 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 company-finance-system/frontend/public/icons/generate-icons.html create mode 100644 company-finance-system/frontend/public/icons/icon.svg create mode 100644 company-finance-system/frontend/public/manifest.json create mode 100644 company-finance-system/frontend/public/sw.js diff --git a/company-finance-system/frontend/index.html b/company-finance-system/frontend/index.html index 15df89e..9bbea34 100644 --- a/company-finance-system/frontend/index.html +++ b/company-finance-system/frontend/index.html @@ -1,9 +1,16 @@ - + - + + + + + + + + 轻远电力老挝ERP - Qingyuan Power Laos @@ -12,5 +19,19 @@
+ diff --git a/company-finance-system/frontend/public/icons/generate-icons.html b/company-finance-system/frontend/public/icons/generate-icons.html new file mode 100644 index 0000000..621c10b --- /dev/null +++ b/company-finance-system/frontend/public/icons/generate-icons.html @@ -0,0 +1,56 @@ + + + + + Generate PWA Icons + + +

PWA图标生成器

+

请使用浏览器打开此文件,然后右键保存生成的图标

+
+ + + + \ No newline at end of file diff --git a/company-finance-system/frontend/public/icons/icon.svg b/company-finance-system/frontend/public/icons/icon.svg new file mode 100644 index 0000000..3f0d19c --- /dev/null +++ b/company-finance-system/frontend/public/icons/icon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/company-finance-system/frontend/public/manifest.json b/company-finance-system/frontend/public/manifest.json new file mode 100644 index 0000000..9828174 --- /dev/null +++ b/company-finance-system/frontend/public/manifest.json @@ -0,0 +1,19 @@ +{ + "name": "轻远电力老挝ERP", + "short_name": "轻远ERP", + "description": "轻远电力老挝分公司财务管理系统", + "start_url": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#1890ff", + "orientation": "portrait", + "scope": "/", + "icons": [ + { + "src": "/logo.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "any maskable" + } + ] +} diff --git a/company-finance-system/frontend/public/sw.js b/company-finance-system/frontend/public/sw.js new file mode 100644 index 0000000..e182fb5 --- /dev/null +++ b/company-finance-system/frontend/public/sw.js @@ -0,0 +1,70 @@ +// Service Worker for PWA +const CACHE_NAME = 'qingyuan-erp-v1'; +const STATIC_ASSETS = [ + '/', + '/index.html', + '/manifest.json', + '/logo.png' +]; + +// 安装时缓存静态资源 +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CACHE_NAME).then((cache) => { + return cache.addAll(STATIC_ASSETS); + }).catch((err) => { + console.log('Cache failed:', err); + }) + ); + self.skipWaiting(); +}); + +// 激活时清理旧缓存 +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((cacheNames) => { + return Promise.all( + cacheNames + .filter((name) => name !== CACHE_NAME) + .map((name) => caches.delete(name)) + ); + }) + ); + self.clients.claim(); +}); + +// 拦截请求,优先使用缓存 +self.addEventListener('fetch', (event) => { + // 跳过非GET请求和API请求 + if (event.request.method !== 'GET' || + event.request.url.includes('/api/') || + event.request.url.includes('chrome-extension')) { + return; + } + + event.respondWith( + caches.match(event.request).then((response) => { + // 如果缓存中有,返回缓存 + if (response) { + return response; + } + + // 否则发起网络请求 + return fetch(event.request).then((networkResponse) => { + // 缓存新请求 + if (networkResponse.status === 200) { + const responseToCache = networkResponse.clone(); + caches.open(CACHE_NAME).then((cache) => { + cache.put(event.request, responseToCache); + }); + } + return networkResponse; + }).catch(() => { + // 网络失败时返回离线页面 + if (event.request.mode === 'navigate') { + return caches.match('/index.html'); + } + }); + }) + ); +});