mirror of https://github.com/abpframework/abp.git
8 changed files with 114 additions and 3 deletions
@ -0,0 +1,53 @@ |
|||
import { Injectable } from '@angular/core'; |
|||
import { InternalStore } from '../utils/internal-store-utils'; |
|||
import { fromEvent, merge, of, Subscription } from 'rxjs'; |
|||
import { map } from 'rxjs/operators'; |
|||
|
|||
export interface InternetConnectionState{ |
|||
status: boolean; |
|||
} |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root', |
|||
}) |
|||
export class InternetConnectionService{ |
|||
private store = new InternalStore<InternetConnectionState>({ status: true }); |
|||
networkStatus$: Subscription = Subscription.EMPTY; |
|||
|
|||
constructor() { |
|||
this.init() |
|||
} |
|||
|
|||
private init(): void { |
|||
this.checkNetworkStatus(); |
|||
} |
|||
|
|||
private checkNetworkStatus() { |
|||
this.networkStatus$ = merge( |
|||
of(null), |
|||
fromEvent(window, 'offline'), |
|||
fromEvent(window, 'online') |
|||
) |
|||
.pipe(map(() => navigator.onLine)) |
|||
.subscribe(status => { |
|||
this.setStatus(status) |
|||
}); |
|||
} |
|||
|
|||
getStatus(){ |
|||
return this.store.state.status |
|||
} |
|||
|
|||
getStatus$(){ |
|||
return this.store.sliceState(({ status }) => status); |
|||
} |
|||
|
|||
updateStatus$() { |
|||
return this.store.sliceUpdate(({ status }) => status); |
|||
} |
|||
|
|||
setStatus(status: boolean){ |
|||
this.store.patch({ status }) |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
import { Component, OnInit, inject } from '@angular/core'; |
|||
import { CommonModule } from '@angular/common' |
|||
import { of } from 'rxjs'; |
|||
import { InternetConnectionService, LocalizationModule } from '@abp/ng.core'; |
|||
|
|||
@Component({ |
|||
selector: 'abp-internet-status', |
|||
standalone: true, |
|||
imports:[CommonModule,LocalizationModule], |
|||
template: ` |
|||
<div class="status-icon" *ngIf="!(internetConnection$ | async)"> |
|||
<i data-toggle="tooltip" title="{{ 'AbpUi::InternetConnectionInfo' | abpLocalization }}" data-placement="left" class="fa fa-circle text-blinking blink"> |
|||
</i> |
|||
</div> |
|||
`,
|
|||
styles: [` |
|||
.blink { |
|||
animation: blinker 0.9s cubic-bezier(.5, 0, 1, 1) infinite alternate; |
|||
} |
|||
@keyframes blinker { |
|||
0% { color:#c1c1c1 } |
|||
70% { color: #DC3545 } |
|||
100% { color: #DC3545 } |
|||
} |
|||
|
|||
.text-blinking{ |
|||
font-size:1.2rem; |
|||
} |
|||
|
|||
.status-icon{ |
|||
position: fixed; |
|||
z-index: 999999; |
|||
top: 10px; |
|||
right: 10px; |
|||
} |
|||
|
|||
@media (width < 768px){ |
|||
.status-icon{ |
|||
top: 80px; |
|||
} |
|||
} |
|||
`]
|
|||
}) |
|||
export class InternetConnectionStatusComponent implements OnInit{ |
|||
internetConnection$ = of(true); |
|||
internetConnectionService = inject(InternetConnectionService) |
|||
|
|||
ngOnInit(): void { |
|||
this.internetConnection$ = this.internetConnectionService.getStatus$() |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue