From c75b17fa05a67f2ccec92e38cf1c0d9a8db31b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Sat, 1 Aug 2020 13:30:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/view/link/link-routing.module.ts | 18 ------------------ src/app/view/link/link.module.ts | 6 +++--- 2 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 src/app/view/link/link-routing.module.ts diff --git a/src/app/view/link/link-routing.module.ts b/src/app/view/link/link-routing.module.ts deleted file mode 100644 index b867f60..0000000 --- a/src/app/view/link/link-routing.module.ts +++ /dev/null @@ -1,18 +0,0 @@ -import {NgModule} from '@angular/core'; -import {RouterModule, Routes} from '@angular/router'; -import {LinkComponent} from './link.component'; - - -const routes: Routes = [ - {path: '**', component: LinkComponent} -]; - -@NgModule({ - imports: [ - RouterModule.forChild(routes) - ], - exports: [RouterModule] -}) - -export class LinkRoutingModule { -} diff --git a/src/app/view/link/link.module.ts b/src/app/view/link/link.module.ts index 1a394ff..ab80d19 100644 --- a/src/app/view/link/link.module.ts +++ b/src/app/view/link/link.module.ts @@ -1,21 +1,21 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {LinkComponent} from './link.component'; -import {LinkRoutingModule} from './link-routing.module'; import {NzButtonModule, NzIconModule, NzInputModule, NzModalModule} from 'ng-zorro-antd'; import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; @NgModule({ declarations: [LinkComponent], imports: [ CommonModule, - LinkRoutingModule, NzIconModule, NzModalModule, FormsModule, NzButtonModule, - NzInputModule + NzInputModule, + RouterModule.forChild([{path: '**', component: LinkComponent}]) ] }) export class LinkModule { From a6c3f16ddf3f729dca60d7cf1952b8ccec52f347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Sat, 1 Aug 2020 13:31:10 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/api.service.ts | 15 +++++++++++---- src/app/class/Link.ts | 10 ++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/app/api/api.service.ts b/src/app/api/api.service.ts index 482250a..f81a958 100644 --- a/src/app/api/api.service.ts +++ b/src/app/api/api.service.ts @@ -9,7 +9,7 @@ import {ArticleReq} from '../class/Article'; import {Category, Tag} from '../class/Tag'; import {Comment} from '../class/Comment'; import {CommentReq} from '../class/Comment'; -import {Link} from '../class/Link'; +import {ApplyLinkReq, Link} from '../class/Link'; import {User} from '../class/User'; import {LoginReq} from '../class/User'; @@ -292,13 +292,20 @@ export class ApiService extends HttpService { }); } - applyLink(link: Link) { + applyLink(link: ApplyLinkReq) { + return super.Service({ + path: '/apply', + method: 'POST', + data: link + }); + } + + reapplyLink(keyStr: string) { return super.Service({ path: '/apply', method: 'POST', queryParam: { - name: link.name, - url: link.url + key: keyStr } }); } diff --git a/src/app/class/Link.ts b/src/app/class/Link.ts index 55fc7d3..7a74650 100644 --- a/src/app/class/Link.ts +++ b/src/app/class/Link.ts @@ -6,3 +6,13 @@ export class Link { iconPath: string; desc: string; } + + +export class ApplyLinkReq { + desc: string; + email: string; + iconPath: string; + linkUrl: string; + name: string; + url: string +} From 5d3b55b8b795a60c66f5f971e86db31dbe414f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Sat, 1 Aug 2020 19:21:37 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/view/link/link.component.html | 91 ++++++++++++++++++++++----- src/app/view/link/link.component.ts | 87 +++++++++++++++++-------- src/app/view/link/link.module.ts | 9 ++- 3 files changed, 142 insertions(+), 45 deletions(-) diff --git a/src/app/view/link/link.component.html b/src/app/view/link/link.component.html index 5d6764a..27d66d9 100644 --- a/src/app/view/link/link.component.html +++ b/src/app/view/link/link.component.html @@ -25,28 +25,89 @@ + (nzOnCancel)="cancel()" nzWidth="650">

申请友链

-
-
- -
-
- -
-
+
+ + 网站名称 + + + +
网站名称不可为空
+
最大长度为255
+
+
+
+ + 站长邮箱 + + + +
站长邮箱不可为空
+
邮箱格式不正确
+
+
+
+ + + 首页链接 + + + + + + + + + + +
首页链接不可为空
+
链接格式不正确
+
+
+
+
+ + 友链页链接 + + + + + + + + + + +
首页链接不可为空
+
链接格式不正确
+
+
+
+
+ + 网站图标 + + + + + + 网站描述 + + + + +
- + -
\ No newline at end of file + diff --git a/src/app/view/link/link.component.ts b/src/app/view/link/link.component.ts index 2aebdee..9e88cea 100644 --- a/src/app/view/link/link.component.ts +++ b/src/app/view/link/link.component.ts @@ -1,8 +1,9 @@ import {Component, OnInit} from '@angular/core'; -import {NzMessageService} from 'ng-zorro-antd'; +import {NzMessageService, NzModalService} from 'ng-zorro-antd'; import {Title} from '@angular/platform-browser'; import {ApiService} from '../../api/api.service'; -import {Link} from '../../class/Link'; +import {ApplyLinkReq, Link} from '../../class/Link'; +import {FormBuilder, FormGroup, Validators} from '@angular/forms'; @Component({ selector: 'view-link', @@ -13,7 +14,9 @@ export class LinkComponent implements OnInit { constructor(private message: NzMessageService, private titleService: Title, - private apiService: ApiService) { + private apiService: ApiService, + private fb: FormBuilder, + private modal: NzModalService) { titleService.setTitle('小海博客 | 友链'); } @@ -23,39 +26,69 @@ export class LinkComponent implements OnInit { link: Link; linkList: Link[]; + loading: boolean = false; + applyFormGroup: FormGroup; ngOnInit() { window.scrollTo(0, 0); this.link = new Link(); - this.apiService.links().subscribe(data => { - this.linkList = data.result; - }, - error => { - this.message.error(error.msg); - }); + this.apiService.links().subscribe({ + next: data => this.linkList = data.result, + error: err => this.message.error(err.msg) + }); + this.applyFormGroup = this.fb.group({ + urlLinkProtocol: ['http://'], + urlProtocol: ['http://'], + desc: [null, [Validators.maxLength(255)]], + email: [null, [Validators.required, Validators.pattern(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/)]], + iconPath: [null, [Validators.pattern(/^(https:\/\/|http:\/\/|)([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]], + linkUrl: [null, [Validators.required, Validators.pattern(/^([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]], + name: [null, [Validators.required, Validators.maxLength(255)]], + url: [null, [Validators.required, Validators.pattern(/^([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]] + }); + this.applyFormGroup.patchValue({ + desc: '百度', + email: 'a@celess.cn', + iconPath: 'baidu.com', + linkUrl: 'baidu.com', + name: '百度', + url: 'baidu.com' + }) } apply() { - if (this.link.name === '') { - this.message.error('网站名称不能为空'); - return; - } - if (this.link.url === '') { - this.message.error('网站链接不能为空'); - return; - } - const regExp = /^(https:\/\/|http:\/\/|)([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/; - if (!regExp.test(this.link.url)) { - this.message.error('网站链接输入不合法'); - return; - } - this.showModal = false; - this.apiService.applyLink(this.link).subscribe(data => { + const value = this.applyFormGroup.value; + value.url = value.urlProtocol + value.url; + value.linkUrl = value.urlLinkProtocol + value.linkUrl; + const req: ApplyLinkReq = value; + this.loading = true; + this.apiService.applyLink(req).subscribe({ + next: data => { this.message.success('提交成功,请稍等,即将为你处理'); + this.loading = false; + this.showModal = false; }, - error => { - this.message.error('提交失败,原因:' + error.msg); - }); + error: err => { + if (err.code === 7200) { + const key = err.result; + this.modal.create({ + nzTitle: '抓取站点失败', + nzContent: '暂未在您的网站友链页抓取到本站链接,是否确认已添加并重新提交邮件申请?', + nzClosable: false, + nzOnOk: () => { + this.apiService.reapplyLink(key).subscribe({ + next: data1 => this.message.success('提交成功,请稍等,即将为你处理'), + error: err1 => this.message.error('提交失败,原因:' + err.msg) + }) + } + }); + } else { + this.message.error('提交失败,原因:' + err.msg); + } + this.loading = false; + this.showModal = false; + } + }); } cancel() { diff --git a/src/app/view/link/link.module.ts b/src/app/view/link/link.module.ts index ab80d19..4e09598 100644 --- a/src/app/view/link/link.module.ts +++ b/src/app/view/link/link.module.ts @@ -1,8 +1,8 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {LinkComponent} from './link.component'; -import {NzButtonModule, NzIconModule, NzInputModule, NzModalModule} from 'ng-zorro-antd'; -import {FormsModule} from '@angular/forms'; +import {NzButtonModule, NzFormModule, NzIconModule, NzInputModule, NzModalModule, NzSelectModule} from 'ng-zorro-antd'; +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import {RouterModule} from '@angular/router'; @@ -15,7 +15,10 @@ import {RouterModule} from '@angular/router'; FormsModule, NzButtonModule, NzInputModule, - RouterModule.forChild([{path: '**', component: LinkComponent}]) + RouterModule.forChild([{path: '**', component: LinkComponent}]), + NzFormModule, + ReactiveFormsModule, + NzSelectModule ] }) export class LinkModule { From 6b63e7b02bd35dbd49d1ed6044d9380dc4974ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Sat, 1 Aug 2020 19:21:56 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/api.service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/api/api.service.ts b/src/app/api/api.service.ts index f81a958..227b368 100644 --- a/src/app/api/api.service.ts +++ b/src/app/api/api.service.ts @@ -296,13 +296,14 @@ export class ApiService extends HttpService { return super.Service({ path: '/apply', method: 'POST', - data: link + data: link, + contentType: 'application/json' }); } reapplyLink(keyStr: string) { return super.Service({ - path: '/apply', + path: '/reapply', method: 'POST', queryParam: { key: keyStr