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.
67 lines
1.8 KiB
67 lines
1.8 KiB
import {Component, OnInit} from '@angular/core';
|
|
import {Commons} from '../../commons';
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
|
import {NoticeService} from './notice.service';
|
|
import {Result} from '../../interface/Result';
|
|
import {MessageInterface, MessageUtil} from '../../message/message.service';
|
|
import {CookieService} from 'ngx-cookie-service';
|
|
import {environment} from '../../../environments/environment';
|
|
import {Router} from '@angular/router';
|
|
import {AbstractRoute} from '../../AbstractRoute';
|
|
|
|
@Component({
|
|
selector: 'app-notice',
|
|
templateUrl: './notice.component.html',
|
|
styleUrls: ['./notice.component.scss']
|
|
})
|
|
export class NoticeComponent extends Commons implements OnInit, MessageInterface {
|
|
|
|
// 公告表单
|
|
noticeForm = this.fb.group({
|
|
// 公告标题
|
|
title: this.fb.control('', [Validators.required]),
|
|
// 公告内容
|
|
content: this.fb.control('', [Validators.required])
|
|
});
|
|
|
|
managerName = '';
|
|
|
|
constructor(
|
|
private fb: FormBuilder,
|
|
private noticeService: NoticeService,
|
|
private messageUtil: MessageUtil,
|
|
private cookieService: CookieService,
|
|
private router: Router,
|
|
private abstractRoute: AbstractRoute
|
|
) {
|
|
super();
|
|
}
|
|
|
|
// 添加公告
|
|
addNotice() {
|
|
this.noticeService.addNotice(Object.assign(
|
|
this.noticeForm.value, {author: this.cookieService.get(environment.managerKey)}
|
|
)).subscribe(res => {
|
|
this.messageUtil.alert(this.prefix(res.message));
|
|
if (res.result === Result.OK) {
|
|
this.router.navigateByUrl('/login');
|
|
}
|
|
});
|
|
}
|
|
|
|
form(): FormGroup {
|
|
return this.noticeForm;
|
|
}
|
|
|
|
prefix(key: string): string {
|
|
return 'server.forum.notice.' + key;
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
if (!this.abstractRoute.isLogin()) {
|
|
this.router.navigateByUrl('/login');
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|