diff --git a/Nest-server/src/modules/column/column.controller.ts b/Nest-server/src/modules/column/column.controller.ts index fba31af..3f5083b 100644 --- a/Nest-server/src/modules/column/column.controller.ts +++ b/Nest-server/src/modules/column/column.controller.ts @@ -16,6 +16,8 @@ import { UserInfoPipe } from '../../common/pipes/user-info.pipe'; import { DataObj } from '../../common/class/data-obj.class'; import { Public } from '../../common/decorators/public.decorator'; import { ApiException } from '../../common/exceptions/api.exception'; +import { PaginationPipe } from '../../common/pipes/pagination.pipe'; +import { QueryColumnDto } from './dto/query-column.dto'; @Controller('column') export class ColumnController { @@ -36,14 +38,14 @@ export class ColumnController { @Public() @Get('list') - list() { - return this.columnService.findPageList(); + list(@Query(PaginationPipe) queryColumnDto: QueryColumnDto) { + return this.columnService.findPageList(queryColumnDto); } @Public() @Get('all') - async all() { - const data = await this.columnService.findAll(); + async all(@Query(PaginationPipe) queryColumnDto: QueryColumnDto) { + const data = await this.columnService.findAll(queryColumnDto); return new DataObj(data); } diff --git a/Nest-server/src/modules/column/column.service.ts b/Nest-server/src/modules/column/column.service.ts index 1c3d265..7f1f97a 100644 --- a/Nest-server/src/modules/column/column.service.ts +++ b/Nest-server/src/modules/column/column.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; +import { FindOptionsWhere, Repository } from 'typeorm'; import { CreateColumnDto } from './dto/create-column.dto'; +import { QueryColumnDto } from './dto/query-column.dto'; import { UpdateColumnDto } from './dto/update-column.dto'; import { Columns } from './entities/column.entity'; @@ -16,16 +17,28 @@ export class ColumnService { await this.columnsRepository.save(createColumnDto); } - async findPageList() { - const [rows, total] = await this.columnsRepository.findAndCount(); + async findPageList(queryColumnDto: QueryColumnDto) { + const where: FindOptionsWhere = {}; + if (queryColumnDto.type) { + where.type = queryColumnDto.type; + } + const [rows, total] = await this.columnsRepository.findAndCount({ + where, + take: queryColumnDto.take, + skip: queryColumnDto.skip, + }); return { rows, total, }; } - async findAll() { - return this.columnsRepository.find(); + async findAll(queryColumnDto: QueryColumnDto) { + const where: FindOptionsWhere = {}; + if (queryColumnDto.type) { + where.type = queryColumnDto.type; + } + return this.columnsRepository.findBy(where); } findOne(where) { diff --git a/Nest-server/src/modules/column/dto/query-column.dto.ts b/Nest-server/src/modules/column/dto/query-column.dto.ts new file mode 100644 index 0000000..8d95654 --- /dev/null +++ b/Nest-server/src/modules/column/dto/query-column.dto.ts @@ -0,0 +1,7 @@ +import { PaginationDto } from '../../../common/dto/pagination.dto'; +import { IsOptional } from 'class-validator'; + +export class QueryColumnDto extends PaginationDto { + @IsOptional() + type: string; +} diff --git a/Nest-server/src/modules/web/index/index.service.ts b/Nest-server/src/modules/web/index/index.service.ts index 48ccaf0..86da6f7 100644 --- a/Nest-server/src/modules/web/index/index.service.ts +++ b/Nest-server/src/modules/web/index/index.service.ts @@ -27,7 +27,14 @@ export class IndexService { 'genre', 'genre.columnValue = columns.value', ) - .select(['columns.name', 'columns.value', 'genre.id', 'genre.name']) + .select([ + 'columns.name', + 'columns.value', + 'columns.type', + 'genre.id', + 'genre.name', + ]) + .where('columns.type = :type', { type: 1 }) .orderBy('columns.order', 'ASC') .addOrderBy('genre.id', 'ASC'); diff --git a/Vue3-admin/src/components/TablePro/index.vue b/Vue3-admin/src/components/TablePro/index.vue index 287185d..8df495f 100644 --- a/Vue3-admin/src/components/TablePro/index.vue +++ b/Vue3-admin/src/components/TablePro/index.vue @@ -4,7 +4,7 @@