feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
@@ -16,19 +16,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import TableEmpty from '../../components/common/table/TableEmpty';
|
||||
import TableToolbar from '../../components/common/table/TableToolbar';
|
||||
import {
|
||||
ConsoleCard,
|
||||
ConsoleSearchBar,
|
||||
} from '../../components/console/ConsolePrimitives';
|
||||
import { ConsolePageActions } from '../../components/console/ConsolePageContainer';
|
||||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
Building2,
|
||||
Plus,
|
||||
Search,
|
||||
Pencil,
|
||||
ExternalLink,
|
||||
BarChart3,
|
||||
Bell,
|
||||
BellOff,
|
||||
} from 'lucide-react';
|
||||
import { Plus, Search, ExternalLink, BarChart3, Bell } from 'lucide-react';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
@@ -85,6 +84,11 @@ const VISIBLE_ORG_FEATURE_KEYS = CLOUD_BRAIN_UI_ENABLED
|
||||
({ key }) => !CLOUD_BRAIN_ORG_FEATURE_KEYS.has(key),
|
||||
);
|
||||
|
||||
import {
|
||||
ConsoleFilterField,
|
||||
ConsoleFilterActions,
|
||||
} from '../../components/console/ConsoleModuleFilters';
|
||||
|
||||
const AdminOrganizations = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
@@ -92,8 +96,10 @@ const AdminOrganizations = () => {
|
||||
const [total, setTotal] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(20);
|
||||
const [keyword, setKeyword] = useState('');
|
||||
const [searchKeyword, setSearchKeyword] = useState('');
|
||||
const [queryVersion, setQueryVersion] = useState(0);
|
||||
const [quotaModalVisible, setQuotaModalVisible] = useState(false);
|
||||
const [quotaOrgId, setQuotaOrgId] = useState(null);
|
||||
const [quotaAmount, setQuotaAmount] = useState(0);
|
||||
@@ -303,7 +309,7 @@ const AdminOrganizations = () => {
|
||||
const seq = ++fetchSeqRef.current;
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = { p: page, page_size: 20 };
|
||||
const params = { p: page, page_size: pageSize };
|
||||
if (searchKeyword) params.keyword = searchKeyword;
|
||||
if (statusFilter != null) params.status = statusFilter;
|
||||
if (levelFilter) params.level = levelFilter;
|
||||
@@ -318,6 +324,8 @@ const AdminOrganizations = () => {
|
||||
if (res.data.success) {
|
||||
setOrgs(res.data.data?.items || []);
|
||||
setTotal(res.data.data?.total || 0);
|
||||
} else {
|
||||
showError(res.data.message || t('查询失败'));
|
||||
}
|
||||
} catch (err) {
|
||||
if (seq === fetchSeqRef.current) showError(err.message);
|
||||
@@ -326,6 +334,7 @@ const AdminOrganizations = () => {
|
||||
}
|
||||
}, [
|
||||
page,
|
||||
pageSize,
|
||||
searchKeyword,
|
||||
statusFilter,
|
||||
levelFilter,
|
||||
@@ -333,11 +342,12 @@ const AdminOrganizations = () => {
|
||||
userIdFilter,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
t,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchOrgs();
|
||||
}, [fetchOrgs]);
|
||||
}, [fetchOrgs, queryVersion]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchGroups();
|
||||
@@ -352,15 +362,15 @@ const AdminOrganizations = () => {
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const hasActiveFilters =
|
||||
!!searchKeyword ||
|
||||
statusFilter != null ||
|
||||
!!levelFilter ||
|
||||
!!salesRepFilter ||
|
||||
!!userIdFilter ||
|
||||
!!sortBy;
|
||||
const handleSearch = () => {
|
||||
setPage(1);
|
||||
setSearchKeyword(keyword.trim());
|
||||
setUserIdFilter(userIdInput);
|
||||
setQueryVersion((version) => version + 1);
|
||||
};
|
||||
|
||||
const resetFilters = () => {
|
||||
setQueryVersion((version) => version + 1);
|
||||
setKeyword('');
|
||||
setSearchKeyword('');
|
||||
setStatusFilter(undefined);
|
||||
@@ -375,10 +385,11 @@ const AdminOrganizations = () => {
|
||||
|
||||
// 服务端排序:列头点击 → 下推 sort_by/sort_order 重新拉取
|
||||
const sortOrderFor = (key) =>
|
||||
sortBy === key ? (sortOrder === 'asc' ? 'ascend' : 'descend') : false;
|
||||
sortBy === key ? (sortOrder === 'asc' ? 'ascend' : 'descend') : null;
|
||||
|
||||
const handleTableChange = ({ sorter }) => {
|
||||
if (!sorter || !sorter.dataIndex) return;
|
||||
// Ant Design clears both the field and order when sorting is cancelled.
|
||||
if (!sorter || (sorter.sortOrder && !sorter.dataIndex)) return;
|
||||
const nextBy = sorter.sortOrder ? sorter.dataIndex : '';
|
||||
const nextOrder = sorter.sortOrder
|
||||
? sorter.sortOrder === 'ascend'
|
||||
@@ -805,22 +816,21 @@ const AdminOrganizations = () => {
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 320,
|
||||
width: 380,
|
||||
render: (_, record) => (
|
||||
<div className='flex items-center gap-1.5 flex-nowrap'>
|
||||
<div className='console-module-row-actions'>
|
||||
{isAdmin() && (
|
||||
<>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<Pencil size={14} />}
|
||||
onClick={() => openEditModal(record)}
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
theme='light'
|
||||
onClick={() => {
|
||||
setQuotaOrgId(record.id);
|
||||
setQuotaAmount(0);
|
||||
@@ -830,8 +840,8 @@ const AdminOrganizations = () => {
|
||||
{t('调额')}
|
||||
</Button>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
theme='light'
|
||||
onClick={() => openFeatureModal(record)}
|
||||
>
|
||||
{t('功能开关')}
|
||||
@@ -839,8 +849,7 @@ const AdminOrganizations = () => {
|
||||
{record.status === 4 ? (
|
||||
<Button
|
||||
size='small'
|
||||
theme='solid'
|
||||
type='primary'
|
||||
type='link'
|
||||
onClick={() => handleActivate(record.id)}
|
||||
>
|
||||
{t('激活')}
|
||||
@@ -848,8 +857,7 @@ const AdminOrganizations = () => {
|
||||
) : record.status === 1 ? (
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='warning'
|
||||
type='link'
|
||||
onClick={() => handleStatusChange(record.id, 2)}
|
||||
>
|
||||
{t('冻结')}
|
||||
@@ -857,17 +865,16 @@ const AdminOrganizations = () => {
|
||||
) : (
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
type='primary'
|
||||
type='link'
|
||||
onClick={() => handleStatusChange(record.id, 1)}
|
||||
>
|
||||
{t('解冻')}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
theme='light'
|
||||
type='danger'
|
||||
danger
|
||||
onClick={() => handleDelete(record.id)}
|
||||
>
|
||||
{t('删除')}
|
||||
@@ -875,16 +882,8 @@ const AdminOrganizations = () => {
|
||||
{isRoot() && (
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
type='link'
|
||||
loading={alertToggleLoading === record.id}
|
||||
icon={
|
||||
alertExcludedIds.has(record.id) ? (
|
||||
<BellOff size={14} />
|
||||
) : (
|
||||
<Bell size={14} />
|
||||
)
|
||||
}
|
||||
title={
|
||||
alertExcludedIds.has(record.id)
|
||||
? t('已屏蔽预警,点击恢复')
|
||||
@@ -896,7 +895,11 @@ const AdminOrganizations = () => {
|
||||
: t('屏蔽该企业的预警')
|
||||
}
|
||||
onClick={() => toggleAlertExclude(record)}
|
||||
/>
|
||||
>
|
||||
{alertExcludedIds.has(record.id)
|
||||
? t('恢复通知')
|
||||
: t('屏蔽通知')}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
@@ -906,114 +909,109 @@ const AdminOrganizations = () => {
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='mt-[60px] p-4 sm:p-6'>
|
||||
<div className='flex items-center justify-between mb-6'>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div className='p-2 rounded-xl bg-gradient-to-br from-blue-500 to-brand-to'>
|
||||
<Building2 size={24} className='text-white' />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className='text-2xl font-bold text-gray-900 dark:text-white'>
|
||||
{t('企业管理')}
|
||||
</h1>
|
||||
<p className='text-sm text-gray-500 dark:text-gray-400'>
|
||||
{t('管理所有企业账户')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='mb-4 flex items-start justify-between flex-wrap gap-3'>
|
||||
<div className='flex items-center flex-wrap gap-2'>
|
||||
<Input
|
||||
prefix={<Search size={16} />}
|
||||
value={keyword}
|
||||
onChange={(v) => {
|
||||
setKeyword(v);
|
||||
// 退格删空/点清除都会走到这里:输入框空了就同步解除过滤,
|
||||
// 避免"框已空但表格仍按旧关键字过滤"的幽灵状态
|
||||
if (v === '' && searchKeyword) {
|
||||
setSearchKeyword('');
|
||||
<div className='console-content'>
|
||||
<ConsoleSearchBar
|
||||
formProps={{
|
||||
layout: 'vertical',
|
||||
onFinish: handleSearch,
|
||||
className: 'console-module-filter-form',
|
||||
}}
|
||||
>
|
||||
<div className='console-module-filter-grid'>
|
||||
<ConsoleFilterField label={t('企业名称')}>
|
||||
<Input
|
||||
prefix={<Search size={16} />}
|
||||
value={keyword}
|
||||
onChange={(v) => {
|
||||
setKeyword(v);
|
||||
// 退格删空/点清除都会走到这里:输入框空了就同步解除过滤,
|
||||
// 避免"框已空但表格仍按旧关键字过滤"的幽灵状态
|
||||
if (v === '' && searchKeyword) {
|
||||
setSearchKeyword('');
|
||||
setPage(1);
|
||||
}
|
||||
}}
|
||||
placeholder={t('搜索企业名称、代码、联系人、商务...')}
|
||||
showClear
|
||||
onEnterPress={() => {
|
||||
setPage(1);
|
||||
}
|
||||
}}
|
||||
placeholder={t('搜索企业名称、代码、联系人、商务...')}
|
||||
showClear
|
||||
style={{ width: 260 }}
|
||||
onEnterPress={() => {
|
||||
setPage(1);
|
||||
setSearchKeyword(keyword);
|
||||
}}
|
||||
/>
|
||||
<Input
|
||||
value={userIdInput}
|
||||
onChange={(v) => {
|
||||
// 只留数字并剥前导零:杜绝 "0"/"007" 这类后端会静默忽略的值,
|
||||
// 否则 UI 显示筛选生效、实际返回全量列表(幽灵筛选态)
|
||||
const digits = (v || '').replace(/\D/g, '').replace(/^0+/, '');
|
||||
setUserIdInput(digits);
|
||||
// 与关键字框同款:删空/点清除即解除过滤
|
||||
if (digits === '' && userIdFilter) {
|
||||
setUserIdFilter('');
|
||||
setSearchKeyword(keyword);
|
||||
}}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('用户ID')}>
|
||||
<Input
|
||||
value={userIdInput}
|
||||
onChange={(v) => {
|
||||
// 只留数字并剥前导零:杜绝 "0"/"007" 这类后端会静默忽略的值,
|
||||
// 否则 UI 显示筛选生效、实际返回全量列表(幽灵筛选态)
|
||||
const digits = (v || '').replace(/\D/g, '').replace(/^0+/, '');
|
||||
setUserIdInput(digits);
|
||||
// 与关键字框同款:删空/点清除即解除过滤
|
||||
if (digits === '' && userIdFilter) {
|
||||
setUserIdFilter('');
|
||||
setPage(1);
|
||||
}
|
||||
}}
|
||||
placeholder={t('用户ID(owner或成员)')}
|
||||
showClear
|
||||
// 10 位封顶:真实用户ID 不会更长,且远离后端 Atoi 溢出边界(19 位)
|
||||
maxLength={10}
|
||||
aria-label={t('按用户ID筛选')}
|
||||
onEnterPress={() => {
|
||||
setPage(1);
|
||||
}
|
||||
}}
|
||||
placeholder={t('用户ID(owner或成员)')}
|
||||
showClear
|
||||
// 10 位封顶:真实用户ID 不会更长,且远离后端 Atoi 溢出边界(19 位)
|
||||
maxLength={10}
|
||||
style={{ width: 170 }}
|
||||
aria-label={t('按用户ID筛选')}
|
||||
onEnterPress={() => {
|
||||
setPage(1);
|
||||
setUserIdFilter(userIdInput);
|
||||
}}
|
||||
/>
|
||||
<Select
|
||||
value={statusFilter}
|
||||
onChange={applyFilter(setStatusFilter)}
|
||||
optionList={[
|
||||
{ value: 1, label: t('正常') },
|
||||
{ value: 2, label: t('冻结') },
|
||||
{ value: 3, label: t('欠费') },
|
||||
{ value: 4, label: t('待激活') },
|
||||
]}
|
||||
placeholder={t('全部状态')}
|
||||
showClear
|
||||
style={{ width: 120 }}
|
||||
aria-label={t('按状态筛选')}
|
||||
/>
|
||||
<Select
|
||||
value={levelFilter}
|
||||
onChange={applyFilter(setLevelFilter)}
|
||||
optionList={levelOptions}
|
||||
placeholder={t('全部等级')}
|
||||
showClear
|
||||
filter
|
||||
style={{ width: 130 }}
|
||||
aria-label={t('按企业等级筛选')}
|
||||
/>
|
||||
<Select
|
||||
value={salesRepFilter}
|
||||
onChange={applyFilter(setSalesRepFilter)}
|
||||
optionList={[
|
||||
{ value: '__none__', label: t('未分配') },
|
||||
...salesRepOptions,
|
||||
]}
|
||||
placeholder={t('全部商务')}
|
||||
showClear
|
||||
filter
|
||||
style={{ width: 130 }}
|
||||
aria-label={t('按商务人员筛选')}
|
||||
/>
|
||||
{hasActiveFilters && (
|
||||
<Button theme='borderless' type='tertiary' onClick={resetFilters}>
|
||||
{t('重置')}
|
||||
</Button>
|
||||
)}
|
||||
setUserIdFilter(userIdInput);
|
||||
}}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('状态')}>
|
||||
<Select
|
||||
value={statusFilter}
|
||||
onChange={applyFilter(setStatusFilter)}
|
||||
optionList={[
|
||||
{ value: 1, label: t('正常') },
|
||||
{ value: 2, label: t('冻结') },
|
||||
{ value: 3, label: t('欠费') },
|
||||
{ value: 4, label: t('待激活') },
|
||||
]}
|
||||
placeholder={t('全部状态')}
|
||||
showClear
|
||||
aria-label={t('按状态筛选')}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('企业等级')}>
|
||||
<Select
|
||||
value={levelFilter}
|
||||
onChange={applyFilter(setLevelFilter)}
|
||||
optionList={levelOptions}
|
||||
placeholder={t('全部等级')}
|
||||
showClear
|
||||
filter
|
||||
aria-label={t('按企业等级筛选')}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
<ConsoleFilterField label={t('商务人员')}>
|
||||
<Select
|
||||
value={salesRepFilter}
|
||||
onChange={applyFilter(setSalesRepFilter)}
|
||||
optionList={[
|
||||
{ value: '__none__', label: t('未分配') },
|
||||
...salesRepOptions,
|
||||
]}
|
||||
placeholder={t('全部商务')}
|
||||
showClear
|
||||
filter
|
||||
aria-label={t('按商务人员筛选')}
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
</div>
|
||||
<ConsoleFilterActions
|
||||
onReset={resetFilters}
|
||||
onSearch={handleSearch}
|
||||
loading={loading}
|
||||
/>
|
||||
{isAdmin() && (
|
||||
<div className='flex gap-2'>
|
||||
<ConsolePageActions>
|
||||
{CLOUD_BRAIN_UI_ENABLED && (
|
||||
<Button icon={<BarChart3 size={16} />} onClick={openEffectUsage}>
|
||||
{t('企业使用统计')}
|
||||
@@ -1028,6 +1026,7 @@ const AdminOrganizations = () => {
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
className='console-create-action'
|
||||
type='primary'
|
||||
icon={<Plus size={16} />}
|
||||
onClick={() => {
|
||||
@@ -1037,28 +1036,36 @@ const AdminOrganizations = () => {
|
||||
>
|
||||
{t('创建企业')}
|
||||
</Button>
|
||||
</div>
|
||||
</ConsolePageActions>
|
||||
)}
|
||||
</div>
|
||||
</ConsoleSearchBar>
|
||||
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={orgs}
|
||||
loading={loading}
|
||||
rowKey='id'
|
||||
// 11 列且「操作」是最后一列(编辑/调额/功能开关/冻结/删除)。
|
||||
// 不给 scroll 时表格会压缩到 min-content(~790px) 硬塞进 390px 视口,
|
||||
// 操作列落在视口右侧 ~500px 处,iOS 上滚动条不可见、毫无可拖动提示。
|
||||
scroll={{ x: 'max-content' }}
|
||||
style={{ width: '100%' }}
|
||||
onChange={handleTableChange}
|
||||
pagination={{
|
||||
currentPage: page,
|
||||
pageSize: 20,
|
||||
total,
|
||||
onPageChange: setPage,
|
||||
}}
|
||||
/>
|
||||
<ConsoleCard>
|
||||
<TableToolbar title={t('企业列表')} />
|
||||
<Table
|
||||
empty={<TableEmpty />}
|
||||
columns={columns}
|
||||
dataSource={orgs}
|
||||
loading={loading}
|
||||
rowKey='id'
|
||||
// 11 列且「操作」是最后一列(编辑/调额/功能开关/冻结/删除)。
|
||||
// 不给 scroll 时表格会压缩到 min-content(~790px) 硬塞进 390px 视口,
|
||||
// 操作列落在视口右侧 ~500px 处,iOS 上滚动条不可见、毫无可拖动提示。
|
||||
scroll={{ x: 'max-content' }}
|
||||
style={{ width: '100%' }}
|
||||
onChange={handleTableChange}
|
||||
pagination={{
|
||||
currentPage: page,
|
||||
pageSize,
|
||||
total,
|
||||
onPageChange: setPage,
|
||||
onPageSizeChange: (size) => {
|
||||
setPage(1);
|
||||
setPageSize(size);
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</ConsoleCard>
|
||||
|
||||
{CLOUD_BRAIN_UI_ENABLED && (
|
||||
<Modal
|
||||
|
||||
Reference in New Issue
Block a user