sync: 同步 monkey-ai@weiyuan(ddc5b9443) 的 web/ 到 ui-optimization
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, DatePicker, Select, Spin, Tag, Typography } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { Table } from '@/components/ui';
|
||||
import { RefreshCw } from '@/components/common/icons/ActionIcons';
|
||||
import OrgSideSheet from '../components/OrgSideSheet';
|
||||
import OrgStateBlock from '../components/OrgStateBlock';
|
||||
import { renderQuota } from '../../../helpers/render';
|
||||
import { timestamp2string } from '../../../helpers/utils';
|
||||
import {
|
||||
FUND_ENTRY_TYPES,
|
||||
FUND_LEDGER_PENDING,
|
||||
fundEntryLabel,
|
||||
} from './fundFormat';
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
const defaultRange = () => {
|
||||
const end = new Date();
|
||||
return [new Date(end.getTime() - 30 * 24 * 3600 * 1000), end];
|
||||
};
|
||||
|
||||
/**
|
||||
* 账户流水(F-29):所选账户、时间范围(默认近 30 日)、类型;时间倒序、每页 20 条。
|
||||
* 金额:消费类保留 6 位(与消费明细一致),资金操作类 2 位。
|
||||
*
|
||||
* @param {(accountId, params)=>Promise} fetchLedger 企业侧或部门侧的流水接口
|
||||
*/
|
||||
const FundLedgerSheet = ({ visible, account, fetchLedger, onClose }) => {
|
||||
const { t } = useTranslation();
|
||||
const [range, setRange] = useState(defaultRange);
|
||||
const [types, setTypes] = useState([]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [items, setItems] = useState([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [rangeError, setRangeError] = useState('');
|
||||
// 筛选状态随组件挂载初始化:父组件按账户 key 重新挂载本抽屉,不会沿用上一个账户的筛选/页码。
|
||||
// 请求序号:快速改筛选或翻页时只采纳最后一次请求的结果。
|
||||
const seqRef = useRef(0);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (!visible || !account?.id) return;
|
||||
const [start, end] = range || [];
|
||||
if (start && end && start > end) {
|
||||
setRangeError(t('开始时间不能晚于结束时间'));
|
||||
return;
|
||||
}
|
||||
setRangeError('');
|
||||
const seq = ++seqRef.current;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
const res = await fetchLedger(account.id, {
|
||||
start_timestamp: start ? Math.floor(start.getTime() / 1000) : undefined,
|
||||
end_timestamp: end ? Math.floor(end.getTime() / 1000) : undefined,
|
||||
type: types.length ? types.join(',') : undefined,
|
||||
p: page,
|
||||
page_size: PAGE_SIZE,
|
||||
});
|
||||
if (seq !== seqRef.current) return;
|
||||
if (res?.data?.success) {
|
||||
setItems(res.data.data?.items || []);
|
||||
setTotal(res.data.data?.total || 0);
|
||||
} else {
|
||||
setError(res?.data?.message || t('加载失败,请重试'));
|
||||
}
|
||||
} catch {
|
||||
// 保留旧数据并标识刷新失败,不把旧数据冒充为最新
|
||||
if (seq === seqRef.current) setError(t('数据刷新失败,请重试'));
|
||||
} finally {
|
||||
if (seq === seqRef.current) setLoading(false);
|
||||
}
|
||||
}, [visible, account?.id, range, types, page, fetchLedger, t]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
const isConsume = (r) =>
|
||||
r.entry_type === 'consume' || r.entry_type === 'consume_adjust';
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('时间'),
|
||||
dataIndex: 'created_at',
|
||||
width: 170,
|
||||
render: (v) => (v ? timestamp2string(v) : '—'),
|
||||
},
|
||||
{
|
||||
title: t('类型'),
|
||||
dataIndex: 'entry_type',
|
||||
width: 120,
|
||||
render: (v, r) => (
|
||||
<span className='inline-flex items-center gap-1'>
|
||||
{fundEntryLabel(t, v)}
|
||||
{r.status === FUND_LEDGER_PENDING && (
|
||||
<Tag color='gold' variant='filled'>
|
||||
{t('结算中')}
|
||||
</Tag>
|
||||
)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('金额'),
|
||||
dataIndex: 'amount',
|
||||
width: 140,
|
||||
align: 'right',
|
||||
render: (v, r) => (
|
||||
<Typography.Text
|
||||
className='tabular-nums'
|
||||
type={v < 0 ? 'danger' : 'success'}
|
||||
>
|
||||
{v > 0 ? '+' : v < 0 ? '-' : ''}
|
||||
{renderQuota(Math.abs(v), isConsume(r) ? 6 : 2)}
|
||||
</Typography.Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('对方账户'),
|
||||
dataIndex: 'counterpart_name',
|
||||
render: (v, r) => (
|
||||
<span className='block max-w-[180px] truncate' title={v}>
|
||||
{isConsume(r) ? t('系统消费') : v || '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('操作人'),
|
||||
dataIndex: 'operator_name',
|
||||
width: 120,
|
||||
render: (v, r) => {
|
||||
// 消费、结算调账等系统产生的行没有操作人
|
||||
const name =
|
||||
r.operator_kind === 'platform'
|
||||
? t('平台管理员')
|
||||
: isConsume(r) || !r.operator_user_id
|
||||
? t('系统')
|
||||
: v || `#${r.operator_user_id}`;
|
||||
return (
|
||||
<span className='block max-w-[120px] truncate' title={name}>
|
||||
{name}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('操作后余额'),
|
||||
dataIndex: 'balance_after',
|
||||
width: 130,
|
||||
align: 'right',
|
||||
render: (v) => (
|
||||
<span className='tabular-nums'>{renderQuota(v || 0, 2)}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('备注'),
|
||||
render: (_, r) => {
|
||||
const badDebt = isConsume(r) ? r.amount_due + r.amount : 0;
|
||||
if (r.entry_type === 'consume' && badDebt > 0) {
|
||||
return (
|
||||
<Typography.Text type='warning' className='text-xs'>
|
||||
{t('应扣 {{due}},未收回 {{bad}}', {
|
||||
due: renderQuota(r.amount_due, 6),
|
||||
bad: renderQuota(badDebt, 6),
|
||||
})}
|
||||
</Typography.Text>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span className='text-xs text-[var(--text-secondary)] break-all'>
|
||||
{r.ref_type === 'transfer' || isConsume(r) ? r.ref_id : ''}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const filtered = types.length > 0;
|
||||
|
||||
return (
|
||||
<OrgSideSheet
|
||||
visible={visible}
|
||||
onCancel={onClose}
|
||||
width={820}
|
||||
closeOnEsc
|
||||
title={`${t('资金流水')} · ${account?.name || ''}`}
|
||||
>
|
||||
<div className='flex flex-wrap items-center gap-2 mb-3'>
|
||||
{/* 状态仍为 Date[](请求换算不变),仅在控件边界与 dayjs 互转 */}
|
||||
<DatePicker.RangePicker
|
||||
showTime
|
||||
value={range?.length ? range.map((d) => dayjs(d)) : null}
|
||||
onChange={(v) => {
|
||||
setRange(v ? v.map((d) => d.toDate()) : []);
|
||||
setPage(1);
|
||||
}}
|
||||
style={{ maxWidth: 380 }}
|
||||
/>
|
||||
<Select
|
||||
mode='multiple'
|
||||
allowClear
|
||||
maxTagCount={2}
|
||||
placeholder={t('全部类型')}
|
||||
value={types}
|
||||
onChange={(v) => {
|
||||
setTypes(v);
|
||||
setPage(1);
|
||||
}}
|
||||
style={{ minWidth: 200 }}
|
||||
options={FUND_ENTRY_TYPES.map((k) => ({
|
||||
value: k,
|
||||
label: fundEntryLabel(t, k),
|
||||
}))}
|
||||
/>
|
||||
<Button icon={<RefreshCw size={16} />} onClick={load} loading={loading}>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
</div>
|
||||
{rangeError && (
|
||||
<Typography.Text type='danger' className='mb-2 block text-xs'>
|
||||
{rangeError}
|
||||
</Typography.Text>
|
||||
)}
|
||||
{error && (
|
||||
<div className='mb-2 flex items-center gap-2 text-xs'>
|
||||
<Typography.Text type='danger' className='text-xs'>
|
||||
{error}
|
||||
</Typography.Text>
|
||||
<Button size='small' type='link' onClick={load}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={items}
|
||||
loading={loading && items.length > 0}
|
||||
rowKey='id'
|
||||
size='middle'
|
||||
scroll={{ x: 'max-content' }}
|
||||
pagination={{
|
||||
currentPage: page,
|
||||
pageSize: PAGE_SIZE,
|
||||
showSizeChanger: false,
|
||||
total,
|
||||
onPageChange: setPage,
|
||||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||||
}}
|
||||
empty={
|
||||
loading ? (
|
||||
<div className='flex justify-center py-16'>
|
||||
<Spin size='large' description={t('正在加载资金流水')}>
|
||||
<div className='h-10 w-10' />
|
||||
</Spin>
|
||||
</div>
|
||||
) : (
|
||||
<OrgStateBlock
|
||||
title={
|
||||
filtered ? t('未找到符合条件的资金流水') : t('暂无资金流水')
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</OrgSideSheet>
|
||||
);
|
||||
};
|
||||
|
||||
export default FundLedgerSheet;
|
||||
Reference in New Issue
Block a user