From e3ec40193e01a85de5be2c4afcc92f3f64968c21 Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 13 Jul 2023 18:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.ts | 5 +- src/access.ts | 4 +- src/pages/Admin.tsx | 44 --------- src/pages/Admin/UserManage/index.tsx | 134 +++++++++++++++++++++++++++ src/services/answerbi/typings.d.ts | 1 + 5 files changed, 139 insertions(+), 49 deletions(-) delete mode 100644 src/pages/Admin.tsx create mode 100644 src/pages/Admin/UserManage/index.tsx diff --git a/config/routes.ts b/config/routes.ts index 28811a7..e3a3341 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -14,11 +14,10 @@ export default [ icon: 'crown', access: 'canAdmin', routes: [ - { path: '/admin', redirect: '/admin/sub-page' }, - { path: '/admin/sub-page', name: '二级管理页', component: './Admin' }, + { path: '/admin', redirect: 'user-manage' }, + { path: '/admin/user-manage', name: '用户管理', icon: 'smile', component: './Admin/UserManage' }, ], }, - { name: '查询表格', icon: 'table', path: '/list', component: './TableList' }, { path: '/', redirect: '/welcome' }, { path: '*', layout: false, component: './404' }, ]; diff --git a/src/access.ts b/src/access.ts index e823e24..41f9829 100644 --- a/src/access.ts +++ b/src/access.ts @@ -1,9 +1,9 @@ /** * @see https://umijs.org/zh-CN/plugins/plugin-access * */ -export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) { +export default function access(initialState: { currentUser?: API.LoginUserVO } | undefined) { const { currentUser } = initialState ?? {}; return { - canAdmin: currentUser && currentUser.access === 'admin', + canAdmin: currentUser && currentUser.userRole === 'admin', }; } diff --git a/src/pages/Admin.tsx b/src/pages/Admin.tsx deleted file mode 100644 index 71277ef..0000000 --- a/src/pages/Admin.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import { HeartTwoTone, SmileTwoTone } from '@ant-design/icons'; -import { PageContainer } from '@ant-design/pro-components'; -import '@umijs/max'; -import { Alert, Card, Typography } from 'antd'; -import React from 'react'; -const Admin: React.FC = () => { - return ( - - - - - Ans智能BI You - - -

- Want to add more pages? Please refer to{' '} - - use block - - 。 -

-
- ); -}; -export default Admin; diff --git a/src/pages/Admin/UserManage/index.tsx b/src/pages/Admin/UserManage/index.tsx new file mode 100644 index 0000000..d9ce777 --- /dev/null +++ b/src/pages/Admin/UserManage/index.tsx @@ -0,0 +1,134 @@ +import { listUserVOByPageUsingPOST } from '@/services/answerbi/userController'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; +import { ProTable, TableDropdown } from '@ant-design/pro-components'; +import { useRef } from 'react'; +export const waitTimePromise = async (time: number = 100) => { + return new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, time); + }); +}; + +export const waitTime = async (time: number = 100) => { + await waitTimePromise(time); +}; + +const columns: ProColumns[] = [ + { + dataIndex: 'id', + valueType: 'indexBorder', + width: 48, + }, + { + title: '昵称', + dataIndex: 'userName', + copyable: true, + }, + { + title: '用户账号', + dataIndex: 'userAccount', + copyable: true, + }, + { + title: '头像', + dataIndex: 'userAvatar', + render: (_, record) => ( +
+ +
+ ) + }, + { + title: '角色', + dataIndex: 'userRole', + }, + { + title: '创建时间', + dataIndex: 'createdTime', + valueType: 'dateTime', + }, + + + { + title: '操作', + valueType: 'option', + key: 'option', + render: (text, record, _, action) => [ + { + action?.startEditable?.(record.id); + }} + > + 编辑 + , + + 查看 + , + action?.reload()} + menus={[ + { key: 'copy', name: '复制' }, + { key: 'delete', name: '删除' }, + ]} + />, + ], + }, +]; + +export default () => { + const actionRef = useRef(); + return ( + + columns={columns} + actionRef={actionRef} + cardBordered + request={async (params = {}, sort, filter) => { + console.log(sort, filter); + const userList = await listUserVOByPageUsingPOST(params); + return { + data: userList + }; + }} + editable={{ + type: 'multiple', + }} + columnsState={{ + persistenceKey: 'pro-table-singe-demos', + persistenceType: 'localStorage', + onChange(value) { + console.log('value: ', value); + }, + }} + rowKey="id" + search={{ + labelWidth: 'auto', + }} + options={{ + setting: { + listsHeight: 400, + }, + }} + form={{ + // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下 + syncToUrl: (values, type) => { + if (type === 'get') { + return { + ...values, + created_at: [values.startTime, values.endTime], + }; + } + return values; + }, + }} + pagination={{ + pageSize: 5, + onChange: (page) => console.log(page), + }} + dateFormatter="string" + headerTitle="高级表格" + /> + ); +}; \ No newline at end of file diff --git a/src/services/answerbi/typings.d.ts b/src/services/answerbi/typings.d.ts index 11f143d..8622e56 100644 --- a/src/services/answerbi/typings.d.ts +++ b/src/services/answerbi/typings.d.ts @@ -351,6 +351,7 @@ declare namespace API { id?: number; userAvatar?: string; userName?: string; + userAccount?: string; userProfile?: string; userRole?: string; };