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 @@ - +
- + + + + + + + +请使用浏览器打开此文件,然后右键保存生成的图标
+ + + + + \ 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'); + } + }); + }) + ); +});