Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
+368
View File
@@ -0,0 +1,368 @@
/*
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, useContext, useEffect, useState } from 'react';
import {
Banner,
Button,
Card,
Form,
Spin,
Typography,
} from '@douyinfe/semi-ui';
import {
AlertTriangle,
BadgePercent,
Clock,
Handshake,
ShieldCheck,
Users,
XCircle,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { API, showError, showSuccess } from '../../helpers';
import { StatusContext } from '../../context/Status';
import Workbench, { BrandTip } from './Workbench';
const { Title, Text } = Typography;
/**
* 合作伙伴(console 内嵌版):挂在个人中心侧边栏下。
* 状态机:loading → apply(未申请)/ status(pending/rejected)/ dashboard(其余状态)/ error。
* 会话过期(401)转门户页登录引导;服务端错误进 error 态可重试——
* 不能落 apply 态,否则已生效伙伴会看到"申请成为合作伙伴"表单造成误导。
*/
export default function PartnerConsole() {
const { t } = useTranslation();
const navigate = useNavigate();
// 平台总开关:关闭时(直敲 URL 进入)显示未开放提示,不发起伙伴接口请求
const [statusState] = useContext(StatusContext);
const portalClosed =
!!statusState?.status &&
statusState.status.commission_partner_portal_enabled !== true;
const [phase, setPhase] = useState('loading'); // loading | apply | status | dashboard | error
const [self, setSelf] = useState(null);
const [dashboard, setDashboard] = useState(null);
const [loadError, setLoadError] = useState('');
const loadSelf = useCallback(async () => {
setPhase('loading');
try {
const res = await API.get('/api/partner/self', {
skipErrorHandler: true,
});
if (!res.data.success) {
setLoadError(res.data.message || '');
setPhase('error');
return;
}
const data = res.data.data;
if (!data.exists) {
setPhase('apply');
return;
}
setSelf(data.partner);
if (
data.partner.status === 'pending' ||
data.partner.status === 'rejected'
) {
setPhase('status');
return;
}
const db = await API.get('/api/partner/dashboard');
if (db.data.success) setDashboard(db.data.data);
setPhase('dashboard');
} catch (e) {
// 会话失效:PrivateRoute 只认本地缓存,需在此处兜底送回登录引导
if (e?.response?.status === 401) {
navigate('/partner', { replace: true });
return;
}
setLoadError('');
setPhase('error');
}
}, [navigate]);
useEffect(() => {
// 等 status 就绪且总开关开启才发起伙伴接口:关闭时直接请求会拿到闸门 403,
// 在 status 到达前会闪一帧"加载失败"卡片
if (!statusState?.status || portalClosed) return;
loadSelf();
}, [loadSelf, statusState?.status, portalClosed]);
const apply = async (values) => {
const res = await API.post('/api/partner/apply', values);
if (res.data.success) {
showSuccess(t('申请已提交,请等待平台审核'));
loadSelf();
} else {
showError(res.data.message);
}
};
return (
// mt-[60px]:顶栏 fixed 定位需自行让位(跑马灯由 PageLayout 占位补偿)
<div className='mt-[60px] px-2 pb-6'>
<div className='flex items-center gap-3 mb-4'>
<div className='p-2.5 bg-gradient-to-br from-brand-from to-brand-to rounded-xl shadow-lg text-white flex-shrink-0'>
<Handshake size={22} />
</div>
<div>
<Title heading={4} style={{ margin: 0 }}>
{t('合作伙伴')}
</Title>
<Text type='tertiary' size='small'>
{t('直接推广分佣 · 间接推广分佣 · 客户报备')}
</Text>
</div>
</div>
{portalClosed && (
<Card className='!rounded-2xl shadow-sm' bodyStyle={{ padding: 40 }}>
<div className='flex flex-col items-center text-center gap-3 max-w-md mx-auto'>
<div className='p-3 rounded-full bg-brand/10 text-brand'>
<Clock size={32} />
</div>
<Title heading={5} style={{ margin: 0 }}>
{t('合作伙伴平台暂未开放')}
</Title>
<Text type='tertiary'>
{t('平台正在筹备中,敬请期待;如有合作意向请联系平台运营')}
</Text>
</div>
</Card>
)}
{!portalClosed && phase === 'loading' && (
<div className='flex justify-center py-24'>
<Spin size='large' />
</div>
)}
{!portalClosed && phase === 'error' && (
<Card className='!rounded-2xl shadow-sm' bodyStyle={{ padding: 40 }}>
<div className='flex flex-col items-center text-center gap-3 max-w-md mx-auto'>
<div className='p-3 rounded-full bg-orange-50 dark:bg-orange-900/20 text-orange-500'>
<AlertTriangle size={32} />
</div>
<Title heading={5} style={{ margin: 0 }}>
{t('加载失败')}
</Title>
<Text type='tertiary'>
{loadError || t('伙伴信息暂时无法获取,请稍后重试')}
</Text>
<Button
theme='solid'
type='primary'
style={{ marginTop: 8 }}
onClick={loadSelf}
>
{t('重试')}
</Button>
</div>
</Card>
)}
{!portalClosed && phase === 'apply' && (
<ApplyCard t={t} onSubmit={apply} />
)}
{!portalClosed && phase === 'status' && (
<StatusCard
t={t}
self={self}
onRefresh={loadSelf}
onReapply={() => setPhase('apply')}
/>
)}
{!portalClosed && phase === 'dashboard' && (
<>
{self?.status === 'dormant' && (
<Banner
style={{ marginBottom: 12 }}
type='warning'
closeIcon={null}
description={t(
'当前处于休眠状态:新报备已暂停;存量客户服务、账单确认与争议、收款账户维护不受影响,返佣照常计提与发放',
)}
/>
)}
{(self?.status === 'suspended' || self?.status === 'terminated') && (
<Banner
style={{ marginBottom: 12 }}
type='danger'
closeIcon={null}
description={t('当前状态仅可查看历史数据,如有疑问请联系平台')}
/>
)}
{/* 权限档位由 Workbench 内部按 status 派生(dormant 半读写 / suspended・terminated 只读) */}
<Workbench self={self} dashboard={dashboard} />
</>
)}
</div>
);
}
/** 权益点:申请页顶部三栏 */
function BenefitItem({ icon, title, desc }) {
return (
<div className='flex items-start gap-3 rounded-xl bg-brand/5 border border-brand/10 p-4'>
<div className='p-2 bg-gradient-to-br from-brand-from to-brand-to rounded-lg text-white flex-shrink-0'>
{icon}
</div>
<div className='min-w-0'>
<p className='text-sm font-semibold text-gray-800 dark:text-gray-100 mb-0.5'>
{title}
</p>
<p className='text-xs text-gray-500 dark:text-gray-400'>{desc}</p>
</div>
</div>
);
}
function ApplyCard({ t, onSubmit }) {
return (
<Card className='!rounded-2xl shadow-sm' bodyStyle={{ padding: 24 }}>
<Title heading={5} style={{ marginBottom: 4 }}>
{t('申请成为合作伙伴')}
</Title>
<Text type='tertiary'>
{t(
'伙伴账号与平台账号通用,提交主体资料后由平台审核;审核通过之日为合作生效日',
)}
</Text>
<div className='grid grid-cols-1 md:grid-cols-3 gap-3 mt-4 mb-5'>
<BenefitItem
icon={<ShieldCheck size={18} />}
title={t('客户报备保护')}
desc={t('报备在先、平台确认,保护期内客户归属受保障')}
/>
<BenefitItem
icon={<BadgePercent size={18} />}
title={t('两级分佣返佣')}
desc={t('直接客户毛利分佣,下级伙伴带来二层分佣')}
/>
<BenefitItem
icon={<Users size={18} />}
title={t('月度对账透明结算')}
desc={t('账单逐行可核对,支持争议登记与导出')}
/>
</div>
<div className='max-w-xl'>
<BrandTip className='mb-2'>
{t('如有推荐人请填写其伙伴编号(推荐关系一经确认不予变更)')}
</BrandTip>
<Form onSubmit={onSubmit}>
<Form.Select
field='type'
label={t('主体类型')}
initValue='company'
size='large'
style={{ width: '100%' }}
rules={[{ required: true }]}
>
<Form.Select.Option value='company'>{t('企业')}</Form.Select.Option>
<Form.Select.Option value='individual'>
{t('个人')}
</Form.Select.Option>
</Form.Select>
<Form.Input
field='name'
label={t('主体名称(个人姓名 / 企业全称)')}
size='large'
rules={[{ required: true, message: t('请输入主体名称') }]}
/>
<Form.Input
field='contact_phone'
label={t('联系电话')}
size='large'
/>
<Form.Input
field='contact_email'
label={t('联系邮箱')}
size='large'
/>
<Form.Input
field='referrer_code'
label={t('推荐人伙伴编号(选填)')}
size='large'
/>
<Button
theme='solid'
htmlType='submit'
type='primary'
size='large'
style={{ marginTop: 16, minWidth: 160 }}
>
{t('提交申请')}
</Button>
</Form>
</div>
</Card>
);
}
function StatusCard({ t, self, onRefresh, onReapply }) {
const pending = self?.status === 'pending';
return (
<Card className='!rounded-2xl shadow-sm' bodyStyle={{ padding: 40 }}>
<div className='flex flex-col items-center text-center gap-3 max-w-md mx-auto'>
{pending ? (
<div className='p-3 rounded-full bg-brand/10 text-brand'>
<Clock size={32} />
</div>
) : (
<div className='p-3 rounded-full bg-red-50 dark:bg-red-900/20 text-red-500'>
<XCircle size={32} />
</div>
)}
<Title heading={5} style={{ margin: 0 }}>
{pending ? t('申请审核中') : t('申请未通过')}
</Title>
{pending ? (
<>
{/* 严禁承诺"逾期自动通过":后端只有报备有该 SLA,伙伴申请无自动通过 job,
页面单方承诺会构成准合同依据(PR4 曾定性工作日历的法律效力) */}
<Text type='tertiary'>
{t('平台将在 1 个工作日内完成审核,请耐心等待')}
</Text>
<Button style={{ marginTop: 8 }} onClick={onRefresh}>
{t('刷新审核状态')}
</Button>
</>
) : (
<>
<Text type='tertiary'>
{t('驳回原因')}: {self?.review_note || '-'}
</Text>
<Button
theme='solid'
type='primary'
style={{ marginTop: 8 }}
onClick={onReapply}
>
{t('重新申请')}
</Button>
</>
)}
</div>
</Card>
);
}
File diff suppressed because it is too large Load Diff
+174
View File
@@ -0,0 +1,174 @@
/*
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, { useContext, useEffect, useState } from 'react';
import { Button, Spin, Typography } from '@douyinfe/semi-ui';
import { BadgePercent, Clock, ShieldCheck, Users } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { API, getLogo, savePostLoginRedirect } from '../../helpers';
import { StatusContext } from '../../context/Status';
import GlassCard from '../../components/auth/GlassCard';
import AuthCardHeader from '../../components/auth/AuthCardHeader';
import AuthBackground from '../../components/common/AuthBackground';
const { Text } = Typography;
/**
* 合作伙伴门户(对外入口)
* 仅承担未登录引导:登录统一走主站登录页并自动回跳;
* 已登录用户一律转入 /console/partner(个人中心 · 合作伙伴),申请/审核/工作台均在 console 内完成。
*/
export default function PartnerPortal() {
const { t } = useTranslation();
const [phase, setPhase] = useState('loading'); // loading | login
const navigate = useNavigate();
// 平台总开关(参数设置页可配):status 未加载时按 loading 处理,避免误判关闭
const [statusState] = useContext(StatusContext);
const portalClosed =
!!statusState?.status &&
statusState.status.commission_partner_portal_enabled !== true;
useEffect(() => {
(async () => {
try {
// skipErrorHandler:未登录访问是常态入口,不弹全局错误 toast
const res = await API.get('/api/partner/self', {
skipErrorHandler: true,
});
if (res.data.success) {
navigate('/console/partner', { replace: true });
return;
}
setPhase('login');
} catch {
setPhase('login');
}
})();
}, [navigate]);
// 登录统一走主站登录页(完整支持人机验证/第三方登录/用户上下文分发),
// 登录成功后经 consumePostLoginRedirect 自动回跳本页,再由本页转入 console
const gotoLogin = () => {
savePostLoginRedirect('/partner');
navigate('/org/login?redirect=%2Fpartner');
};
const gotoRegister = () => {
savePostLoginRedirect('/partner');
navigate('/register');
};
const logo = getLogo();
return (
<div
className='relative overflow-hidden flex items-center justify-center px-4 sm:px-6 lg:px-8'
// paddingTop 让位 fixed 顶栏;minHeight 抵扣跑马灯占位,保证占位+容器恰为一屏
style={{
minHeight: 'calc(100vh - var(--content-top-offset, 0px))',
paddingTop: 88,
paddingBottom: 48,
}}
>
<AuthBackground />
<div className='w-full max-w-md z-10 flex flex-col items-center'>
<GlassCard>
<AuthCardHeader
wrapperClassName='mb-6'
logo={logo}
title={t('合作伙伴平台')}
subtitle={
portalClosed
? t('敬请期待')
: phase === 'loading'
? t('正在加载…')
: t('欢迎加入合作伙伴计划')
}
/>
<div className='auth-glass-form'>
{portalClosed ? (
<div className='flex flex-col items-center gap-3 py-6 text-center'>
<span className='p-3 rounded-full bg-brand/10 text-brand'>
<Clock size={28} />
</span>
<Text strong>{t('合作伙伴平台暂未开放')}</Text>
<Text type='tertiary' size='small'>
{t('平台正在筹备中,敬请期待;如有合作意向请联系平台运营')}
</Text>
</div>
) : phase === 'loading' ? (
<div className='flex justify-center py-8'>
<Spin size='large' />
</div>
) : (
<div className='flex flex-col gap-4'>
<div className='flex flex-col gap-2.5'>
<FeatureRow
icon={<ShieldCheck size={16} />}
text={t('客户报备保护,保护期内归属受保障')}
/>
<FeatureRow
icon={<BadgePercent size={16} />}
text={t('两级分佣返佣,下级伙伴带来二层收益')}
/>
<FeatureRow
icon={<Users size={16} />}
text={t('月度对账透明结算,账单逐行可核对')}
/>
</div>
<Button
theme='solid'
type='primary'
size='large'
block
onClick={gotoLogin}
>
{t('登录 / 进入伙伴平台')}
</Button>
<Button
theme='borderless'
size='large'
block
className='!text-gray-500'
onClick={gotoRegister}
>
{t('还没有账号?立即注册')}
</Button>
<div className='text-center'>
<Text type='quaternary' size='small'>
{t(
'伙伴账号与平台账号通用;登录完成后将自动进入伙伴工作台',
)}
</Text>
</div>
</div>
)}
</div>
</GlassCard>
</div>
</div>
);
}
function FeatureRow({ icon, text }) {
return (
<div className='flex items-center gap-2.5 rounded-lg bg-brand/5 border border-brand/10 px-3 py-2'>
<span className='text-brand flex-shrink-0'>{icon}</span>
<span className='text-sm text-gray-600 dark:text-gray-300'>{text}</span>
</div>
);
}