某寶可自行購買 abp.zero 框架,本文相關的Abp Zero Angular 培訓 B站視頻有須要的可前往B站觀看。javascript
備註:已經安裝的可忽略此項,國外資源很差訪問問題,本身用國內淘寶或者其餘第三方鏡像解決。css
yarnhtml
yarn start前端
編譯完後,可在瀏覽器中打開:http://localhost:4200,默認帳號:admin/123qwevue
src/shared/layout/nav/
找到配置路由服務app-navigation.server.ts
添加新的路由java
new AppMenuItem('Fsu管理', null, 'flaticon-line-graph', '/app/main/fsuManager'),
我這裏假設將Fsu管理組件注入到main文件夾下,main-routing.module.ts文件node
{ path: 'fsuManager', component: FsuManagerComponent },
此時編譯會報錯,由於並沒有fsuManagerComponent組件服務,繼續往下添加,另外組件的命名方式(FsuManagerComponent)必須是
Pascal命名方式,首字母須要大寫不然會報錯。macos
建立組件服務文件fsuManager.component.ts, fsuManager.component.html
css文件的引入與html文件引入相似,舉例 styleUrls: ['./users.component.less'],
自行完善
各組件含義自行去網上查詢學習。主要介紹AppComponentBase,框架的基類,
目的是爲了更方便的生成各類業務類,業務類直接繼承此類便可。npm
import { Component, Injector } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { appModuleAnimation } from '@shared/animations/routerTransition'; @Component({ templateUrl: './fsuManager.component.html', animations: [appModuleAnimation()] }) export class FsuManagerComponent extends AppComponentBase { constructor(injector: Injector) { super(injector); } }
<div [@routerTransition]> <div class="modal-content"> <div class="m-portlet m-portlet--mobile"> <div class="m=portlet_body"> <p>welcome to Fsumanager!</p> </div> </div> </div> </div>
在main.module.ts中聲明fsuManager服務組件。編程
declarations: [ DashboardComponent, FsuManagerComponent ],
appconfig.json
文件位置:src/assets/
"remoteServiceBaseUrl": "http://localhost:21021",
appconfig.production.json
文件位置:src/assets/
"remoteServiceBaseUrl": "https:www.daxxxop.tech/proxyForApi",
使用nswag掃描後臺新增接口,生成代理服務,此服務類同時會提供Dto模型(實體或者實體集合),
很是方便前端人員編碼,根據接口文檔來對後臺服務下的增刪改查接口進行調用。
"url": "http://localhost:21021/swagger/v1/swagger.json",
進入nswag文件夾調用refresh.bat批處理文件
./refresh.bat
進入nswag文件夾調用refresh.sh批處理文件
./refresh.sh
備註:該腳本是本身編寫,有須要讀者可提供。
位置src/shared/service-proxies.ts
這裏框架使用了代理設計模式,思考下,代理設計模式的目的??
自動生成了FsuManagerServiceProxy代理類,裏面有getFsu方法可傳入
filter過濾字段;註冊到Ngmodule裏,其餘頁面便可調用。
這裏pipe是rxjs裏的管道概念,可在管道里對數據作延時或者數據變換。
@Injectable() export class FsuManagerServiceProxy { private http: HttpClient; private baseUrl: string; protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined; constructor(@Inject(HttpClient) http: HttpClient, @Optional() @Inject(API_BASE_URL) baseUrl?: string) { this.http = http; this.baseUrl = baseUrl ? baseUrl : ""; } /** * @param filter (optional) * @return Success */ getFsu(filter: string | null | undefined): Observable<ListResultDtoOfFsuListDto> { let url_ = this.baseUrl + "/api/services/app/FsuManager/GetFsu?"; if (filter !== undefined) url_ += "Filter=" + encodeURIComponent("" + filter) + "&"; url_ = url_.replace(/[?&]$/, ""); let options_ : any = { observe: "response", responseType: "blob", headers: new HttpHeaders({ "Accept": "text/plain" }) }; return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any) => { return this.processGetFsu(response_); })).pipe(_observableCatch((response_: any) => { if (response_ instanceof HttpResponseBase) { try { return this.processGetFsu(<any>response_); } catch (e) { return <Observable<ListResultDtoOfFsuListDto>><any>_observableThrow(e); } } else return <Observable<ListResultDtoOfFsuListDto>><any>_observableThrow(response_); })); } protected processGetFsu(response: HttpResponseBase): Observable<ListResultDtoOfFsuListDto> { const status = response.status; const responseBlob = response instanceof HttpResponse ? response.body : (<any>response).error instanceof Blob ? (<any>response).error : undefined; let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }}; if (status === 200) { return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => { let result200: any = null; let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); result200 = ListResultDtoOfFsuListDto.fromJS(resultData200); return _observableOf(result200); })); } else if (status !== 200 && status !== 204) { return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => { return throwException("An unexpected server error occurred.", status, _responseText, _headers); })); } return _observableOf<ListResultDtoOfFsuListDto>(<any>null); }
以及掃描出後臺FsuListDto及其接口的形式,增長了json序列化與反序列化的方法;
export class FsuListDto implements IFsuListDto { fsuName!: string | undefined; id!: number; constructor(data?: IFsuListDto) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) (<any>this)[property] = (<any>data)[property]; } } } init(_data?: any) { if (_data) { this.fsuName = _data["fsuName"]; this.id = _data["id"]; } } static fromJS(data: any): FsuListDto { data = typeof data === 'object' ? data : {}; let result = new FsuListDto(); result.init(data); return result; } toJSON(data?: any) { data = typeof data === 'object' ? data : {}; data["fsuName"] = this.fsuName; data["id"] = this.id; return data; } }
接口形式以下:
export interface IFsuListDto { fsuName: string | undefined; id: number; }
將其返回形式封裝程item
export class ListResultDtoOfFsuListDto implements IListResultDtoOfFsuListDto { items!: FsuListDto[] | undefined; constructor(data?: IListResultDtoOfFsuListDto) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) (<any>this)[property] = (<any>data)[property]; } } } init(_data?: any) { if (_data) { if (Array.isArray(_data["items"])) { this.items = [] as any; for (let item of _data["items"]) this.items!.push(FsuListDto.fromJS(item)); } } } static fromJS(data: any): ListResultDtoOfFsuListDto { data = typeof data === 'object' ? data : {}; let result = new ListResultDtoOfFsuListDto(); result.init(data); return result; } toJSON(data?: any) { data = typeof data === 'object' ? data : {}; if (Array.isArray(this.items)) { data["items"] = []; for (let item of this.items) data["items"].push(item.toJSON()); } return data; } } export interface IListResultDtoOfFsuListDto { items: FsuListDto[] | undefined; }
找到service-proxy.module.ts文件,嫁給你FsuManager代理服務注入到NgModule中去。
ApiServiceProxies.FsuManagerServiceProxy,
建立以下業務文件.ts,頁面文件.html,固然有須要的話能夠增長.css。
本文不對.css多作說明,自行學習。
fsuManager.component.ts fsuManager.component.html
fsuManager.component.ts代碼以下
import {Component, Injector, OnInit} from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import {FsuListDto, FsuManagerServiceProxy} from '@shared/service-proxies/service-proxies'; import {ThemesLayoutBaseComponent} from '@app/shared/layout/themes/themes-layout-base.component'; //註冊了組件模板的位置 @Component({ templateUrl: './fsuManager.component.html', animations: [appModuleAnimation()] }) export class FsuManagerComponent extends AppComponentBase implements OnInit { fsuList: FsuListDto[] = []; filter: string = ''; constructor(injector: Injector, private _fsuManagerService: FsuManagerServiceProxy) { super(injector); } ngOnInit(): void { this.getFsu(); } getFsu(): void { this._fsuManagerService.getFsu(this.filter).subscribe((result) => { this.fsuList = result.items; } ); } }
subscribe rxjs 響應式編程中的發佈訂閱模式;
RxJS: 簡單入門
Rxjs_觀察者模式和發佈訂閱模式
*.html文件中主要用了ngFor,與vue中的v-for基本相似。另外須要明確掉用的UI組件,找到其官網地址,
沒用一個組件要看其說明,多是英文網站,學會用谷歌翻譯。
<div [@routerTransition]> <div class="row margin-bottom-5"> <div class="col-xs-12"> <div class="page-head"> <div class="page-title"> <h1> <span>{{l("Fsu列表")}}</span> </h1> </div> </div> </div> </div> <div class="portlet light margin-bottom-0"> <div class="portlet-body"> <h3>{{l("Fsu Manager")}}</h3> <div class="list-group"> <a *ngFor="let fsu of fsuList" href="javascript:;" class="list-group-item"> <h4 class="list-group-item-heading"> {{fsu.id + ' ' + fsu.fsuName}} </h4> <p class="list-group-item-text"> {{fsu.fsuName}} </p> </a> </div> </div> </div> </div>
版權聲明:本文爲博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接和本聲明。 本文連接:http://www.javashuo.com/article/p-gsjgmqse-ny.html