Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user过滤 & 合同页面异常捕获 #200

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {
Body,
Controller,
DefaultValuePipe,
Delete,
Get,
HttpException,
HttpStatus,
Param,
ParseArrayPipe,
ParseEnumPipe,
ParseIntPipe,
Patch,
Post,
Put,
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -84,7 +84,12 @@ export class UserService {
}

//获取所有用户信息
async getAllUser(paginationQuery: PaginationQueryDto): Promise<any> {
async getAllUser(
paginationQuery: PaginationQueryDto,
name?: string,
role?: number[],
email?: string
): Promise<any> {
const { page, limit } = paginationQuery; // 从DTO获取分页参数
const relations = ['role', 'role.permission'];
const result = await paginate<User>(
Expand All @@ -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) {
Expand Down
22 changes: 20 additions & 2 deletions packages/toolkits/pro/template/tinyvue/src/api/user.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -50,8 +51,25 @@ export function logout(data: LogoutData) {
}

// 获取全部用户
export function getAllUser(page?: number, limit?: number) {
return axios.get<UserInfo>(`/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<UserInfo>(`/api/user?${params.toString()}`);
}

// 获取单个用户
Expand Down
12 changes: 12 additions & 0 deletions packages/toolkits/pro/template/tinyvue/src/types/global.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
export type FilterType = {
[key: string]: {
type: string;
value:
| {
text: string;
relation: string;
}
| number[];
};
};

export interface AnyObject {
[key: string]: unknown;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] };
});
}
}
Loading