Skip to content

Commit 72e1f93

Browse files
committed
refactor: 项目结构调整
1 parent 9977676 commit 72e1f93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+185
-166
lines changed
File renamed without changes.
File renamed without changes.

src/app/app.component.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from "@angular/core";
2+
3+
@Component({
4+
selector: "contact-app",
5+
templateUrl: "app/app.component.html",
6+
styleUrls: ["app/app.component.css"]
7+
})
8+
9+
export class AppComponent {
10+
constructor() {}
11+
}

src/app/app.module.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {NgModule} from '@angular/core'
2+
import {RouterModule} from "@angular/router";
3+
import {FormsModule} from "@angular/forms";
4+
import {BrowserModule} from "@angular/platform-browser";
5+
import {HttpModule} from "@angular/http";
6+
7+
import {rootRouterConfig} from "./app.routes";
8+
import {AppComponent} from "./app.component";
9+
10+
import {CollectionComponent} from './collection/collection.component';
11+
import {ListComponent, ItemComponent} from './list';
12+
import {DetailComponent, AnotationComponent} from './detail';
13+
import {EditComponent} from './edit/edit.component';
14+
15+
import {ContactService} from "./shared/contact.service";
16+
import {FooterComponent} from './shared/footer.component';
17+
import {DateReformPipe} from './shared/date-reform.pipe';
18+
import {BtnClickDirective} from './shared/btn-click.directive';
19+
import {UtilService} from './shared/util.service';
20+
21+
22+
@NgModule({
23+
declarations: [
24+
AppComponent,
25+
ListComponent,
26+
DetailComponent,
27+
AnotationComponent,
28+
CollectionComponent,
29+
EditComponent,
30+
FooterComponent,
31+
ItemComponent,
32+
DateReformPipe,
33+
BtnClickDirective
34+
],
35+
imports : [BrowserModule, FormsModule, HttpModule, RouterModule.forRoot(rootRouterConfig)],
36+
providers : [ContactService, UtilService],
37+
bootstrap : [AppComponent]
38+
})
39+
export class AppModule {
40+
41+
}

src/app/app.routes.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {Routes} from "@angular/router";
2+
3+
import {CollectionComponent} from './collection/collection.component';
4+
import {ListComponent, ItemComponent} from './list';
5+
import {DetailComponent, AnotationComponent} from './detail';
6+
import {EditComponent} from './edit/edit.component';
7+
8+
9+
export const rootRouterConfig: Routes = [
10+
{
11+
path: "",
12+
redirectTo: "list",
13+
pathMatch: 'full'
14+
},
15+
{
16+
path: "list",
17+
component: ListComponent
18+
},
19+
{
20+
path: "list/:id",
21+
component: DetailComponent,
22+
children: [
23+
{
24+
path: "",
25+
component: AnotationComponent
26+
}
27+
]
28+
},
29+
{
30+
path: "edit",
31+
component: EditComponent
32+
},
33+
{
34+
path: "edit/:id",
35+
component: EditComponent
36+
},
37+
{
38+
path: "collection",
39+
component: CollectionComponent
40+
}
41+
];

src/app/components/collection/collection.html src/app/collection/collection.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ <h3 class="collection-header">我的收藏</h3>
22
<h3 *ngIf="coll_length == 0" class="no-collection">没有收藏</h3>
33
<ul class="my-collection">
44
<li *ngFor="let collection of collections">
5-
<a [routerLink]="['/contact-detail', collection.id]">
5+
<a [routerLink]="['/list', collection.id]">
66
<label>{{ collection.name }}</label><span>{{ collection.telNum }}</span>
77
</a>
88
</li>

src/app/components/collection/collection.ts src/app/collection/collection.component.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {Footer} from '../../widget/footer';
3-
import {ContactService} from '../../services/contact-service';
2+
import {ContactService} from 'shared/contact.service';
43

