Skip to content

Commit

Permalink
用户端过滤菜单类型
Browse files Browse the repository at this point in the history
  • Loading branch information
yinMrsir committed Apr 21, 2023
1 parent 801f768 commit 4520124
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
10 changes: 6 additions & 4 deletions Nest-server/src/modules/column/column.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}

Expand Down
23 changes: 18 additions & 5 deletions Nest-server/src/modules/column/column.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<Columns> = {};
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<Columns> = {};
if (queryColumnDto.type) {
where.type = queryColumnDto.type;
}
return this.columnsRepository.findBy(where);
}

findOne(where) {
Expand Down
7 changes: 7 additions & 0 deletions Nest-server/src/modules/column/dto/query-column.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PaginationDto } from '../../../common/dto/pagination.dto';
import { IsOptional } from 'class-validator';

export class QueryColumnDto extends PaginationDto {
@IsOptional()
type: string;
}
9 changes: 8 additions & 1 deletion Nest-server/src/modules/web/index/index.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion Vue3-admin/src/components/TablePro/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<template v-for="item in filterOptions">
<el-form-item :label="item.title" :prop="item.field">
<template v-for="item in filterOptions">
<template v-if="item.type === 'select'">
<template v-if="item.type === 'select' || item.type === 'radio'">
<el-select v-model="queryParams[item.field]" :placeholder="`请选择${item.title}`" clearable>
<el-option
v-for="item in item.options"
Expand Down
5 changes: 3 additions & 2 deletions Vue3-admin/src/views/column/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const columns = ref([
field: 'type',
type: 'radio',
options: column_type,
add: true
add: true,
search: true
},
{
title: '目录/路径',
Expand All @@ -42,4 +43,4 @@ const columns = ref([
}
])
</script>
</script>

0 comments on commit 4520124

Please sign in to comment.