You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
import { Component } from "@angular/core";
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
import { NgxPermissionsService } from "ngx-permissions";
|
|
|
|
@Component({
|
|
selector: "app-home",
|
|
templateUrl: "./home.component.html",
|
|
styleUrls: ["./home.component.less"],
|
|
})
|
|
export class HomeComponent {
|
|
constructor(private perm: NgxPermissionsService, private router: Router, private route: ActivatedRoute) {}
|
|
|
|
async ngOnInit() {
|
|
let children = this.route.parent?.routeConfig?.children;
|
|
const { from } = this.route.snapshot.queryParams;
|
|
if (Array.isArray(children)) {
|
|
if (from) {
|
|
children = children.find((f) => f.path === from)?.children ?? [];
|
|
}
|
|
for (const child of children) {
|
|
if (child.path === this.route.routeConfig?.path) {
|
|
continue;
|
|
}
|
|
const only = child.data?.["permissions"]?.only;
|
|
if (Array.isArray(only)) {
|
|
if (await this.perm.hasPermission(only)) {
|
|
this.router.navigate(["/detection", from, child.path].filter(Boolean));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|