feat: multi page: maintenance

dev/timezone
Lei OT 1 year ago
parent 92a29ca6d3
commit 9724de3bc5

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import MaintenancePage from './maintenance/index' import MaintenancePage from './maintenance/Index';
import '@/assets/index.css';
ReactDOM.createRoot(document.getElementById('maintenance-root')).render( ReactDOM.createRoot(document.getElementById('maintenance-root')).render(
<React.StrictMode> <React.StrictMode>

@ -1,23 +1,44 @@
const MaintenancePage = (props) => { import { clearAllCaches } from '@/utils/commons';
function handleClearCache() {
// Implement your cache clearing logic here
}
function handleReloadUpdate() { const MaintenancePage = () => {
// Implement your update reloading logic here const handleClearCache = async () => {
} await clearAllCaches();
};
function handleVersionCheck() { const handleReload = () => {
// Implement your version checking logic here const url = new URL(window.location.href);
} url.searchParams.forEach((value, name) => {
url.searchParams.delete(name);
});
const _num = Date.now();
url.searchParams.set('_spam' + _num, _num);
window.location.href = url.toString();
// window.location.href = window.location.href + '?versionCheck=true';
// window.location.reload(true);
};
const handleVersionCheck = () => {};
const __BUILD_DATE__ = `__BUILD_DATE__`;
const __BUILD_VERSION__ = `__BUILD_VERSION__`;
return ( return (
<> <>
<div> <div className='flex flex-col items-center justify-center h-5/6 bg-gray-100'>
<h1>Maintenance Page</h1> <h1 className='text-2xl font-bold mb-4 text-slate-800'>Sales CRM Maintenance Page</h1>
<button onClick={handleClearCache}>Clear Cache</button> <button onClick={handleClearCache} className='px-4 py-2 mb-4 bg-blue-500 text-white rounded-md border-0'>
<button onClick={handleReloadUpdate}>Reload Update</button> 清除缓存
<button onClick={handleVersionCheck}>Check Version</button> </button>
<button onClick={handleReload} className='px-4 py-2 mb-2 bg-green-500 text-white rounded-md border-0'>
重新加载
</button>
{/* <button onClick={handleVersionCheck} className='px-4 py-2 mb-2 bg-yellow-500 text-white rounded-md border-0'>
检查版本
</button> */}
<p>Version: {__BUILD_VERSION__}</p>
<p>
Build Date: {__BUILD_DATE__}&nbsp;&nbsp;<span>GMT+00:00</span>
</p>
</div> </div>
</> </>
); );

@ -467,7 +467,7 @@ export const calcCacheSizes = async () => {
let indexedDBSize = 0; let indexedDBSize = 0;
// 1. Get the service worker cache size // 1. Get the service worker cache size
if (navigator.serviceWorker) { if ('caches' in window) {
const cacheNames = await caches.keys(); const cacheNames = await caches.keys();
for (const name of cacheNames) { for (const name of cacheNames) {
const cache = await caches.open(name); const cache = await caches.open(name);
@ -480,13 +480,13 @@ export const calcCacheSizes = async () => {
} }
// 2. Get the disk cache size // 2. Get the disk cache size
const diskCacheName = 'disk-cache'; // const diskCacheName = 'disk-cache';
const diskCache = await caches.open(diskCacheName); // const diskCache = await caches.open(diskCacheName);
const diskCacheKeys = await diskCache.keys(); // const diskCacheKeys = await diskCache.keys();
for (const request of diskCacheKeys) { // for (const request of diskCacheKeys) {
const response = await diskCache.match(request); // const response = await diskCache.match(request);
diskCacheSize += Number(response.headers.get('Content-Length')) || 0; // diskCacheSize += Number(response.headers.get('Content-Length')) || 0;
} // }
// 3. Get the IndexedDB cache size // 3. Get the IndexedDB cache size
// const indexedDBNames = await window.indexedDB.databases(); // const indexedDBNames = await window.indexedDB.databases();

@ -22,6 +22,7 @@ const manifestForPlugIn = {
enabled: true enabled: true
}, },
workbox: { workbox: {
navigateFallbackDenylist: [/^\/maintenance/],
globPatterns: ['**/*.{json,css,js,html,ico,png,svg,woff2}'], globPatterns: ['**/*.{json,css,js,html,ico,png,svg,woff2}'],
maximumFileSizeToCacheInBytes: 3000000, maximumFileSizeToCacheInBytes: 3000000,
clientsClaim: true, clientsClaim: true,
@ -109,6 +110,7 @@ const manifestForPlugIn = {
export default defineConfig({ export default defineConfig({
define: { define: {
__BUILD_DATE__: JSON.stringify(`${new Date().toISOString()}`), __BUILD_DATE__: JSON.stringify(`${new Date().toISOString()}`),
__BUILD_VERSION__: JSON.stringify(`${packageJson.version}`),
}, },
plugins: [react(), WindiCSS(), buildDatePlugin(), VitePWA(manifestForPlugIn)], plugins: [react(), WindiCSS(), buildDatePlugin(), VitePWA(manifestForPlugIn)],
server: { server: {

Loading…
Cancel
Save