多租户与景区关系
This commit is contained in:
@@ -10,6 +10,7 @@ const HomeCarouselPage: React.FC = () => {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<HomeCarouselItem | undefined>(undefined);
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
|
||||
const columns: any[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
@@ -40,14 +41,20 @@ const HomeCarouselPage: React.FC = () => {
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '首页轮播' }}>
|
||||
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 切换后后端生效 */ }} />
|
||||
<SearchBarPlus
|
||||
defaultCollapsed
|
||||
split
|
||||
span={8}
|
||||
onTenantChanged={() => { /* 仅触发表格刷新 */ }}
|
||||
onFinish={async (values) => setParams(values)}
|
||||
/>
|
||||
|
||||
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
|
||||
|
||||
<GlassCard>
|
||||
<ProTable<HomeCarouselItem>
|
||||
rowKey="id"
|
||||
request={(p) => ordersApi.homeCarouselList(p as any)}
|
||||
request={(p) => ordersApi.homeCarouselList({ ...(p as any), ...params })}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Col, Row, Statistic, message, Button } from 'antd';
|
||||
import TenantScopeFilter from '@/components/TenantScopeFilter';
|
||||
@@ -8,22 +8,23 @@ import { ActionBar } from '@/components/ui';
|
||||
const ProfitSharingStatisticsPage: React.FC = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [stat, setStat] = useState<any>({});
|
||||
const [scope, setScope] = useState<{ tenantId?: string; includeChildren?: boolean }>({});
|
||||
|
||||
const load = async () => {
|
||||
const load = async (p?: any) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await ordersApi.getProfitSharingStatistics();
|
||||
const res = await ordersApi.getProfitSharingStatistics(p);
|
||||
setStat(res?.data || res);
|
||||
} catch (e) {
|
||||
message.error('加载统计失败');
|
||||
} finally { setLoading(false); }
|
||||
};
|
||||
|
||||
useEffect(() => { load(); }, []);
|
||||
useEffect(() => { load(scope); }, [scope]);
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '分账统计' }} extra={<TenantScopeFilter onChanged={() => load()} /> }>
|
||||
<ActionBar right={<Button size="middle" onClick={() => load()}>刷新</Button>} />
|
||||
<PageContainer header={{ title: '分账统计' }} extra={<TenantScopeFilter useSwitchTenant onChanged={(tid, inc) => setScope({ tenantId: tid, includeChildren: inc })} /> }>
|
||||
<ActionBar right={<Button size="middle" onClick={() => load(scope)}>刷新</Button>} />
|
||||
<Row gutter={16}>
|
||||
<Col span={6}><Card loading={loading}><Statistic title="总分账额" value={stat?.totalSharingAmount || 0} precision={2} /></Card></Col>
|
||||
<Col span={6}><Card loading={loading}><Statistic title="分账笔数" value={stat?.sharingCount || 0} /></Card></Col>
|
||||
|
||||
@@ -10,6 +10,7 @@ const QrcodePage: React.FC = () => {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<QrcodeItem | undefined>(undefined);
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
|
||||
const columns: any[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
@@ -40,12 +41,18 @@ const QrcodePage: React.FC = () => {
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '二维码管理' }}>
|
||||
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 租户切换 */ }} />
|
||||
<SearchBarPlus
|
||||
defaultCollapsed
|
||||
split
|
||||
span={8}
|
||||
onTenantChanged={() => { /* 仅触发表格刷新 */ }}
|
||||
onFinish={async (values) => setParams(values)}
|
||||
/>
|
||||
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
|
||||
<GlassCard>
|
||||
<ProTable<QrcodeItem>
|
||||
rowKey="id"
|
||||
request={(p) => ordersApi.qrcodeList(p as any)}
|
||||
request={(p) => ordersApi.qrcodeList({ ...(p as any), ...params })}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
|
||||
@@ -31,8 +31,15 @@ const StatisticsPage: React.FC = () => {
|
||||
span={8}
|
||||
onTenantChanged={() => load(range)}
|
||||
onFinish={async (values) => {
|
||||
const v = values?.timeRange;
|
||||
const r = v && v.length === 2 ? { startTime: v[0]?.toISOString(), endTime: v[1]?.toISOString() } : undefined;
|
||||
const v = (values as any)?.timeRange;
|
||||
const base: any = {};
|
||||
if (v && v.length === 2) {
|
||||
base.startTime = v[0]?.toISOString();
|
||||
base.endTime = v[1]?.toISOString();
|
||||
}
|
||||
// 合并租户筛选参数
|
||||
const r = { ...values, ...base } as any;
|
||||
delete r.timeRange;
|
||||
setRange(r);
|
||||
await load(r);
|
||||
}}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import React from 'react';
|
||||
import React from 'react';
|
||||
import { ModalForm, ProForm, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
|
||||
import TenantSelector from '@/components/ui/TenantSelector';
|
||||
|
||||
export interface TourismItem {
|
||||
id?: number;
|
||||
tenantId?: string;
|
||||
tourismName?: string;
|
||||
address?: string;
|
||||
contactPerson?: string;
|
||||
contactPhone?: string;
|
||||
status?: number;
|
||||
tourismAddress?: string;
|
||||
tourismPhone?: string;
|
||||
status?: number; // 1 启用,0 禁用
|
||||
longitude?: string;
|
||||
latitude?: string;
|
||||
showInHomepage?: number; // 1 是,0 否
|
||||
description?: string;
|
||||
}
|
||||
|
||||
@@ -29,14 +33,41 @@ const TourismForm: React.FC<TourismFormProps> = ({ open, title, initialValues, o
|
||||
initialValues={initialValues}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
>
|
||||
{/* 所属租户(必选) */}
|
||||
<TenantSelector nameTenant="tenantId" labelTenant="所属租户" hideIncludeChildren rulesTenant={[{ required: true, message: '请选择租户' }]} />
|
||||
|
||||
<ProFormText name="tourismName" label="景区名称" rules={[{ required: true, message: '请输入景区名称' }]} />
|
||||
<ProFormText name="address" label="地址" />
|
||||
<ProFormText name="contactPerson" label="联系人" />
|
||||
<ProFormText name="contactPhone" label="联系电话" />
|
||||
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} />
|
||||
<ProFormText name="tourismAddress" label="地址" />
|
||||
<ProFormText name="tourismPhone" label="联系电话" />
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormText name="longitude" label="经度" placeholder="例如 116.397128" />
|
||||
<ProFormText name="latitude" label="纬度" placeholder="例如 39.916527" />
|
||||
</ProForm.Group>
|
||||
|
||||
{/* 下拉中文,不显示数字 */}
|
||||
<ProFormSelect
|
||||
name="showInHomepage"
|
||||
label="首页展示"
|
||||
options={[
|
||||
{ label: '是', value: 1 },
|
||||
{ label: '否', value: 0 },
|
||||
]}
|
||||
initialValue={0}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
options={[
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
]}
|
||||
initialValue={1}
|
||||
/>
|
||||
<ProFormTextArea name="description" label="描述" />
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default TourismForm;
|
||||
|
||||
|
||||
@@ -1,56 +1,113 @@
|
||||
import React, { useState } from 'react';
|
||||
import { PageContainer, ProTable } from '@ant-design/pro-components';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { PageContainer, ProFormText, ProTable } from '@ant-design/pro-components';
|
||||
import { Popconfirm, Space, Tag, message } from 'antd';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import TourismForm, { TourismItem } from './components/TourismForm';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
|
||||
const TourismPage: React.FC = () => {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<TourismItem | undefined>(undefined);
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
|
||||
// 首次进入时,默认按“当前租户 + 包含下级租户”查询,避免全量数据
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
let tenantId: string | undefined;
|
||||
const cur: any = await tenantApi.getCurrentTenant();
|
||||
tenantId = cur?.data?.tenantId ?? cur?.tenantId;
|
||||
if (!tenantId) {
|
||||
const stats: any = await tenantApi.getScopeStats();
|
||||
tenantId = stats?.data?.currentTenantId ?? stats?.currentTenantId;
|
||||
}
|
||||
if (tenantId) setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren: true }));
|
||||
} catch {
|
||||
// 忽略错误,保留手动查询能力
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const columns: any[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
{ title: '旅游项目', dataIndex: 'tourismName' },
|
||||
{ title: '地址', dataIndex: 'address' },
|
||||
{ title: '联系人', dataIndex: 'contactPerson' },
|
||||
{ title: '联系电话', dataIndex: 'contactPhone' },
|
||||
{ title: '状态', dataIndex: 'status', render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag> },
|
||||
{ title: '地址', dataIndex: 'tourismAddress' },
|
||||
{ title: '经度', dataIndex: 'longitude' },
|
||||
{ title: '纬度', dataIndex: 'latitude' },
|
||||
{
|
||||
title: '操作', key: 'action',
|
||||
title: '首页展示',
|
||||
dataIndex: 'showInHomepage',
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '是' : '否'}</Tag>,
|
||||
},
|
||||
{ title: '联系电话', dataIndex: 'tourismPhone' },
|
||||
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime' },
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_: any, record: TourismItem) => (
|
||||
<Space>
|
||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
||||
<Popconfirm title={`确认删除项目[${record.tourismName}]?`} onConfirm={async () => {
|
||||
const hide = message.loading('删除中...');
|
||||
try {
|
||||
await ordersApi.deleteTourism(record.id!);
|
||||
message.success('删除成功');
|
||||
} catch (e) {
|
||||
message.error('删除失败');
|
||||
} finally { hide(); }
|
||||
}}>
|
||||
<Popconfirm
|
||||
title={`确认删除项目[${record.tourismName}]?`}
|
||||
onConfirm={async () => {
|
||||
const hide = message.loading('正在删除...');
|
||||
try {
|
||||
await ordersApi.deleteTourism(record.id!);
|
||||
message.success('删除成功');
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
} finally { hide(); }
|
||||
}}
|
||||
>
|
||||
<a style={{ color: '#1677ff' }}>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '旅游项目' }}>
|
||||
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 租户切换 */ }} />
|
||||
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
|
||||
<SearchBarPlus
|
||||
defaultCollapsed
|
||||
split
|
||||
span={8}
|
||||
onTenantChanged={(tenantId, includeChildren) => {
|
||||
setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren }));
|
||||
}}
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="tourismName" label="景区名称" placeholder="请输入景区名称" />
|
||||
</SearchBarPlus>
|
||||
|
||||
<ActionBar
|
||||
left={
|
||||
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>
|
||||
新增
|
||||
</GradientButton>
|
||||
}
|
||||
/>
|
||||
|
||||
<GlassCard>
|
||||
<ProTable<TourismItem>
|
||||
rowKey="id"
|
||||
request={(p) => ordersApi.tourism(p as any)}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
/>
|
||||
{params?.tenantId ? (
|
||||
<ProTable<TourismItem>
|
||||
rowKey="id"
|
||||
params={params}
|
||||
request={(p) => ordersApi.tourism({ ...(p as any), ...params })}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
toolBarRender={false}
|
||||
/>
|
||||
) : null}
|
||||
</GlassCard>
|
||||
|
||||
<TourismForm
|
||||
@@ -63,8 +120,8 @@ const TourismPage: React.FC = () => {
|
||||
await ordersApi.saveOrUpdateTourism(values);
|
||||
message.success('新增成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('保存失败');
|
||||
} catch {
|
||||
message.error('新增失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
@@ -81,7 +138,7 @@ const TourismPage: React.FC = () => {
|
||||
await ordersApi.saveOrUpdateTourism({ ...(current as any), ...values });
|
||||
message.success('修改成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
} catch {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
|
||||
Reference in New Issue
Block a user