Browse Source

Merge branch 'master' of http://121.36.37.70:3000/shaojiahao/Jinan_project

非煤矿山灾害智能感知和预警系统
jingbowen 3 years ago
parent
commit
fc0622d7b3
  1. 5
      src/app/CustomReuseStrategy.ts
  2. 4
      src/app/home/system-management/role/addrole/addrole.component.html
  3. 19
      src/app/home/system-management/role/addrole/addrole.component.ts
  4. 4
      src/app/home/system-management/role/editrole/editrole.component.html
  5. 20
      src/app/home/system-management/role/editrole/editrole.component.ts
  6. 26
      src/app/home/system-management/role/role.component.html
  7. 97
      src/app/home/system-management/role/role.component.ts
  8. 24
      src/app/pages/login/login.component.ts

5
src/app/CustomReuseStrategy.ts

@ -14,7 +14,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy {
/** 表示对所有路由允许复用 如果你有路由不想利用可以在这加一些业务逻辑判断 */ /** 表示对所有路由允许复用 如果你有路由不想利用可以在这加一些业务逻辑判断 */
shouldDetach(route: ActivatedRouteSnapshot): boolean { shouldDetach(route: ActivatedRouteSnapshot): boolean {
console.log('shouldDetach======>', route); // console.log('shouldDetach======>', route);
if (route.routeConfig.path == 'basicInfo' || route.routeConfig.path == '') { if (route.routeConfig.path == 'basicInfo' || route.routeConfig.path == '') {
return false; return false;
} else { } else {
@ -25,8 +25,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy {
/** 当路由离开时会触发。按path作为key存储路由快照&组件当前实例对象 */ /** 当路由离开时会触发。按path作为key存储路由快照&组件当前实例对象 */
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void { store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
console.log('store======>route', route); // console.log('store======>route', route);
// console.log('store======>handle', handle);
if (route.routeConfig.path == 'unit') { if (route.routeConfig.path == 'unit') {
CustomReuseStrategy.handlers[this.getRouteUrl(route)] = handle; CustomReuseStrategy.handlers[this.getRouteUrl(route)] = handle;
} }

4
src/app/home/system-management/role/addrole/addrole.component.html

@ -8,13 +8,13 @@
</nz-input-group> </nz-input-group>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
<nz-form-item> <!-- <nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24" nzFor="权限">权限</nz-form-label> <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="权限">权限</nz-form-label>
<nz-form-control> <nz-form-control>
<nz-select formControlName="power" nzPlaceHolder="请选择权限" nzMode="multiple"> <nz-select formControlName="power" nzPlaceHolder="请选择权限" nzMode="multiple">
<nz-option *ngFor="let o of optionList" [nzValue]="o.name" [nzLabel]="o.displayName"></nz-option> <nz-option *ngFor="let o of optionList" [nzValue]="o.name" [nzLabel]="o.displayName"></nz-option>
</nz-select> </nz-select>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item> -->
</form> </form>
</div> </div>

19
src/app/home/system-management/role/addrole/addrole.component.ts

@ -12,21 +12,14 @@ import { NzTreeComponent } from 'ng-zorro-antd/tree';
export class AddroleComponent implements OnInit { export class AddroleComponent implements OnInit {
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
@Input() data?: any;
@Input() nodes?: any;
@Input() title?: string;
@Input() subtitle?: string;
validateForm!: FormGroup; validateForm!: FormGroup;
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { } constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { }
ngOnInit(): void { ngOnInit(): void {
this.loadMore();
this.validateForm = this.fb.group({ this.validateForm = this.fb.group({
name: [null, [Validators.required]], name: [null, [Validators.required]]
power: [null],
menus: [null]
}); });
} }
@ -37,14 +30,6 @@ export class AddroleComponent implements OnInit {
} }
optionList = []; optionList = [];
isLoading = false; isLoading = false;
//获取权限列表
loadMore() {
this.isLoading = true;
this.http.get('/api/services/app/Role/GetAllPermissions').subscribe((data: any) => {
this.isLoading = false;
this.optionList = data.result.items
console.log('所有权限', data)
})
}
} }

4
src/app/home/system-management/role/editrole/editrole.component.html

@ -8,13 +8,13 @@
</nz-input-group> </nz-input-group>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
<nz-form-item> <!-- <nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24" nzFor="权限">权限</nz-form-label> <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="权限">权限</nz-form-label>
<nz-form-control> <nz-form-control>
<nz-select [(ngModel)]="multipleValue" formControlName="power" nzPlaceHolder="请选择权限" nzMode="multiple"> <nz-select [(ngModel)]="multipleValue" formControlName="power" nzPlaceHolder="请选择权限" nzMode="multiple">
<nz-option *ngFor="let o of optionList" [nzValue]="o.name" [nzLabel]="o.displayName"></nz-option> <nz-option *ngFor="let o of optionList" [nzValue]="o.name" [nzLabel]="o.displayName"></nz-option>
</nz-select> </nz-select>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item> -->
</form> </form>
</div> </div>

20
src/app/home/system-management/role/editrole/editrole.component.ts

@ -12,22 +12,14 @@ import { TreeService } from 'src/app/service/tree.service';
export class EditroleComponent implements OnInit { export class EditroleComponent implements OnInit {
@Input() data?: any; @Input() data?: any;
@Input() optionList?: any;
@Input() nodes?: any;
validateForm!: FormGroup; validateForm!: FormGroup;
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { } constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { }
multipleValue: any multipleValue: any
ngOnInit(): void { ngOnInit(): void {
this.multipleValue = this.data.grantedPermissions
this.validateForm = this.fb.group({ this.validateForm = this.fb.group({
name: [null, [Validators.required]], name: [null, [Validators.required]]
power: [null],
menus: [null]
}); });
if (this.optionList.length == 0) {
this.loadMore()
}
} }
totalCount totalCount
@ -36,14 +28,4 @@ export class EditroleComponent implements OnInit {
this.modal.destroy({ data: 'this the result data' }); this.modal.destroy({ data: 'this the result data' });
} }
// optionList = [];
//获取权限列表
loadMore() {
this.http.get('/api/services/app/Role/GetAllPermissions').subscribe((data: any) => {
this.optionList = data.result.items
this.modal.containerInstance.config.nzOkLoading = false
// console.log('所有权限',data)
})
}
} }

26
src/app/home/system-management/role/role.component.html

@ -6,21 +6,39 @@
<button nz-button nzType="primary" (click)="addRole()">创建角色</button> <button nz-button nzType="primary" (click)="addRole()">创建角色</button>
</div> </div>
<div class="content"> <div class="content">
<nz-table #colSpanTable [nzData]="listOfData" nzBordered nzSize="small" [nzShowPagination]="false"> <nz-table [nzLoading]="isLoading" [nzPageSize]="1000" #colSpanTable [nzData]="listOfData" nzBordered nzSize="small" [nzShowPagination]="false">
<thead> <thead>
<tr> <tr>
<th nzWidth="18%">角色名称</th> <th nzWidth="18%">角色名称</th>
<th nzWidth="18%">创建/修改时间</th> <th nzWidth="18%">创建/修改时间</th>
<th>状态</th>
<th>操作</th> <th>操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let item of colSpanTable.data; index as i"> <tr *ngFor="let item of colSpanTable.data; index as i">
<td>访客</td> <td>{{item.name}}</td>
<td>2021-11-19</td> <td>{{item.creationTime | date:"yyyy-MM-dd"}}</td>
<td>
<ng-container *ngIf="item.enabled; else elseTemplate">
<span style="color: rgb(77, 192, 77);">已启用</span>
</ng-container>
<ng-template #elseTemplate>
<span style="color: rgb(226, 25, 58);">已禁用</span>
</ng-template>
</td>
<td class="operation"> <td class="operation">
<span class="blue" (click)="editRole(item)">编辑</span> <span class="blue" (click)="editRole(item)">编辑</span>
<span class="blue" (click)="forbidRole(item)">禁用</span> <ng-container *ngIf="item.enabled; else elseTemplate2">
<span class="blue" (click)="forbidRole(item,false)">
禁用
</span>
</ng-container>
<ng-template #elseTemplate2>
<span class="green" (click)="forbidRole(item,true)">
启用
</span>
</ng-template>
<span class="red" (click)="deleteRole(item)">删除</span> <span class="red" (click)="deleteRole(item)">删除</span>
</td> </td>
</tr> </tr>

97
src/app/home/system-management/role/role.component.ts

@ -14,47 +14,61 @@ import { EditroleComponent } from './editrole/editrole.component';
export class RoleComponent implements OnInit { export class RoleComponent implements OnInit {
constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { } constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { }
listOfData = [11 listOfData = [];
];
ngOnInit(): void { ngOnInit(): void {
this.getAllRoles()
} }
getAllRoles() {
//获取角色列表
isLoading = false
async getAllRoles() {
this.isLoading = true
let params = {
PageNumber: 1,
PageSize: 100
}
await new Promise<void>((resolve, reject) => {
this.http.get('/api/Roles', {
params: params
}).subscribe((data: any) => {
this.isLoading = false
this.listOfData = data.items
resolve(data)
})
})
} }
addRole() { addRole() {
const modal = this.modal.create({ const modal = this.modal.create({
nzTitle: '新增角色', nzTitle: '新增角色',
nzContent: AddroleComponent, nzContent: AddroleComponent,
nzViewContainerRef: this.viewContainerRef, nzViewContainerRef: this.viewContainerRef,
nzWidth: 400, nzWidth: 400,
nzComponentParams: {
nodes: null
},
nzMaskClosable: false, nzMaskClosable: false,
nzOnOk: async () => { nzOnOk: async () => {
if (instance.validateForm.valid) { if (instance.validateForm.valid) {
await new Promise(resolve => { await new Promise(resolve => {
console.log('表单信息', instance.validateForm)
let body = { let body = {
name: instance.validateForm.value.name, name: instance.validateForm.value.name
DisplayName: instance.validateForm.value.name,
grantedPermissions: instance.validateForm.value.power || []
} }
let body2 = instance.validateForm.value.menus || [] this.http.post('/api/Roles', body).subscribe({
this.http.post('/api/services/app/Role/Create', body).subscribe({ next: async (data) => {
next: (data) => { await this.getAllRoles()
this.message.create('success', '创建成功');
resolve(data) resolve(data)
this.message.create('success', '创建成功!');
this.getAllRoles()
return true return true
}, },
error: (err) => { error: (err) => {
this.message.create('warning', '分配菜单错误!'); this.isLoading = false
this.message.create('warning', '创建失败');
} }
}) })
}) })
} else { } else {
this.message.create('warning', '请填写完整'); this.message.create('warning', '请填写完整');
return false return false
} }
} }
@ -76,28 +90,24 @@ export class RoleComponent implements OnInit {
nzOnOk: async () => { nzOnOk: async () => {
if (instance.validateForm.valid) { if (instance.validateForm.valid) {
await new Promise(resolve => { await new Promise(resolve => {
console.log('表单信息', instance.validateForm)
let body = { let body = {
id: item.id,
name: instance.validateForm.value.name, name: instance.validateForm.value.name,
DisplayName: instance.validateForm.value.name,
grantedPermissions: instance.validateForm.value.power || []
} }
let body2 = instance.validateForm.value.menus || [] this.http.patch(`/api/Roles/${item.id}`, body).subscribe({
this.http.put('/api/services/app/Role/Update', body).subscribe({ next: async (data) => {
next: (data) => { await this.getAllRoles()
resolve(data) resolve(data)
this.message.create('success', '修改成功!'); this.message.create('success', '修改成功');
this.getAllRoles()
return true return true
}, },
error: (err) => { error: (err) => {
this.message.create('warning', '分配菜单错误!'); this.message.create('warning', '修改失败');
return false
} }
}) })
}) })
} else { } else {
this.message.create('warning', '请填写完整'); this.message.create('warning', '请填写完整');
return false return false
} }
} }
@ -107,18 +117,37 @@ export class RoleComponent implements OnInit {
// Return a result when closed // Return a result when closed
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result));
} }
forbidRole(item) { forbidRole(item, type) {
this.isLoading = true
let body = {
enabled: type,
}
this.http.patch(`/api/Roles/${item.id}`, body).subscribe({
next: async (data) => {
await this.getAllRoles()
this.message.create('success', '修改成功');
},
error: (err) => {
this.isLoading = false
this.message.create('warning', '修改失败');
}
})
} }
deleteRole(item) { deleteRole(item) {
this.modal.confirm({ this.modal.confirm({
nzTitle: `确定要删除${item.title}这个机构吗?`, nzTitle: `确定要删除${item.name}这个机构吗?`,
nzOkText: '确定', nzOkText: '确定',
nzOkType: 'primary', nzOkType: 'primary',
nzOnOk: () => { nzOnOk: () => {
this.http.delete(`/api/Organizations/${item.origin.id}`).subscribe(data => { this.http.delete(`/api/Roles/${item.id}`).subscribe({
next: async (data) => {
this.message.create('success', '删除成功!'); await this.getAllRoles()
this.message.create('success', '删除成功');
},
error: (err) => {
this.isLoading = false
this.message.create('warning', '删除失败');
}
}) })
}, },
nzCancelText: '取消', nzCancelText: '取消',

24
src/app/pages/login/login.component.ts

@ -97,20 +97,28 @@ export class LoginComponent implements OnInit {
password: this.validateForm.value.password password: this.validateForm.value.password
}).subscribe({ }).subscribe({
next: (data: any) => { next: (data: any) => {
this.isLoading = false;
this.rememberInfo()
this.autoLogin()
sessionStorage.setItem("token", data.token); sessionStorage.setItem("token", data.token);
sessionStorage.setItem("refreshToken", data.refreshToken); sessionStorage.setItem("refreshToken", data.refreshToken);
this.router.navigate(['/system']) this.http.get('/api/Accounts/Profile').subscribe({
this.message.create('success', `登录成功`); next: (data: any) => {
console.log('登录用户信息', data)
this.isLoading = false;
this.rememberInfo()
this.autoLogin()
this.router.navigate(['/system'])
this.message.create('success', `登录成功`);
sessionStorage.setItem("userData", JSON.stringify(data));
},
error: (err) => {
this.isLoading = false;
}
})
}, },
error: (err) => { error: (err) => {
this.isLoading = false; this.isLoading = false;
} }
} })
)
} }
forget() { forget() {

Loading…
Cancel
Save