修复bug
修复bug
This commit is contained in:
@@ -59,6 +59,7 @@ export class EditableTagComponent implements OnInit, OnChanges {
|
|||||||
@Input() doubleClick: boolean;
|
@Input() doubleClick: boolean;
|
||||||
@Input() autoClear: boolean;
|
@Input() autoClear: boolean;
|
||||||
@Input() size: 'small' | 'default' | 'large';
|
@Input() size: 'small' | 'default' | 'large';
|
||||||
|
@Output() inEditStatus = new EventEmitter<void>();
|
||||||
@Output() modalOK = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>();
|
@Output() modalOK = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>();
|
||||||
@Output() modalCancel = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>();
|
@Output() modalCancel = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>();
|
||||||
|
|
||||||
@@ -85,6 +86,10 @@ export class EditableTagComponent implements OnInit, OnChanges {
|
|||||||
this.key = changes.key.currentValue;
|
this.key = changes.key.currentValue;
|
||||||
this.getFocus(this.tmpKey);
|
this.getFocus(this.tmpKey);
|
||||||
}
|
}
|
||||||
|
if (changes.text && !changes.text.isFirstChange()) {
|
||||||
|
this.text = changes.text.currentValue;
|
||||||
|
this.inputValue = changes.text.currentValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showInput(doubleClick: boolean): void {
|
showInput(doubleClick: boolean): void {
|
||||||
@@ -95,12 +100,14 @@ export class EditableTagComponent implements OnInit, OnChanges {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (new Date().getTime() - this.doubleClickInfo.date < 200) {
|
if (new Date().getTime() - this.doubleClickInfo.date < 200) {
|
||||||
|
this.inEditStatus.emit()
|
||||||
this.inputVisible = true;
|
this.inputVisible = true;
|
||||||
setTimeout(() => this.inputElement?.nativeElement.focus(), 10);
|
setTimeout(() => this.inputElement?.nativeElement.focus(), 10);
|
||||||
}
|
}
|
||||||
this.doubleClickInfo.date = new Date().getTime();
|
this.doubleClickInfo.date = new Date().getTime();
|
||||||
} else {
|
} else {
|
||||||
this.inputVisible = true;
|
this.inputVisible = true;
|
||||||
|
this.inEditStatus.emit()
|
||||||
setTimeout(() => this.inputElement?.nativeElement.focus(), 10);
|
setTimeout(() => this.inputElement?.nativeElement.focus(), 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<form nz-form [formGroup]="formGroup" (ngSubmit)="publishArticle()">
|
<form nz-form [formGroup]="formGroup" (ngSubmit)="publishArticle()">
|
||||||
<!-- 文章类型 -->
|
<!-- 文章类型 -->
|
||||||
<nz-form-item *ngIf="primaryData.id">
|
<nz-form-item *ngIf="primaryData?.id">
|
||||||
<nz-form-label nzSpan="4">发布为</nz-form-label>
|
<nz-form-label nzSpan="4">发布为</nz-form-label>
|
||||||
<nz-form-control nzSpan="19" nzOffset="1" nzErrorTip="请选择文章发布类型">
|
<nz-form-control nzSpan="19" nzOffset="1" nzErrorTip="请选择文章发布类型">
|
||||||
<nz-radio-group formControlName="isUpdate">
|
<nz-radio-group formControlName="isUpdate">
|
||||||
@@ -20,37 +20,7 @@
|
|||||||
</nz-radio-group>
|
</nz-radio-group>
|
||||||
</nz-form-control>
|
</nz-form-control>
|
||||||
</nz-form-item>
|
</nz-form-item>
|
||||||
<!-- 标签 -->
|
|
||||||
<nz-form-item>
|
|
||||||
<nz-form-label [nzSpan]="4" (click)="showTagInput()">文章标签</nz-form-label>
|
|
||||||
<nz-form-control [nzSpan]="19" [nzOffset]="1">
|
|
||||||
<input formControlName="tagList" style="display: none">
|
|
||||||
<nz-tag *ngFor="let t of tagTmpList" nzMode="closeable"
|
|
||||||
(nzOnClose)="handleClose(t)">{{t}}</nz-tag>
|
|
||||||
<nz-tag *ngIf="!tagInputVisible&&tagTmpList.length<5" (click)="showTagInput()">
|
|
||||||
<i nz-icon nzType="plus"></i> New Tag
|
|
||||||
</nz-tag>
|
|
||||||
<input #inputElement nz-input nzSize="small" *ngIf="tagInputVisible" formControlName="tags"
|
|
||||||
type="text" style="width: 78px;" (blur)="handleTagInputConfirm()"
|
|
||||||
(keydown.enter)="handleTagInputConfirm()">
|
|
||||||
|
|
||||||
<div *ngIf="tagListTouched&&formGroup.get('tagList').hasError('required')"
|
|
||||||
class="errTip">未选择或添加标签
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<nz-card nzSize="small" nzTitle="已有标签" title="最多可选五个标签">
|
|
||||||
<nz-tag *ngFor="let tag of tagNacList"
|
|
||||||
style="margin: 4px; border: 1px dashed #6A6A6A;user-select: none"
|
|
||||||
[nzMode]="(tagTmpList.length<5||tagTmpList.indexOf(tag.name) > -1)?'checkable':'default'"
|
|
||||||
[nzChecked]="tagTmpList.indexOf(tag.name) > -1"
|
|
||||||
(nzCheckedChange)="tagChange($event,tag.name)">
|
|
||||||
{{ tag.name }}
|
|
||||||
</nz-tag>
|
|
||||||
</nz-card>
|
|
||||||
|
|
||||||
|
|
||||||
</nz-form-control>
|
|
||||||
</nz-form-item>
|
|
||||||
<!-- 文章分类 -->
|
<!-- 文章分类 -->
|
||||||
<nz-form-item>
|
<nz-form-item>
|
||||||
<nz-form-label nzSpan="4">文章分类</nz-form-label>
|
<nz-form-label nzSpan="4">文章分类</nz-form-label>
|
||||||
@@ -83,6 +53,40 @@
|
|||||||
</nz-form-control>
|
</nz-form-control>
|
||||||
</nz-form-item>
|
</nz-form-item>
|
||||||
|
|
||||||
|
<!-- 标签 -->
|
||||||
|
<nz-form-item>
|
||||||
|
<nz-form-label [nzSpan]="4" (click)="showTagInput()">文章标签</nz-form-label>
|
||||||
|
<nz-form-control [nzSpan]="19" [nzOffset]="1">
|
||||||
|
<input formControlName="tagList" style="display: none">
|
||||||
|
<nz-tag *ngFor="let t of tagTmpList;let i =index" nzMode="closeable"
|
||||||
|
(nzOnClose)="handleClose(t)" [nzColor]="color[i]">{{t}}</nz-tag>
|
||||||
|
<div style="display: inline-block; width: 60px">
|
||||||
|
<editable-tag *ngIf="tagTmpList?.length!=5" [autoClear]="false"
|
||||||
|
[text]="editTagText"
|
||||||
|
[showConfirmModal]="false"
|
||||||
|
[showEditIcon]="false"
|
||||||
|
(inEditStatus)="editTagText=null"
|
||||||
|
(valueChange)="handleTagInputConfirm($event)"
|
||||||
|
size="small">
|
||||||
|
<i nz-icon nzType="plus"></i>
|
||||||
|
</editable-tag>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span *ngIf="tagListTouched&&formGroup.get('tagList').hasError('required')" class="errTip">未选择或添加标签</span>
|
||||||
|
<nz-card nzSize="small" nzTitle="已有标签" title="最多可选五个标签" style="margin-top: 10px;">
|
||||||
|
<nz-tag *ngFor="let tag of tagNacList"
|
||||||
|
style="margin: 4px; border: 1px dashed #6A6A6A;user-select: none"
|
||||||
|
[nzMode]="(tagTmpList?.length<5||tagTmpList?.indexOf(tag.name) > -1)?'checkable':'default'"
|
||||||
|
[nzChecked]="tagTmpList&&tagTmpList.indexOf(tag.name) > -1"
|
||||||
|
(nzCheckedChange)="tagChange($event,tag.name)">
|
||||||
|
{{ tag.name }}
|
||||||
|
</nz-tag>
|
||||||
|
</nz-card>
|
||||||
|
|
||||||
|
|
||||||
|
</nz-form-control>
|
||||||
|
</nz-form-item>
|
||||||
|
|
||||||
<button nz-button style="width: 100%" nzType="primary"
|
<button nz-button style="width: 100%" nzType="primary"
|
||||||
type="submit" [disabled]="!formGroup.valid">提交
|
type="submit" [disabled]="!formGroup.valid">提交
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
.errTip {
|
.errTip {
|
||||||
color: #f5222d;
|
color: #f5222d;
|
||||||
line-height: 30px;
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
|
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
|
||||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||||
import {Category, Tag} from '../../../../class/Tag';
|
import {Category, Tag} from '../../../../class/Tag';
|
||||||
|
import {ColorList} from '../../../../utils/color'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'c-publish-form',
|
selector: 'c-publish-form',
|
||||||
@@ -12,17 +13,28 @@ export class PublishFormComponent implements OnInit {
|
|||||||
constructor(private fb: FormBuilder) {
|
constructor(private fb: FormBuilder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewChild('inputElement', {static: false}) tagInputElement: ElementRef;
|
@ViewChild('inputElement', {static: true}) tagInputElement: ElementRef;
|
||||||
|
|
||||||
@Input() tagNacList: { name: string, size: number }[];
|
@Input() tagNacList: { name: string, size: number }[];
|
||||||
@Input() categoryList: Category[];
|
@Input() categoryList: Category[];
|
||||||
@Input() primaryData: { id: number, type: boolean, tags: string[], category: string, url?: string };
|
@Input() primaryData: { id: number, type: boolean, tags: string[], category: string, url?: string };
|
||||||
@Output() submitEvent = new EventEmitter<{ id: number, type: boolean, tags: string[], category: string, url?: string }>();
|
@Output() submitEvent = new EventEmitter<{
|
||||||
|
id: number,
|
||||||
|
type: boolean,
|
||||||
|
tags: string[],
|
||||||
|
category: string,
|
||||||
|
isUpdate: boolean,
|
||||||
|
url?: string
|
||||||
|
}>();
|
||||||
|
|
||||||
formGroup: FormGroup;
|
formGroup: FormGroup;
|
||||||
tagTmpList: string[] = [];
|
tagTmpList: string[] = [];
|
||||||
tagInputVisible: boolean = false;
|
tagInputVisible: boolean = false;
|
||||||
tagListTouched: boolean = false;
|
tagListTouched: boolean = false;
|
||||||
|
editTagText: string = '新增';
|
||||||
|
|
||||||
|
color: string[] = [];
|
||||||
|
randomColor = () => this.color = ColorList.map(c => c.bgColor).sort(() => Math.floor(Math.random() * 2));
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.formGroup = this.fb.group({
|
this.formGroup = this.fb.group({
|
||||||
@@ -41,15 +53,18 @@ export class PublishFormComponent implements OnInit {
|
|||||||
this.formGroup.get('category').setValue(this.primaryData.category);
|
this.formGroup.get('category').setValue(this.primaryData.category);
|
||||||
this.formGroup.get('url').setValue(this.primaryData.url);
|
this.formGroup.get('url').setValue(this.primaryData.url);
|
||||||
}
|
}
|
||||||
|
this.randomColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
publishArticle() {
|
publishArticle() {
|
||||||
|
console.log(this.formGroup.value)
|
||||||
const formData = {
|
const formData = {
|
||||||
id: this.formGroup.value.isUpdate ? this.primaryData.id : null,
|
id: this.formGroup.value.isUpdate ? this.primaryData?.id : null,
|
||||||
type: this.formGroup.value.type,
|
type: this.formGroup.value.type,
|
||||||
tags: this.formGroup.value.tagList,
|
tags: this.formGroup.value.tagList,
|
||||||
category: this.formGroup.value.category,
|
category: this.formGroup.value.category,
|
||||||
url: this.formGroup.value.type ? null : this.formGroup.value.url
|
url: this.formGroup.value.type ? null : this.formGroup.value.url,
|
||||||
|
isUpdate: this.formGroup.value.isUpdate
|
||||||
};
|
};
|
||||||
this.submitEvent.emit(formData);
|
this.submitEvent.emit(formData);
|
||||||
}
|
}
|
||||||
@@ -58,6 +73,7 @@ export class PublishFormComponent implements OnInit {
|
|||||||
showTagInput() {
|
showTagInput() {
|
||||||
this.tagInputVisible = true;
|
this.tagInputVisible = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
||||||
this.tagInputElement.nativeElement.focus();
|
this.tagInputElement.nativeElement.focus();
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
@@ -69,9 +85,10 @@ export class PublishFormComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 输入框输入完成
|
// 输入框输入完成
|
||||||
handleTagInputConfirm() {
|
handleTagInputConfirm($event: { value: string; originalValue: string; changed: boolean }) {
|
||||||
this.tagListTouched = true;
|
this.tagListTouched = true;
|
||||||
const tmpTag = this.formGroup.get('tags').value;
|
// const tmpTag = this.formGroup.get('tags').value;
|
||||||
|
const tmpTag = $event.value;
|
||||||
if (tmpTag && this.tagTmpList.indexOf(tmpTag) === -1) {
|
if (tmpTag && this.tagTmpList.indexOf(tmpTag) === -1) {
|
||||||
this.tagTmpList = [...this.tagTmpList, tmpTag];
|
this.tagTmpList = [...this.tagTmpList, tmpTag];
|
||||||
}
|
}
|
||||||
@@ -79,12 +96,13 @@ export class PublishFormComponent implements OnInit {
|
|||||||
this.formGroup.get('tagList').setValue(this.tagTmpList.length ? this.tagTmpList : null);
|
this.formGroup.get('tagList').setValue(this.tagTmpList.length ? this.tagTmpList : null);
|
||||||
this.formGroup.get('tagList').updateValueAndValidity();
|
this.formGroup.get('tagList').updateValueAndValidity();
|
||||||
this.tagInputVisible = false;
|
this.tagInputVisible = false;
|
||||||
|
this.editTagText = '新增'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 点击tag切换
|
// 点击tag切换
|
||||||
tagChange($event: boolean, name: string) {
|
tagChange($event: boolean, name: string) {
|
||||||
this.tagListTouched = true;
|
this.tagListTouched = true;
|
||||||
if (this.tagTmpList.indexOf(name) > -1) {
|
if (this.tagTmpList?.indexOf(name) > -1) {
|
||||||
this.tagTmpList = this.tagTmpList.filter(v => v !== name);
|
this.tagTmpList = this.tagTmpList.filter(v => v !== name);
|
||||||
} else {
|
} else {
|
||||||
this.tagTmpList.push(name);
|
this.tagTmpList.push(name);
|
||||||
@@ -99,6 +117,7 @@ export class PublishFormComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 点选了文章类型
|
// 点选了文章类型
|
||||||
|
|
||||||
articleTypeChanged() {
|
articleTypeChanged() {
|
||||||
this.formGroup.get(`url`).clearValidators();
|
this.formGroup.get(`url`).clearValidators();
|
||||||
const type = this.formGroup.get(`type`).value;
|
const type = this.formGroup.get(`type`).value;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class WriteComponent implements OnInit {
|
|||||||
userInfo: User;
|
userInfo: User;
|
||||||
categoryList: Tag[];
|
categoryList: Tag[];
|
||||||
tagNacList: { name: string, size: number }[];
|
tagNacList: { name: string, size: number }[];
|
||||||
primaryData = {};
|
primaryData = null;
|
||||||
// 发布新文章时,文章相同会被拦回 此处判断一下
|
// 发布新文章时,文章相同会被拦回 此处判断一下
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
@@ -44,6 +44,8 @@ export class WriteComponent implements OnInit {
|
|||||||
// 同步属性内容
|
// 同步属性内容
|
||||||
syncModel(str): void {
|
syncModel(str): void {
|
||||||
this.article.mdContent = str;
|
this.article.mdContent = str;
|
||||||
|
// 文章 暂存
|
||||||
|
localStorage.setItem('tmpArticle', JSON.stringify(this.article));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,12 +111,13 @@ export class WriteComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* 文章数据提交
|
* 文章数据提交
|
||||||
*/
|
*/
|
||||||
publishArticle(e: { id: number, type: boolean, tags: string[], category: string, url?: string }) {
|
publishArticle(e: { id: number; type: boolean; tags: string[]; category: string; isUpdate: boolean; url?: string }) {
|
||||||
this.article.type = e.type;
|
this.article.type = e.type;
|
||||||
this.article.tags = e.tags;
|
this.article.tags = e.tags;
|
||||||
this.article.category = e.category;
|
this.article.category = e.category;
|
||||||
this.article.url = e.url;
|
this.article.url = e.url;
|
||||||
this.article.id = e.id;
|
this.article.id = e.id;
|
||||||
|
this.isUpdate = e.isUpdate
|
||||||
|
|
||||||
this.modalVisible = false;
|
this.modalVisible = false;
|
||||||
|
|
||||||
@@ -123,11 +126,8 @@ export class WriteComponent implements OnInit {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// 文章 暂存
|
|
||||||
localStorage.setItem('tmpArticle', JSON.stringify(this.article));
|
|
||||||
|
|
||||||
this.article.url = this.article.type ? null : this.article.url;
|
this.article.url = this.article.type ? null : this.article.url;
|
||||||
|
|
||||||
if (!this.isUpdate) {
|
if (!this.isUpdate) {
|
||||||
// 非文章更新
|
// 非文章更新
|
||||||
|
|
||||||
@@ -149,6 +149,7 @@ export class WriteComponent implements OnInit {
|
|||||||
if (err.code === 3020) {
|
if (err.code === 3020) {
|
||||||
this.message.error('你没有发布文章的权限,文章替你暂存在本地');
|
this.message.error('你没有发布文章的权限,文章替你暂存在本地');
|
||||||
}
|
}
|
||||||
|
this.message.error(err.msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -163,13 +164,13 @@ export class WriteComponent implements OnInit {
|
|||||||
this.router.navigateByUrl('article/' + data.result.id);
|
this.router.navigateByUrl('article/' + data.result.id);
|
||||||
}, 2500);
|
}, 2500);
|
||||||
},
|
},
|
||||||
error: e => {
|
error: err => {
|
||||||
if (e.code === 3010) {
|
if (err.code === 3010) {
|
||||||
this.router.navigateByUrl('login');
|
this.router.navigateByUrl('login');
|
||||||
} else if (e.code === 3020) {
|
} else if (err.code === 3020) {
|
||||||
this.message.error('你没有更新文章的权限');
|
this.message.error('你没有更新文章的权限');
|
||||||
} else {
|
} else {
|
||||||
this.message.error('失败,原因:' + e.msg);
|
this.message.error('失败,原因:' + err.msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
NzSelectModule,
|
NzSelectModule,
|
||||||
NzTagModule
|
NzTagModule
|
||||||
} from 'ng-zorro-antd';
|
} from 'ng-zorro-antd';
|
||||||
|
import {EditableTagModule} from '../admin/components/editable-tag/editable-tag.module';
|
||||||
|
|
||||||
const routes: Route[] = [
|
const routes: Route[] = [
|
||||||
{path: '**', component: WriteComponent}
|
{path: '**', component: WriteComponent}
|
||||||
@@ -38,6 +39,7 @@ const routes: Route[] = [
|
|||||||
NzSelectModule,
|
NzSelectModule,
|
||||||
NzCardModule,
|
NzCardModule,
|
||||||
NzDividerModule,
|
NzDividerModule,
|
||||||
|
EditableTagModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class WriteModule {
|
export class WriteModule {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
logger: true,
|
logger: true,
|
||||||
host: 'http://127.0.0.1:8081'
|
host: 'http://celess.cn:8082/'
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user