refactor: 用LocalStorageService代理localStorage

This commit is contained in:
禾几海
2021-03-16 20:38:42 +08:00
parent a2e80e6fdd
commit 2ba3d4ca1b
5 changed files with 36 additions and 18 deletions

View File

@@ -119,7 +119,7 @@ export class WriteComponent implements OnInit, OnDestroy {
next: data => {
// TODO 成功
this.message.success('发布成功,即将转跳');
localStorage.removeItem('tmpArticle');
this.localStorageService.removeItem('tmpArticle');
setTimeout(() => {
this.router.navigateByUrl('article/' + data.result.id);
@@ -143,7 +143,7 @@ export class WriteComponent implements OnInit, OnDestroy {
this.apiService.updateArticle(this.article).subscribe({
next: data => {
this.message.success('更新成功,即将转跳');
localStorage.removeItem('tmpArticle');
this.localStorageService.removeItem('tmpArticle');
setTimeout(() => {
this.router.navigateByUrl('article/' + data.result.id);
}, 2500);
@@ -253,8 +253,8 @@ export class WriteComponent implements OnInit, OnDestroy {
this.isUpdate = true;
this.getArticle();
}
if (!this.articleId && localStorage.getItem('tmpArticle')) {
this.article = JSON.parse(localStorage.getItem('tmpArticle'));
if (!this.articleId && this.localStorageService.getItem('tmpArticle')) {
this.article = JSON.parse(this.localStorageService.getItem('tmpArticle'));
}
}
};