Skip to content

Commit 1dfe464

Browse files
author
guosw
committed
feat: New user type filter on user management page
1 parent 5ceba4a commit 1dfe464

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

server/controllers/user.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,25 @@ class UserController {
172172
static async getList(ctx) {
173173
const validator = ctx.validate(ctx.query, {
174174
username: Joi.string().allow(''),
175+
type: Joi.number(), // 检索类型 type = 1 github 用户 type = 2 站内用户 不传则检索所有
175176
page: Joi.string(),
176177
pageSize: Joi.number()
177178
})
178179

179180
if (validator) {
180-
const { page = 1, pageSize = 10, username } = ctx.query
181+
const { page = 1, pageSize = 10, username, type } = ctx.query
181182
const where = {
182-
role: {
183-
$not: 1
184-
}
183+
role: { $not: 1 }
185184
}
185+
186186
if (username) {
187187
where.username = {}
188188
where.username['$like'] = `%${username}%`
189189
}
190+
191+
if (type) {
192+
where.github = parseInt(type) === 1 ? { $not: null } : null
193+
}
190194
const result = await UserModel.findAndCountAll({
191195
where,
192196
offset: (page - 1) * pageSize,

src/views/admin/user/index.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import React, { useState } from 'react'
2-
import { Table, Input, Tag, Form, Switch, Button, Popconfirm } from 'antd'
2+
import { Table, Input, Tag, Form, Switch, Button, Popconfirm, Select } from 'antd'
33

44
import axios from '@/utils/axios'
55
import moment from 'moment'
66

77
import useAntdTable from '@/hooks/useAntdTable'
88
import useBreadcrumb from '@/hooks/useBreadcrumb'
99

10+
const typeMapList = [
11+
{ value: 1, label: 'github 用户' },
12+
{ value: 2, label: '站内用户' }
13+
]
14+
1015
function AdminUser(props) {
1116
useBreadcrumb(['用户管理'])
1217
const { getFieldDecorator } = props.form
@@ -83,6 +88,18 @@ function AdminUser(props) {
8388
)}
8489
</Form.Item>
8590

91+
<Form.Item label='用户类型'>
92+
{getFieldDecorator('type')(
93+
<Select style={{ width: 200 }} allowClear>
94+
{typeMapList.map(item => (
95+
<Select.Option key={item.value} value={item.value}>
96+
{item.label}
97+
</Select.Option>
98+
))}
99+
</Select>
100+
)}
101+
</Form.Item>
102+
86103
<Form.Item>
87104
<Button type='primary' htmlType='submit' style={{ marginRight: 8 }}>检索</Button>
88105

0 commit comments

Comments
 (0)