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 {