54
@Component({
65
selector: 'call-record',
7-
templateUrl: 'app/components/collection/collection.html',
8-
styleUrls: ['app/components/collection/collection.css']
6+
templateUrl: 'app/collection/collection.component.html',
7+
styleUrls: ['app/collection/collection.component.css']
98
})
10-
export class Collection implements OnInit {
9+
export class CollectionComponent implements OnInit {
1110
collections:any = [];
1211
contacts:any = {};
1312

src/app/components/contact-app.ts

-11
This file was deleted.

src/app/components/contact-detail/anotation.ts

-11
This file was deleted.
File renamed without changes.

src/app/detail/anotation.component.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'detail',
5+
templateUrl: 'app/detail/anotation.component.html',
6+
styleUrls: ['app/detail/anotation.component.css'],
7+
})
8+
9+
export class AnotationComponent {
10+
constructor() {}
11+
}

src/app/components/contact-detail/contact-detail.ts src/app/detail/detail.component.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {Component, OnInit, OnDestroy} from '@angular/core';
22
import {Router, ActivatedRoute} from '@angular/router';
3-
import {ContactService} from '../../services/contact-service';
3+
import {ContactService} from 'shared/contact.service';
44

55
@Component({
66
selector: 'detail',
7-
templateUrl: 'app/components/contact-detail/contact-detail.html',
8-
styleUrls: ['app/components/contact-detail/contact-detail.css']
7+
templateUrl: 'app/detail/detail.component.html',
8+
styleUrls: ['app/detail/detail.component.css']
99
})
10-
export class ContactDetail implements OnInit, OnDestroy {
10+
export class DetailComponent implements OnInit, OnDestroy {
1111
contact_id: number;
1212
detail:any = {};
1313
contacts:any = {};
@@ -33,7 +33,7 @@ export class ContactDetail implements OnInit, OnDestroy {
3333
}
3434

3535
editContact() {
36-
this._router.navigate(['/operate/id',this.contact_id]);
36+
this._router.navigate(['/edit',this.contact_id]);
3737
}
3838

3939
collectTheContact() {

src/app/detail/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './detail.component';
2+
export * from './anotation.component';
File renamed without changes.
File renamed without changes.

src/app/widget/operate.ts src/app/edit/edit.component.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {Component, OnInit, Input} from '@angular/core';
22
import {Router, ActivatedRoute} from '@angular/router';
33
import {Location} from '@angular/common';
4-
import {ContactService} from '../services/contact-service';
5-
import * as UT from '../utils/utils';
4+
import {ContactService} from 'shared/contact.service';
5+
import {UtilService} from 'shared/util.service';
66

77
@Component({
88
selector: 'my-operate',
9-
templateUrl: 'app/widget/operate.html',
10-
styleUrls: ['app/widget/operate.css']
9+
templateUrl: 'app/edit/edit.component.html',
10+
styleUrls: ['app/edit/edit.component.css']
1111
})
12-
export class Operate implements OnInit {
13-
isAdd: number;
12+
export class EditComponent implements OnInit {
13+
isAdd: boolean;
1414
operateTitle: string;
1515
editId: number;
1616
contacts:any = {};
@@ -31,18 +31,20 @@ export class Operate implements OnInit {
3131
private _router: Router,
3232
private _activatedRoute:ActivatedRoute,
3333
private _constactService: ContactService,
34-
private _location:Location
34+
private _location:Location,
35+
private util: UtilService
3536
) {}
3637

3738
ngOnInit() {
3839
this.getContacts();
3940
this._activatedRoute.params.subscribe(params => {
40-
this.isAdd = params['isAdd'];
41+
// this.isAdd = params['isAdd'];
4142
this.editId = params['id'];
43+
this.isAdd = !this.editId;
4244
})
43-
this.operateTitle = this.isAdd == 1 ? '新建联系人' : '编辑联系人';
45+
this.operateTitle = this.isAdd ? '新建联系人' : '编辑联系人';
4446
//
45-
if(this.isAdd != 1) this.getContactDetailById(this.editId);
47+
if(!this.isAdd) this.getContactDetailById(this.editId);
4648
}
4749

4850
submitForm() {
@@ -53,7 +55,7 @@ export class Operate implements OnInit {
5355
this.birTip = true;
5456

5557
if(this.isName && this.isPhoneNum && this.isAddr && this.isEmail && this.isBir){
56-
if(this.isAdd == 1) this.addContact();
58+
if(this.isAdd) this.addContact();
5759
else this.editeContact();
5860
}
5961
}
@@ -107,7 +109,7 @@ export class Operate implements OnInit {
107109
this.contacts = JSON.parse(ss_contacts);
108110
this.contacts.splice(this.editId - 1, 1, edit_contact);
109111
sessionStorage.setItem("contacts",JSON.stringify(this.contacts));
110-
this._router.navigate(['/contact-detail',this.editId]);
112+
this._router.navigate(['/list',this.editId]);
111113
}
112114

113115
cancleOperate() {
@@ -121,15 +123,15 @@ export class Operate implements OnInit {
121123
}
122124
onBlurPhone() {
123125
this.phoneTip = true;
124-
this.isPhoneNum = UT.checkPhoneNum(this.contact.telNum);
126+
this.isPhoneNum = util.checkPhoneNum(this.contact.telNum);
125127
}
126128
onBlurAddr() {
127129
this.addrTip = true;
128130
this.isAddr = this.contact.address ? true : false;
129131
}
130132
onBlurEmail() {
131133
this.emailTie = true;
132-
this.isEmail = UT.checkEmail(this.contact.email);
134+
this.isEmail = util.checkEmail(this.contact.email);
133135
}
134136
onBlurBir() {
135137
this.birTip = true;

src/app/list/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './list.component';
2+
export * from './item.component';
File renamed without changes.
File renamed without changes.

src/app/components/contact-list/list-li.ts src/app/list/item.component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {Router} from '@angular/router';
33

44
@Component({
55
selector: 'list-li',
6-
templateUrl: 'app/components/contact-list/list-li.html',
7-
styleUrls: ['app/components/contact-list/list-li.css']
6+
templateUrl: 'app/list/item.component.html',
7+
styleUrls: ['app/list/item.component.css']
88
})
99

10-
export class ListChildrenComponent implements OnInit {
10+
export class ItemComponent implements OnInit {
1111
@Input() contact:any = {};
1212
@Output() routerNavigate = new EventEmitter<number>();
1313

src/app/components/contact-list/contact-list.ts src/app/list/list.component.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import {Component, OnInit} from '@angular/core';
22
import {Router} from '@angular/router';
3-
import {Operate} from '../../widget/operate';
4-
import {ContactService} from '../../services/contact-service';
3+
import {ContactService} from 'shared/contact.service';
54

65
@Component({
76
selector: 'list',
8-
templateUrl: 'app/components/contact-list/contact-list.html',
9-
styleUrls: ['app/components/contact-list/contact-list.css']
7+
templateUrl: 'app/list/list.component.html',
8+
styleUrls: ['app/list/list.component.css']
109
})
11-
export class ContactList implements OnInit {
10+
export class ListComponent implements OnInit {
1211
contacts: {};
1312
private isAdd:number = 1;
1413

@@ -34,11 +33,11 @@ export class ContactList implements OnInit {
3433
}
3534

3635
addContact() {
37-
this._router.navigate(['/operate/isAdd', this.isAdd]);
36+
this._router.navigate(['edit']);
3837
}
3938

4039
routerNavigate(id: number) {
41-
this._router.navigate(['/contact-detail',id]);
40+
this._router.navigate(['/list',id]);
4241
}
4342

4443
}

src/app/router/app-module.ts

-38
This file was deleted.

0 commit comments

Comments
 (0)