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.
 
 
 
 
pocketcommunityweb/src/app/forum/notice/notice.component.ts

67 lines
1.7 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';
@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
) {
super();
}
// 添加公告
addNotice() {
this.noticeService.addNotice(Object.assign(
this.noticeForm.value, {author: this.cookieService.get(environment.managerKey)}
)).subscribe(res => {
if (res.result === Result.OK) {
location.href = '/forum';
} else {
this.messageUtil.danger(res.message);
}
});
}
ngOnInit(): void {
this.validForm = {};
for (const key of Object.keys(this.noticeForm.value)) {
this.validForm[key] = {
flag: false
};
}
}
form(): FormGroup {
return this.noticeForm;
}
prefix(key: string): string {
return 'server.forum.notice.';
}
}