diff --git a/packages/toolkits/pro/template/server/nestJs/src/user/user.controller.ts b/packages/toolkits/pro/template/server/nestJs/src/user/user.controller.ts index 1736a1b5..f13aec44 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/user/user.controller.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/user/user.controller.ts @@ -1,11 +1,15 @@ import { Body, Controller, + DefaultValuePipe, Delete, Get, HttpException, HttpStatus, Param, + ParseArrayPipe, + ParseEnumPipe, + ParseIntPipe, Patch, Post, Put, @@ -57,8 +61,13 @@ export class UserController { } @Get() @Permission('user::query') - async getAllUser(@Query() paginationQuery: PaginationQueryDto) { - return this.userService.getAllUser(paginationQuery); + async getAllUser( + @Query() paginationQuery: PaginationQueryDto, + @Query('name') name?: string, + @Query('role', new DefaultValuePipe([]), ParseArrayPipe) role?: number[], + @Query('email') email?: string + ) { + return this.userService.getAllUser(paginationQuery, name, role, email); } @Patch('/admin/updatePwd') diff --git a/packages/toolkits/pro/template/server/nestJs/src/user/user.service.ts b/packages/toolkits/pro/template/server/nestJs/src/user/user.service.ts index 23eec02c..cd0bf313 100644 --- a/packages/toolkits/pro/template/server/nestJs/src/user/user.service.ts +++ b/packages/toolkits/pro/template/server/nestJs/src/user/user.service.ts @@ -6,7 +6,7 @@ import { UpdatePwdAdminDto } from './dto/update-pwd-admin.dto'; import { UpdatePwdUserDto } from './dto/update-pwd-user.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { Role, User } from '@app/models'; -import { In, Repository } from 'typeorm'; +import { In, Like, Repository } from 'typeorm'; import * as crypto from 'crypto'; import { AuthService } from '../auth/auth.service'; import { paginate, IPaginationOptions } from 'nestjs-typeorm-paginate'; @@ -84,7 +84,12 @@ export class UserService { } //获取所有用户信息 - async getAllUser(paginationQuery: PaginationQueryDto): Promise { + async getAllUser( + paginationQuery: PaginationQueryDto, + name?: string, + role?: number[], + email?: string + ): Promise { const { page, limit } = paginationQuery; // 从DTO获取分页参数 const relations = ['role', 'role.permission']; const result = await paginate( @@ -109,6 +114,16 @@ export class UserService { 'status', ], relations, + where: { + name: name ? Like(name) : undefined, + role: + role && role.length + ? { + id: In(role), + } + : undefined, + email: email ? Like(email) : undefined, + }, } ); for (const user of result.items) { diff --git a/packages/toolkits/pro/template/tinyvue/src/api/user.ts b/packages/toolkits/pro/template/tinyvue/src/api/user.ts index 92c038bb..c105d5f7 100644 --- a/packages/toolkits/pro/template/tinyvue/src/api/user.ts +++ b/packages/toolkits/pro/template/tinyvue/src/api/user.ts @@ -1,5 +1,6 @@ import axios from 'axios'; import { UserInfo } from '@/store/modules/user/types'; +import { FilterType } from '@/types/global'; export interface LoginData { email: string; @@ -50,8 +51,25 @@ export function logout(data: LogoutData) { } // 获取全部用户 -export function getAllUser(page?: number, limit?: number) { - return axios.get(`/api/user?page=${page}&limit=${limit}`); +export function getAllUser(page?: number, limit?: number, filter?: FilterType) { + const keys = Object.keys(filter ?? {}); + const params = new URLSearchParams(); + params.set('page', page.toString()); + params.set('limit', limit.toString()); + for (let i = 0; i < keys.length; i += 1) { + const key = keys[i]; + const value = filter[key]; + if (value.type === 'enum') { + if (Array.isArray(value.value) && value.value.length) { + params.set(key, value.value.toString()); + } + } + if (value.type === 'input' && !Array.isArray(value.value)) { + let sql = `${value.value.relation === 'startwith' || value.value.relation === 'contains' ? '%' : ''}${value.value.text}${value.value.relation === 'contains' ? '%' : ''}`; + params.set(key, sql); + } + } + return axios.get(`/api/user?${params.toString()}`); } // 获取单个用户 diff --git a/packages/toolkits/pro/template/tinyvue/src/types/global.ts b/packages/toolkits/pro/template/tinyvue/src/types/global.ts index ae6ca9ed..234bf38b 100644 --- a/packages/toolkits/pro/template/tinyvue/src/types/global.ts +++ b/packages/toolkits/pro/template/tinyvue/src/types/global.ts @@ -1,3 +1,15 @@ +export type FilterType = { + [key: string]: { + type: string; + value: + | { + text: string; + relation: string; + } + | number[]; + }; +}; + export interface AnyObject { [key: string]: unknown; } diff --git a/packages/toolkits/pro/template/tinyvue/src/utils/hwcClient.service.ts b/packages/toolkits/pro/template/tinyvue/src/utils/hwcClient.service.ts index d32389f4..2a53b7c3 100644 --- a/packages/toolkits/pro/template/tinyvue/src/utils/hwcClient.service.ts +++ b/packages/toolkits/pro/template/tinyvue/src/utils/hwcClient.service.ts @@ -4,18 +4,21 @@ import BaseUtils from '@/utils/base-utils'; export class HwcClientService { static async apiRequest(fnName: string, params: any, apigInfo: ApigInfo) { - try { - const response = await HwcClient.apigClient.exec( - apigInfo.apigGroupName, - apigInfo.apigName, - { - query: { fn_name: fnName }, - body: JSON.stringify(params), + return HwcClient.apigClient + .exec(apigInfo.apigGroupName, apigInfo.apigName, { + query: { fn_name: fnName }, + body: JSON.stringify(params), + }) + .then((rep) => { + if (rep.ok) { + return rep; } - ); - return await response?.json(); - } catch (error) { - return BaseUtils.getErrorMessage(error); - } + throw new Error(); + }) + .then((rep) => rep.json()) + .then((rep) => (rep.error_code ? { data: [] } : rep)) + .catch((err) => { + return { data: [] }; + }); } } diff --git a/packages/toolkits/pro/template/tinyvue/src/views/cloud/contracts/index.vue b/packages/toolkits/pro/template/tinyvue/src/views/cloud/contracts/index.vue index a95ce6d1..50c989c6 100644 --- a/packages/toolkits/pro/template/tinyvue/src/views/cloud/contracts/index.vue +++ b/packages/toolkits/pro/template/tinyvue/src/views/cloud/contracts/index.vue @@ -1,107 +1,4 @@ - - -