Skip to content

Commit 4c7c660

Browse files
committed
refactor: 支持离线状态
1 parent 7287e74 commit 4c7c660

File tree

1 file changed

+19
-41
lines changed
  • src/BootstrapBlazor/wwwroot/modules

1 file changed

+19
-41
lines changed
Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//import Data from "./data.js"
2-
//import EventHandler from "./event-handler.js";
1+
import Data from "./data.js"
2+
import EventHandler from "./event-handler.js";
3+
import { registerBootstrapBlazorModule } from './utility.js'
34

45
export function init(options) {
56
const { invoke, onNetworkStateChangedCallback } = options;
@@ -13,46 +14,23 @@ export function init(options) {
1314
updateState(e.target);
1415
}
1516

16-
//const onlineStateChanged = () => {
17-
// //if (Array.isArray(indicators)) {
18-
// // indicators.forEach(indicator => {
19-
// // const el = document.getElementById(indicator);
20-
// // if (el) {
21-
// // el.classList.remove('offline');
22-
// // }
23-
// // });
24-
// //}
25-
// invoke.invokeMethodAsync(onlineStateChangedCallback, true);
26-
//}
27-
//const offlineStateChanged = () => {
28-
// //if (Array.isArray(indicators)) {
29-
// // indicators.forEach(indicator => {
30-
// // const el = document.getElementById(indicator);
31-
// // if (el) {
32-
// // el.classList.add('offline');
33-
// // }
34-
// // });
35-
// //}
36-
// invoke.invokeMethodAsync(onlineStateChangedCallback, false);
37-
//}
38-
//EventHandler.on(window, 'online', onlineStateChanged);
39-
//EventHandler.on(window, 'offline', offlineStateChanged);
17+
const onlineStateChanged = () => {
18+
const indicators = [...document.querySelectorAll('.bb-nt-indicator')];
19+
indicators.forEach(indicator => {
20+
indicator.classList.remove('offline');
21+
});
22+
}
23+
const offlineStateChanged = () => {
24+
const indicators = [...document.querySelectorAll('.bb-nt-indicator')];
25+
indicators.forEach(indicator => {
26+
indicator.classList.add('offline');
27+
});
28+
}
4029

41-
//Data.set(id, {
42-
// onlineStateChanged,
43-
// offlineStateChanged
44-
//});
30+
registerBootstrapBlazorModule("NetworkMonitor", null, () => {
31+
EventHandler.on(window, 'online', onlineStateChanged);
32+
EventHandler.on(window, 'offline', offlineStateChanged);
33+
});
4534

4635
updateState(navigator.connection);
4736
}
48-
49-
//export async function dispose(id) {
50-
// const nt = Data.get(id);
51-
// Data.remove(id);
52-
53-
//// if (nt) {
54-
//// const { onlineStateChanged, offlineStateChanged } = nt;
55-
//// EventHandler.off(window, 'online', onlineStateChanged);
56-
//// EventHandler.off(window, 'offline', offlineStateChanged);
57-
//// }
58-
//}

0 commit comments

Comments
 (0)