|
| 1 | +import { Suspense, lazy } from 'react'; |
| 2 | + |
| 3 | +import { enableStatusRecord, userGenderRecord } from '@/constants/business'; |
| 4 | +import { ATG_MAP } from '@/constants/common'; |
| 5 | +import { TableHeaderOperation, useTable, useTableOperate, useTableScroll } from '@/features/table'; |
| 6 | +import { fetchGetUserList } from '@/service/api'; |
| 7 | + |
| 8 | +import UserSearch from './modules/UserSearch'; |
| 9 | + |
| 10 | +const UserOperateDrawer = lazy(() => import('./modules/UserOperateDrawer')); |
| 11 | + |
| 12 | +const tagUserGenderMap: Record<Api.SystemManage.UserGender, string> = { |
| 13 | + 1: 'processing', |
| 14 | + 2: 'error' |
| 15 | +}; |
| 16 | + |
1 | 17 | const UserManage = () => {
|
2 |
| - return <AInput />; |
| 18 | + const { t } = useTranslation(); |
| 19 | + |
| 20 | + const { scrollConfig, tableWrapperRef } = useTableScroll(); |
| 21 | + |
| 22 | + const nav = useNavigate(); |
| 23 | + |
| 24 | + const isMobile = useMobile(); |
| 25 | + |
| 26 | + const { columnChecks, data, run, searchProps, setColumnChecks, tableProps } = useTable( |
| 27 | + { |
| 28 | + apiFn: fetchGetUserList, |
| 29 | + apiParams: { |
| 30 | + current: 1, |
| 31 | + nickName: null, |
| 32 | + size: 10, |
| 33 | + // if you want to use the searchParams in Form, you need to define the following properties, and the value is null |
| 34 | + // the value can not be undefined, otherwise the property in Form will not be reactive |
| 35 | + status: null, |
| 36 | + userEmail: null, |
| 37 | + userGender: null, |
| 38 | + userName: null, |
| 39 | + userPhone: null |
| 40 | + }, |
| 41 | + columns: () => [ |
| 42 | + { |
| 43 | + align: 'center', |
| 44 | + dataIndex: 'index', |
| 45 | + key: 'index', |
| 46 | + title: t('common.index'), |
| 47 | + width: 64 |
| 48 | + }, |
| 49 | + { |
| 50 | + align: 'center', |
| 51 | + dataIndex: 'userName', |
| 52 | + key: 'userName', |
| 53 | + minWidth: 100, |
| 54 | + title: t('page.manage.user.userName') |
| 55 | + }, |
| 56 | + { |
| 57 | + align: 'center', |
| 58 | + dataIndex: 'userGender', |
| 59 | + key: 'userGender', |
| 60 | + render: (_, record) => { |
| 61 | + if (record?.userGender === null) { |
| 62 | + return null; |
| 63 | + } |
| 64 | + |
| 65 | + const label = t(userGenderRecord[record.userGender]); |
| 66 | + |
| 67 | + return <ATag color={tagUserGenderMap[record.userGender]}>{label}</ATag>; |
| 68 | + }, |
| 69 | + title: t('page.manage.user.userGender'), |
| 70 | + width: 100 |
| 71 | + }, |
| 72 | + { |
| 73 | + align: 'center', |
| 74 | + dataIndex: 'nickName', |
| 75 | + key: 'nickName', |
| 76 | + minWidth: 100, |
| 77 | + title: t('page.manage.user.nickName') |
| 78 | + }, |
| 79 | + { |
| 80 | + align: 'center', |
| 81 | + dataIndex: 'userPhone', |
| 82 | + key: 'userPhone', |
| 83 | + title: t('page.manage.user.userPhone'), |
| 84 | + width: 120 |
| 85 | + }, |
| 86 | + { |
| 87 | + align: 'center', |
| 88 | + dataIndex: 'userEmail', |
| 89 | + key: 'userEmail', |
| 90 | + minWidth: 200, |
| 91 | + title: t('page.manage.user.userEmail') |
| 92 | + }, |
| 93 | + { |
| 94 | + align: 'center', |
| 95 | + dataIndex: 'status', |
| 96 | + key: 'status', |
| 97 | + render: (_, record) => { |
| 98 | + if (record.status === null) { |
| 99 | + return null; |
| 100 | + } |
| 101 | + const label = t(enableStatusRecord[record.status]); |
| 102 | + return <ATag color={ATG_MAP[record.status]}>{label}</ATag>; |
| 103 | + }, |
| 104 | + title: t('page.manage.user.userStatus'), |
| 105 | + width: 100 |
| 106 | + }, |
| 107 | + { |
| 108 | + align: 'center', |
| 109 | + key: 'operate', |
| 110 | + render: (_, record) => ( |
| 111 | + <div className="flex-center gap-8px"> |
| 112 | + <AButton |
| 113 | + ghost |
| 114 | + size="small" |
| 115 | + type="primary" |
| 116 | + onClick={() => edit(record.id)} |
| 117 | + > |
| 118 | + {t('common.edit')} |
| 119 | + </AButton> |
| 120 | + <AButton |
| 121 | + size="small" |
| 122 | + onClick={() => nav(`/manage/user/${record.id}`)} |
| 123 | + > |
| 124 | + 详情 |
| 125 | + </AButton> |
| 126 | + <APopconfirm |
| 127 | + title={t('common.confirmDelete')} |
| 128 | + onConfirm={() => handleDelete(record.id)} |
| 129 | + > |
| 130 | + <AButton |
| 131 | + danger |
| 132 | + size="small" |
| 133 | + > |
| 134 | + {t('common.delete')} |
| 135 | + </AButton> |
| 136 | + </APopconfirm> |
| 137 | + </div> |
| 138 | + ), |
| 139 | + title: t('common.operate'), |
| 140 | + width: 195 |
| 141 | + } |
| 142 | + ] |
| 143 | + }, |
| 144 | + { showQuickJumper: true } |
| 145 | + ); |
| 146 | + |
| 147 | + const { checkedRowKeys, generalPopupOperation, handleAdd, handleEdit, onBatchDeleted, onDeleted, rowSelection } = |
| 148 | + useTableOperate(data, run, async (res, type) => { |
| 149 | + if (type === 'add') { |
| 150 | + // add request 调用新增的接口 |
| 151 | + console.log(res); |
| 152 | + } else { |
| 153 | + // edit request 调用编辑的接口 |
| 154 | + console.log(res); |
| 155 | + } |
| 156 | + }); |
| 157 | + |
| 158 | + async function handleBatchDelete() { |
| 159 | + // request |
| 160 | + console.log(checkedRowKeys); |
| 161 | + onBatchDeleted(); |
| 162 | + } |
| 163 | + |
| 164 | + function handleDelete(id: number) { |
| 165 | + // request |
| 166 | + console.log(id); |
| 167 | + |
| 168 | + onDeleted(); |
| 169 | + } |
| 170 | + |
| 171 | + function edit(id: number) { |
| 172 | + handleEdit(id); |
| 173 | + } |
| 174 | + return ( |
| 175 | + <div className="h-full min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto"> |
| 176 | + <ACollapse |
| 177 | + bordered={false} |
| 178 | + className="card-wrapper" |
| 179 | + defaultActiveKey={isMobile ? undefined : '1'} |
| 180 | + items={[ |
| 181 | + { |
| 182 | + children: <UserSearch {...searchProps} />, |
| 183 | + key: '1', |
| 184 | + label: t('common.search') |
| 185 | + } |
| 186 | + ]} |
| 187 | + /> |
| 188 | + |
| 189 | + <ACard |
| 190 | + className="flex-col-stretch sm:flex-1-hidden card-wrapper" |
| 191 | + ref={tableWrapperRef} |
| 192 | + title={t('page.manage.user.title')} |
| 193 | + variant="borderless" |
| 194 | + extra={ |
| 195 | + <TableHeaderOperation |
| 196 | + add={handleAdd} |
| 197 | + columns={columnChecks} |
| 198 | + disabledDelete={checkedRowKeys.length === 0} |
| 199 | + loading={tableProps.loading} |
| 200 | + refresh={run} |
| 201 | + setColumnChecks={setColumnChecks} |
| 202 | + onDelete={handleBatchDelete} |
| 203 | + /> |
| 204 | + } |
| 205 | + > |
| 206 | + <ATable |
| 207 | + rowSelection={rowSelection} |
| 208 | + scroll={scrollConfig} |
| 209 | + size="small" |
| 210 | + {...tableProps} |
| 211 | + /> |
| 212 | + <Suspense> |
| 213 | + <UserOperateDrawer {...generalPopupOperation} /> |
| 214 | + </Suspense> |
| 215 | + </ACard> |
| 216 | + </div> |
| 217 | + ); |
3 | 218 | };
|
4 | 219 |
|
5 | 220 | export const handle = {
|
|
0 commit comments