<wang-Editor *ngIf='show' #wangEditor [editorData]="editorData" ></wang-Editor>
import { Component, OnInit,ViewChild } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup} from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd/message';
import { editSysNotice,readSysNoticeDto } from '@api/zhjg/sysNotice';
import { DomSanitizer } from '@angular/platform-browser';
import { UploadChangeParam, UploadFile } from 'ng-zorro-antd/upload';
import { download,upload } from '@api/member/file';
import ImageView from '@shared/utils/ImageView';
import { getServer } from 'src/app/request';
import { stringify } from '@angular/compiler/src/util';
@Component({
selector: 'app-notice-add',
templateUrl: './notice-add.component.html',
styleUrls: ['./notice-add.component.less'],
})
export class NoticeAddComponent implements OnInit {
@ViewChild('wangEditor',{ static: false }) public save : any;
public loading = false;
public noticeForm: FormGroup;
public noticeId:"";
public editorData;
public UploadFileList = [];
public lookpicList: string[] = [];
public imgUrl = '';
previewVisible = false;
show=false
constructor(private router: Router, private route: ActivatedRoute,private sanitizer: DomSanitizer,private fb: FormBuilder,private message:NzMessageService) {
this.noticeForm = this.fb.group({
noticeType:"",
content:"",
title:"",
fileType:"tzfj"
})
}
ngOnInit() {
this.route.queryParams.subscribe(async params => {
if(!params.id){
this.show=true
}
if(!params.id) return;
this.noticeId =params.id;
const res= await readSysNoticeDto({ noticeId: params.id })
this.noticeForm.reset({
noticeType:res.noticeType,
title:res.title,
})
this.editorData=res.content
this.show=true
console.log(' this.editorData', this.editorData);
if(Array.isArray(res.fileInfoList)){
this.UploadFileList = res.fileInfoList.map(it=>{
return {
name:it.fileName,
uid:it.fileId,
fileName:it.fileName,
fileSize:it.fileSize,
fileUrl:it.fileUrl,
fileKey:it.fileKey,
}
});
}
console.log(res.fileInfoList,"编辑")
});
}
handleSubmit(){
this.save.editorOut()
console.log(this.save.data);
if(!this.noticeForm.value.noticeType){
return this.message.error('请选类别');
}
if(!this.noticeForm.value.title){
return this.message.error('请输标题');
}
console.log(this.save.data.length);
if(this.save.data.length>10000){
return this.message.error(`通知内容不能超过10000字符(当前字符数${this.save.data.length})`);
}
const postParams={
noticeType:this.noticeForm.value.noticeType,
title:this.noticeForm.value.title,
content:this.save.data,
fileType:"tzfj",
noticeId:this.noticeId,
fileInfoRequestList:this.handleDisponseFile(this.UploadFileList)
}
if(!this.noticeId){
delete postParams.noticeId;
}
editSysNotice(postParams).then(res => {
this.message.success("提交成功")
this.noticeForm.reset();
this.UploadFileList=[];
this.handleCancel();
});
}
handleText(){
}
handleCancel(){
console.log("取消操作")
this.router.navigate(['/notice'], {
queryParams: {
id: new Date(),
},
});
}
handleChange({ file, fileList }: UploadChangeParam): void {
console.log(file,"file",this.UploadFileList)
const status = file.status;
if (status !== 'uploading') {
}
if (status === 'done') {
this.message.success(`${file.name} 文件上传完成.`);
console.log(file.response.data, "上传成功");
} else if (status === 'error') {
this.message.error(`${file.name} 文件上传失败.`);
}
}
handleDisponseFile(fileList){
const fileParams=[];
fileList.forEach(it=>{
if(it?.fileKey){
fileParams.push(it)
}else{
fileParams.push(it?.response?.data)
}
})
return fileParams
}
}
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
import { getServer } from 'src/app/request';
import E from "wangeditor"
@Component({
selector: 'wang-Editor',
template: `
<div id="content"></div>
`,
})
export class wangEditorComponent implements OnInit {
public editor:any
@Input() editorData;
data=""
constructor() { }
ngOnInit() {
this.editor = new E(document.getElementById('content'))
this.editor.config.uploadFileName = 'file';
this.editor.config.uploadImgMaxLength = 5
this.editor.config.uploadImgServer = `${getServer()}/member/file/upload`
this.setEditorConfig()
this.editor.create()
this.editor.txt.html(this.editorData)
this.editor.config.uploadImgHooks = {
customInsert: function (insertImgFn, result) {
insertImgFn(getServer() + '/member/file/downloadImg?fileKey=' + result.data.fileKey)
}
}
}
setEditorConfig() {
this.editor.config.menus = this.getMenuConfig();
}
getMenuConfig(): string[] {
return [
'bold',
'italic',
'underline',
'head',
'fontName',
'fontSize',
'strikeThrough',
'foreColor',
'backColor',
'link',
'list',
'justify',
'quote',
'image',
'code',
'undo',
'redo'
];
}
editorOut(){
this.data=this.editor.txt.html()
}
}