• Abp vNext学习(3) 创建书籍信息展示页


      前面已经完成书籍信息后台的业务,现在来展示书籍信息

      首先准备本地化文本(Localization Text,不知道是不是这么翻译,暂时这么叫)

      找到.Domain.Shared类库下面的Localization/BookStore/en.json

      修改如下:

    {
      "Culture": "en",
      "Texts": {
        "Menu:Home": "Home",
        "Welcome": "Welcome",
        "LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io.",
        "Menu:BookStore": "Book Store",
        "Menu:Books": "Books",
        "Actions": "Actions",
        "Close": "Close",
        "Delete": "Delete",
        "Edit": "Edit",
        "PublishDate": "Publish date",
        "NewBook": "New book",
        "Name": "Name",
        "Type": "Type",
        "Price": "Price",
        "CreationTime": "Creation time",
        "AreYouSure": "Are you sure?",
        "AreYouSureToDelete": "Are you sure you want to delete this item?",
        "Enum:BookType:0": "Undefined",
        "Enum:BookType:1": "Adventure",
        "Enum:BookType:2": "Biography",
        "Enum:BookType:3": "Dystopia",
        "Enum:BookType:4": "Fantastic",
        "Enum:BookType:5": "Horror",
        "Enum:BookType:6": "Science",
        "Enum:BookType:7": "Science fiction",
        "Enum:BookType:8": "Poetry"
      }
    }

      这是一些基础配置,可以随便写,但是规范:

      1.菜单前加Menu:,比如Menu:Home

      2.使用类似Enum:<type>:<value>定义枚举类型

      首先确保安装了npm和angular脚手架

      cmd安装yarn:npm install yarn -g

      安装angular脚手架:npm install -g @angular/cli

      可能遇到node版本低的错误

      查看Node版本:node -v

      在vscode中使用yarn ng generate module book  --module app --routing --route books

      便会产生六个新文件,打开/src/app/book/book.module.ts并修改

    import { NgModule } from '@angular/core';
    import { SharedModule } from '../shared/shared.module';
    import { BookRoutingModule } from './book-routing.module';
    import { BookComponent } from './book.component';
    
    @NgModule({
      declarations: [BookComponent],
      imports: [
        BookRoutingModule,
        SharedModule
      ]
    })
    export class BookModule { }

      在app-routing.module.ts中添加路径

    { path: 'books', loadChildren: () => import('./book/book.module').then(m => m.BookModule) },

      在route.provider.ts中修改

    function configureRoutes(routes: RoutesService) {
      return () => {
        routes.add([
          {
            path: '/',
            name: '::Menu:Home',
            iconClass: 'fas fa-home',
            order: 1,
            layout: eLayoutType.application,
          },
          {
            path: '/book-store',
            name: '::Menu:BookStore',
            iconClass: 'fas fa-book',
            order: 2,
            layout: eLayoutType.application,
          },
          {
            path: '/books',
            name: '::Menu:Books',
            parentName: '::Menu:BookStore',
            layout: eLayoutType.application,
          },
        ]);
      };
    }

      添加菜单目录

      修改展示页面book.component.ts

    import { ListService, PagedResultDto } from '@abp/ng.core';
    import { Component, OnInit } from '@angular/core';
    import { BookDto } from './models';
    import { BookService } from './services';
    
    @Component({
      selector: 'app-book',
      templateUrl: './book.component.html',
      styleUrls: ['./book.component.scss'],
      providers: [ListService],
    })
    export class BookComponent implements OnInit {
      book = { items: [], totalCount: 0 } as PagedResultDto<BookDto>;
    
      constructor(public readonly list: ListService, private bookService: BookService) {}
    
      ngOnInit() {
        const bookStreamCreator = (query) => this.bookService.getListByInput(query);
    
        this.list.hookToQuery(bookStreamCreator).subscribe((response) => {
          this.book = response;
        });
      }
    }

      修改book.component.html

    <div class="card">
      <div class="card-header">
        <div class="row">
          <div class="col col-md-6">
            <h5 class="card-title">
              {{ '::Menu:Books' | abpLocalization }}
            </h5>
          </div>
          <div class="text-right col col-md-6"></div>
        </div>
      </div>
      <div class="card-body">
        <ngx-datatable [rows]="book.items" [count]="book.totalCount" [list]="list" default>
          <ngx-datatable-column [name]="'::Name' | abpLocalization" prop="name"></ngx-datatable-column>
          <ngx-datatable-column [name]="'::Type' | abpLocalization" prop="type">
            <ng-template let-row="row" ngx-datatable-cell-template>
              {{ '::Enum:BookType:' + row.type | abpLocalization }}
            </ng-template>
          </ngx-datatable-column>
          <ngx-datatable-column [name]="'::PublishDate' | abpLocalization" prop="publishDate">
            <ng-template let-row="row" ngx-datatable-cell-template>
              {{ row.publishDate | date }}
            </ng-template>
          </ngx-datatable-column>
          <ngx-datatable-column [name]="'::Price' | abpLocalization" prop="price">
            <ng-template let-row="row" ngx-datatable-cell-template>
              {{ row.price | currency }}
            </ng-template>
          </ngx-datatable-column>
        </ngx-datatable>
      </div>
    </div>

      

    记录编程的点滴,体会学习的乐趣
  • 相关阅读:
    Android动画系列
    Handler处理机制
    cp命令覆盖文件时不用按Y来确认的方法
    phantomjs
    无界面模式
    win10上安装keras
    MongoDB 排序
    MongoDB 条件操作符
    MongoDB 对象操作
    SQL 和 NoSQL 的区别
  • 原文地址:https://www.cnblogs.com/AduBlog/p/13424097.html
Copyright © 2020-2023  润新知