Merge branches 'feat/company-expire' and 'feat/platform-limit' into dev/2.0
Resolved conflicts: - typings.d.ts: Keep both validity fields and platform quota fields in CompanyListItem - company/Popup.tsx: Merge imports (Card, Col, Row from platform-limit + Dayjs from company-expire) - company/index.tsx: Keep useAccess and Typography imports needed by company-expire - rules/index.tsx: Keep validityStatus check from company-expire, adopt simplified clone button from platform-limit Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useModel } from '@umijs/max';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export default function useUserInfo() {
|
||||
const { initialState, setInitialState } = useModel('@@initialState');
|
||||
@@ -14,5 +15,24 @@ export default function useUserInfo() {
|
||||
setUserInfo(info);
|
||||
};
|
||||
|
||||
return { userInfo, refreshUserInfo, setUserInfo };
|
||||
const userPlatform = useMemo(() => {
|
||||
const company = userInfo?.company;
|
||||
const originalPlatform = [
|
||||
{
|
||||
label: 'MT5',
|
||||
value: 5,
|
||||
isOpen: company?.mt5Open === 1,
|
||||
},
|
||||
{
|
||||
label: 'MT4',
|
||||
value: 4,
|
||||
isOpen: company?.mt4Open === 1,
|
||||
},
|
||||
];
|
||||
|
||||
// return originalPlatform.filter((item) => item.isOpen);
|
||||
return originalPlatform;
|
||||
}, [userInfo]);
|
||||
|
||||
return { userInfo, refreshUserInfo, setUserInfo, userPlatform };
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ export default {
|
||||
'common.loading': 'Loading...',
|
||||
'common.content.noRules': 'No rules available',
|
||||
'common.content.noData': 'No data available',
|
||||
'table.platformAccess': 'Platform Quota',
|
||||
'table.group': 'Group',
|
||||
'table.operatorRecords': 'Operator Records',
|
||||
'table.operatorAction': 'Operator Action',
|
||||
@@ -615,6 +616,10 @@ export default {
|
||||
'Enter verified sender emails (comma separated)',
|
||||
'pages.email.status.normal': 'Active',
|
||||
'pages.email.status.disabled': 'Inactive',
|
||||
'pages.email.platformAccess': ' Platform Access',
|
||||
'pages.email.platformAccessEnable': ' Access',
|
||||
'pages.email.platformMax': 'Quota Limit',
|
||||
'pages.email.platformAssigned': 'Assigned',
|
||||
'pages.email.notification': 'Email Notification Config',
|
||||
'pages.email.notificationEmail': 'Notification Email',
|
||||
'pages.email.notificationEmail.tips':
|
||||
|
||||
@@ -2,6 +2,7 @@ export default {
|
||||
'common.loading': '加载中...',
|
||||
'common.content.noRules': '暂无规则',
|
||||
'common.content.noData': '暂无数据',
|
||||
'table.platformAccess': '平台配额',
|
||||
'table.group': '所属组',
|
||||
'table.operatorRecords': '操作记录',
|
||||
'table.operatorAction': '操作动作',
|
||||
@@ -581,6 +582,10 @@ export default {
|
||||
'pages.email.availableEmails.tips': '在服务商已验证的邮箱,多个用逗号分隔',
|
||||
'pages.email.status.normal': '正常',
|
||||
'pages.email.status.disabled': '停用',
|
||||
'pages.email.platformAccess': '平台接入权限',
|
||||
'pages.email.platformAccessEnable': '接入',
|
||||
'pages.email.platformMax': '最大数量上限',
|
||||
'pages.email.platformAssigned': '已配',
|
||||
'pages.email.notification': '邮件通知配置',
|
||||
'pages.email.notificationEmail': '通知邮箱',
|
||||
'pages.email.notificationEmail.tips':
|
||||
|
||||
@@ -21,7 +21,7 @@ const maxAlertHideCount = 9999;
|
||||
|
||||
const Account: React.FC = () => {
|
||||
const { isGlobalCompany } = useAccess();
|
||||
const { userInfo } = useUserInfo();
|
||||
const { userInfo, userPlatform } = useUserInfo();
|
||||
const companyInfo = userInfo?.company;
|
||||
|
||||
const [visible, setVisible] = useState(false);
|
||||
@@ -122,14 +122,7 @@ const Account: React.FC = () => {
|
||||
label: $t('table.all'),
|
||||
value: '',
|
||||
},
|
||||
// {
|
||||
// label: 'MT4',
|
||||
// value: '4',
|
||||
// },
|
||||
{
|
||||
label: 'MT5',
|
||||
value: '5',
|
||||
},
|
||||
...userPlatform,
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -64,7 +64,7 @@ const Alert: React.FC = () => {
|
||||
const [dataSourceList, setDataSourceList] = useState<
|
||||
API.DataSourceListItem[]
|
||||
>([]);
|
||||
const { userInfo } = useUserInfo();
|
||||
const { userInfo, userPlatform } = useUserInfo();
|
||||
const userDataSourceList = userInfo?.userDataSourceList;
|
||||
const companyInfo = userInfo?.company;
|
||||
|
||||
@@ -257,14 +257,7 @@ const Alert: React.FC = () => {
|
||||
label: $t('table.all'),
|
||||
value: '',
|
||||
},
|
||||
// {
|
||||
// label: 'MT4',
|
||||
// value: 4,
|
||||
// },
|
||||
{
|
||||
label: 'MT5',
|
||||
value: 5,
|
||||
},
|
||||
...userPlatform,
|
||||
],
|
||||
},
|
||||
render: (_, { platform }) => {
|
||||
|
||||
@@ -2,13 +2,14 @@ import {
|
||||
ModalForm,
|
||||
ProFormDatePicker,
|
||||
ProFormDependency,
|
||||
ProFormDigit,
|
||||
type ProFormInstance,
|
||||
ProFormSelect,
|
||||
ProFormSwitch,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { useAccess } from '@umijs/max';
|
||||
import { Divider, Space, Typography } from 'antd';
|
||||
import { Card, Col, Divider, Row, Space, Typography } from 'antd';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
import { useRef } from 'react';
|
||||
import useUserInfo from '@/hooks/useUserInfo';
|
||||
@@ -138,6 +139,75 @@ export default (props: {
|
||||
{formValues?.id !== void 0 && (
|
||||
<>
|
||||
<Divider size="small" />
|
||||
|
||||
<Text strong style={{ lineHeight: '40px', fontSize: 16 }}>
|
||||
⚙️ {$t('pages.email.platformAccess')}
|
||||
</Text>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Card
|
||||
title={`MT4 ${$t('pages.email.platformAccessEnable')}`}
|
||||
extra={
|
||||
<ProFormSwitch
|
||||
name="mt4Open"
|
||||
noStyle
|
||||
transform={(value) => +value}
|
||||
/>
|
||||
}
|
||||
styles={{
|
||||
header: { fontSize: 14, minHeight: 40, paddingInline: 14 },
|
||||
body: { paddingInline: 14 },
|
||||
}}
|
||||
>
|
||||
<ProFormDependency name={['mt4Open']}>
|
||||
{({ mt4Open }) => (
|
||||
<ProFormDigit
|
||||
name="mt4Count"
|
||||
label={`${$t('pages.email.platformMax')}`}
|
||||
min={0}
|
||||
step={1}
|
||||
disabled={!mt4Open}
|
||||
formItemProps={{
|
||||
style: { marginBottom: 0 },
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</ProFormDependency>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Card
|
||||
title={`MT5 ${$t('pages.email.platformAccessEnable')}`}
|
||||
extra={
|
||||
<ProFormSwitch
|
||||
name="mt5Open"
|
||||
noStyle
|
||||
transform={(value) => +value}
|
||||
/>
|
||||
}
|
||||
styles={{
|
||||
header: { fontSize: 14, minHeight: 40, paddingInline: 14 },
|
||||
body: { paddingInline: 14 },
|
||||
}}
|
||||
>
|
||||
<ProFormDependency name={['mt5Open']}>
|
||||
{({ mt5Open }) => (
|
||||
<ProFormDigit
|
||||
name="mt5Count"
|
||||
label={`${$t('pages.email.platformMax')}`}
|
||||
min={0}
|
||||
step={1}
|
||||
disabled={!mt5Open}
|
||||
formItemProps={{
|
||||
style: { marginBottom: 0 },
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</ProFormDependency>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
{/* <Divider size="small" /> */}
|
||||
<Text strong style={{ lineHeight: '40px', fontSize: 16 }}>
|
||||
📧 {$t('pages.email.notification')}
|
||||
</Text>
|
||||
|
||||
@@ -74,6 +74,46 @@ const Company: React.FC = () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: $t('table.platformAccess'),
|
||||
dataIndex: 'platformAccess',
|
||||
render: (
|
||||
_,
|
||||
{
|
||||
mt4Count,
|
||||
mt4Open,
|
||||
mt5Count,
|
||||
mt5Open,
|
||||
sourceType4Count,
|
||||
sourceType5Count,
|
||||
},
|
||||
) => {
|
||||
return (
|
||||
<Space direction="vertical" size={4}>
|
||||
<MyTag color={mt4Open === 1 ? '#818cf8' : '#94a3b8'}>
|
||||
MT4:{' '}
|
||||
{mt4Open === 1 ? (
|
||||
<span>
|
||||
{sourceType4Count ?? '-'} / {mt4Count ?? '-'}
|
||||
</span>
|
||||
) : (
|
||||
$t('pages.rules.disable')
|
||||
)}
|
||||
</MyTag>
|
||||
<MyTag color={mt5Open === 1 ? '#3b82f6' : '#94a3b8'}>
|
||||
MT5:{' '}
|
||||
{mt5Open === 1 ? (
|
||||
<span>
|
||||
{sourceType5Count ?? '-'} / {mt5Count ?? '-'}
|
||||
</span>
|
||||
) : (
|
||||
$t('pages.rules.disable')
|
||||
)}
|
||||
</MyTag>
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: $t('table.userCount'),
|
||||
dataIndex: 'userCount',
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from '@ant-design/pro-components';
|
||||
import { useAccess } from '@umijs/max';
|
||||
import { Divider, type FormInstance, Typography } from 'antd';
|
||||
import { useRef } from 'react';
|
||||
import { useMemo, useRef } from 'react';
|
||||
import useUserInfo from '@/hooks/useUserInfo';
|
||||
import { preventScientificNotation } from '@/utils';
|
||||
import { $t } from '@/utils/i18n';
|
||||
@@ -22,7 +22,7 @@ export default (props: {
|
||||
}) => {
|
||||
const { visible, formValues, onSubmit, onDone, companyList } = props;
|
||||
|
||||
const { userInfo } = useUserInfo();
|
||||
const { userInfo, userPlatform } = useUserInfo();
|
||||
const { isGlobalCompany } = useAccess();
|
||||
const globalCompanyId = isGlobalCompany ? userInfo?.companyId : 0;
|
||||
const formRef = useRef<FormInstance>(null);
|
||||
@@ -41,6 +41,12 @@ export default (props: {
|
||||
message: $t('form.placeholder.ipAddress'),
|
||||
},
|
||||
];
|
||||
|
||||
const filteredUserPlatform = useMemo(
|
||||
() => userPlatform.filter((v) => v?.isOpen),
|
||||
[userPlatform],
|
||||
);
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
width="600px"
|
||||
@@ -50,7 +56,10 @@ export default (props: {
|
||||
formValues?.id
|
||||
? formValues
|
||||
: {
|
||||
sourceType: 5,
|
||||
sourceType:
|
||||
filteredUserPlatform.length > 0
|
||||
? filteredUserPlatform[0].value
|
||||
: null,
|
||||
}
|
||||
}
|
||||
open={visible}
|
||||
@@ -78,16 +87,7 @@ export default (props: {
|
||||
label={$t('form.dataSource.type')}
|
||||
allowClear={false}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
options={[
|
||||
// {
|
||||
// value: 4,
|
||||
// label: 'MT4',
|
||||
// },
|
||||
{
|
||||
value: 5,
|
||||
label: 'MT5',
|
||||
},
|
||||
]}
|
||||
options={filteredUserPlatform}
|
||||
/>
|
||||
|
||||
{isGlobalCompany && (
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
dataSourceHandle,
|
||||
getCompanyList,
|
||||
getDataSourcePages,
|
||||
getPlatformList,
|
||||
} from '@/services/api';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import Popup from './Popup';
|
||||
@@ -49,6 +50,7 @@ const DataSource: React.FC = () => {
|
||||
setCompanyList(data || []);
|
||||
});
|
||||
}
|
||||
getPlatformList();
|
||||
}, []);
|
||||
const [cardInfo, setCardInfo] = useState({
|
||||
// mt4Count: 0,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
useBreakpoint,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Divider, Flex, Input, Modal, Space, Typography } from 'antd';
|
||||
import { createContext, useMemo, useRef, useState } from 'react';
|
||||
import { useMemo, useRef, useState } from 'react';
|
||||
import useRichFormat from '@/hooks/useRichI18n';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import '../style.less';
|
||||
@@ -14,26 +14,9 @@ import { handleEmptyValuesFunc } from '../../utils';
|
||||
import BatchCloneModal from './comp/BatchCloneModal';
|
||||
import Step1 from './comp/Step1';
|
||||
import Step2 from './comp/Step2';
|
||||
import { MultiCopyPopupContext } from './context';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
type MultiCopyPopupContextValue = {
|
||||
ruleMeta: Record<string, any>;
|
||||
dataSourceList: API.DataSourceListItem[];
|
||||
currentRuleType: number;
|
||||
targetDataSourceId: string | number | null;
|
||||
selectRules: API.RuleListItem[];
|
||||
setSelectRules: (rules: API.RuleListItem[]) => void;
|
||||
currentSchemaMap: Record<string, any>;
|
||||
};
|
||||
export const MultiCopyPopupContext = createContext<MultiCopyPopupContextValue>({
|
||||
ruleMeta: {},
|
||||
dataSourceList: [],
|
||||
currentRuleType: 0,
|
||||
targetDataSourceId: null,
|
||||
selectRules: [],
|
||||
setSelectRules: () => {},
|
||||
currentSchemaMap: {},
|
||||
});
|
||||
type MultiCopyPopupProps = {
|
||||
visible: boolean;
|
||||
ruleMeta: Record<string, any>;
|
||||
@@ -232,22 +215,22 @@ const MultiCopyPopup = ({
|
||||
onValuesChange={({ sourceDataSourceId }) => {
|
||||
if (sourceDataSourceId) {
|
||||
const curFormRef = formMapRef?.current?.[0]?.current;
|
||||
const curTargetDataSourceId =
|
||||
curFormRef?.getFieldValue('targetDataSourceId');
|
||||
if (curTargetDataSourceId === sourceDataSourceId) {
|
||||
let targetDataSourceId: string | number | null = null;
|
||||
for (const item of dataSourceList) {
|
||||
if (item.id !== sourceDataSourceId) {
|
||||
targetDataSourceId = item.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetDataSourceId) {
|
||||
curFormRef?.setFieldsValue({
|
||||
targetDataSourceId,
|
||||
});
|
||||
setTargetDataSourceId(targetDataSourceId);
|
||||
}
|
||||
const curTargetId = curFormRef?.getFieldValue('targetDataSourceId');
|
||||
const sourceItem = dataSourceList.find(
|
||||
(item) => item.id === sourceDataSourceId,
|
||||
);
|
||||
const targetItem = dataSourceList.find(
|
||||
(item) => item.id === curTargetId,
|
||||
);
|
||||
if (targetItem && sourceItem && targetItem.sourceType !== sourceItem.sourceType) {
|
||||
const fallback =
|
||||
dataSourceList.find(
|
||||
(item) =>
|
||||
item.id !== sourceDataSourceId &&
|
||||
item.sourceType === sourceItem.sourceType,
|
||||
)?.id || sourceDataSourceId;
|
||||
curFormRef?.setFieldsValue({ targetDataSourceId: fallback });
|
||||
setTargetDataSourceId(fallback);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
Row,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import useRichFormat from '@/hooks/useRichI18n';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import { type SchemaType, schemaMap } from '../../ruleFormSchema';
|
||||
@@ -68,49 +68,83 @@ const SingleCopyPopup = ({
|
||||
} =
|
||||
schemaMap[currentRuleType as unknown as SchemaType]?.({ richFormat }) || {};
|
||||
|
||||
const rightDataSourceList = dataSourceList.filter(
|
||||
(item) => item.id !== formValues?.dataSourceId,
|
||||
);
|
||||
const sourceSourceType = useMemo(() => {
|
||||
return dataSourceList.find((item) => item.id === formValues?.dataSourceId)
|
||||
?.sourceType;
|
||||
}, [dataSourceList, formValues?.dataSourceId]);
|
||||
|
||||
const dataSourceOptions = useMemo(() => {
|
||||
return dataSourceList.map((item) => ({
|
||||
...item,
|
||||
disabled: item.sourceType !== sourceSourceType,
|
||||
label: (
|
||||
<Flex justify="space-between" align="center">
|
||||
<span>{item.sourceName}</span>
|
||||
<Typography.Text
|
||||
type="secondary"
|
||||
style={{ fontSize: 12, marginLeft: 8 }}
|
||||
>
|
||||
MT{item.sourceType}
|
||||
</Typography.Text>
|
||||
</Flex>
|
||||
),
|
||||
}));
|
||||
}, [dataSourceList, sourceSourceType]);
|
||||
|
||||
const initialValues = transformInitialValue?.(formValues) || formValues;
|
||||
|
||||
const rightFirstDataSource = rightDataSourceList[0];
|
||||
const rightFirstDataSource =
|
||||
dataSourceOptions.find(
|
||||
(item) => item.id !== formValues?.dataSourceId && !item.disabled,
|
||||
) || dataSourceOptions[0];
|
||||
const isSameSource = rightFirstDataSource?.id === formValues?.dataSourceId;
|
||||
const copyFormValues = {
|
||||
...initialValues,
|
||||
name: initialValues?.name
|
||||
? `${initialValues.name} - ${rightFirstDataSource?.sourceName}`
|
||||
: `${Date.now()} - ${rightFirstDataSource?.sourceName}`,
|
||||
groupFilter: '',
|
||||
id: void 0,
|
||||
dataSourceId: rightFirstDataSource?.id || '',
|
||||
...(isSameSource
|
||||
? {}
|
||||
: {
|
||||
groupFilter: '',
|
||||
...(symbolFormShow ? { param2: '' } : {}),
|
||||
...(assetFormShow ? { param1: '' } : {}),
|
||||
}),
|
||||
};
|
||||
if (symbolFormShow) {
|
||||
copyFormValues.param2 = '';
|
||||
}
|
||||
if (assetFormShow) {
|
||||
copyFormValues.param1 = '';
|
||||
}
|
||||
|
||||
const formContent = ({
|
||||
dataSourceList,
|
||||
dataSourceList: options,
|
||||
formAttr,
|
||||
onDataSourceChange,
|
||||
}: {
|
||||
dataSourceList: API.DataSourceListItem[];
|
||||
dataSourceList: any[];
|
||||
formAttr: Record<string, any>;
|
||||
onDataSourceChange?: (dataSourceId: string | number) => void;
|
||||
}) => {
|
||||
return (
|
||||
<ProForm {...formAttr} submitter={false}>
|
||||
<ProForm
|
||||
{...formAttr}
|
||||
submitter={false}
|
||||
onValuesChange={(changedValues) => {
|
||||
if (changedValues.dataSourceId && onDataSourceChange) {
|
||||
onDataSourceChange(changedValues.dataSourceId);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="dataSourceId"
|
||||
label={$t('table.dataSource')}
|
||||
options={dataSourceList}
|
||||
options={options}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
label: 'label',
|
||||
value: 'id',
|
||||
},
|
||||
optionLabelProp: 'label',
|
||||
}}
|
||||
/>
|
||||
<BetaSchemaForm layoutType="Embed" columns={leftForm} />
|
||||
@@ -194,53 +228,64 @@ const SingleCopyPopup = ({
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Row>
|
||||
<Col xs={24} sm={11}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>📋 {$t('pages.rules.originalRule')}</Text>
|
||||
</div>
|
||||
{formContent({
|
||||
dataSourceList,
|
||||
formAttr: { initialValues, disabled: true },
|
||||
})}
|
||||
</Col>
|
||||
{visible && (
|
||||
<Row>
|
||||
<Col xs={24} sm={11}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>📋 {$t('pages.rules.originalRule')}</Text>
|
||||
</div>
|
||||
{formContent({
|
||||
dataSourceList: dataSourceOptions,
|
||||
formAttr: { initialValues, disabled: true },
|
||||
})}
|
||||
</Col>
|
||||
|
||||
<Col xs={0} sm={1}>
|
||||
<Flex vertical align="center" style={{ height: '100%' }}>
|
||||
<ArrowRightOutlined style={{ marginTop: 2, fontSize: 18 }} />
|
||||
<Divider type="vertical" style={{ flex: 1, marginTop: 16 }} />
|
||||
</Flex>
|
||||
</Col>
|
||||
<Col xs={0} sm={1}>
|
||||
<Flex vertical align="center" style={{ height: '100%' }}>
|
||||
<ArrowRightOutlined style={{ marginTop: 2, fontSize: 18 }} />
|
||||
<Divider type="vertical" style={{ flex: 1, marginTop: 16 }} />
|
||||
</Flex>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={0}>
|
||||
<div className="text-center" style={{ marginBottom: 16 }}>
|
||||
<ArrowDownOutlined />
|
||||
</div>
|
||||
</Col>
|
||||
<Col xs={24} sm={0}>
|
||||
<div className="text-center" style={{ marginBottom: 16 }}>
|
||||
<ArrowDownOutlined />
|
||||
</div>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>✏️ {$t('pages.rules.cloneRulePreview')}</Text>
|
||||
</div>
|
||||
<Col xs={24} sm={12}>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>✏️ {$t('pages.rules.cloneRulePreview')}</Text>
|
||||
</div>
|
||||
|
||||
{formContent({
|
||||
dataSourceList: rightDataSourceList,
|
||||
formAttr: {
|
||||
initialValues: copyFormValues,
|
||||
formRef: formRef,
|
||||
disabled: confirmLoading,
|
||||
},
|
||||
})}
|
||||
{errMsg && (
|
||||
<Alert
|
||||
message={errMsg}
|
||||
type="error"
|
||||
showIcon
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
{formContent({
|
||||
dataSourceList: dataSourceOptions,
|
||||
formAttr: {
|
||||
initialValues: copyFormValues,
|
||||
formRef: formRef,
|
||||
disabled: confirmLoading,
|
||||
},
|
||||
onDataSourceChange: (dataSourceId) => {
|
||||
const isSame = dataSourceId === formValues?.dataSourceId;
|
||||
if (!isSame) {
|
||||
const fields: Record<string, any> = { groupFilter: '' };
|
||||
if (symbolFormShow) fields.param2 = '';
|
||||
if (assetFormShow) fields.param1 = '';
|
||||
formRef.current?.setFieldsValue(fields);
|
||||
}
|
||||
},
|
||||
})}
|
||||
{errMsg && (
|
||||
<Alert
|
||||
message={errMsg}
|
||||
type="error"
|
||||
showIcon
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -17,10 +17,13 @@ import {
|
||||
Tag,
|
||||
Tooltip,
|
||||
} from 'antd';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { processSingleRule } from '@/pages/rules/utils';
|
||||
import { $t } from '@/utils/i18n';
|
||||
|
||||
type TaskStatus = 'waiting' | 'processing' | 'success' | 'warning' | 'error';
|
||||
type Task = { name: string; status: TaskStatus; errorMsg: string };
|
||||
|
||||
type BatchCloneModalProps = {
|
||||
visible: boolean;
|
||||
selectedRows: Partial<API.RuleListItem>[];
|
||||
@@ -33,26 +36,33 @@ const BatchCloneModal = ({
|
||||
onClose,
|
||||
onFinish,
|
||||
}: BatchCloneModalProps) => {
|
||||
const [tasks, setTasks] = useState<any[]>([]);
|
||||
const [tasks, setTasks] = useState<Task[]>([]);
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
const [currentRunning, setCurrentRunning] = useState(0);
|
||||
const selectedRowsRef = useRef(selectedRows);
|
||||
selectedRowsRef.current = selectedRows;
|
||||
|
||||
useEffect(() => {
|
||||
const initialTasks = selectedRows.map((row) => ({
|
||||
name: row.name,
|
||||
status: 'waiting', // waiting, processing, success, error
|
||||
errorMsg: '',
|
||||
}));
|
||||
setTasks(initialTasks);
|
||||
}, [visible, selectedRows]);
|
||||
if (visible) {
|
||||
setTasks(
|
||||
selectedRows.map((row) => ({
|
||||
name: row.name || '',
|
||||
status: 'waiting',
|
||||
errorMsg: '',
|
||||
})),
|
||||
);
|
||||
setIsRunning(false);
|
||||
setCurrentRunning(0);
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
const finishedTasks = useMemo(
|
||||
() => tasks.filter((t) => ['success', 'warning'].includes(t.status)),
|
||||
() => tasks.filter((t) => t.status === 'success' || t.status === 'warning'),
|
||||
[tasks],
|
||||
);
|
||||
|
||||
const finishedMessage = useMemo(() => {
|
||||
const hasWarning = finishedTasks.find((t) => t.status === 'warning');
|
||||
const hasWarning = finishedTasks.some((t) => t.status === 'warning');
|
||||
const type: AlertProps['type'] = hasWarning
|
||||
? 'warning'
|
||||
: finishedTasks.length === tasks.length
|
||||
@@ -69,9 +79,10 @@ const BatchCloneModal = ({
|
||||
};
|
||||
}, [finishedTasks, tasks]);
|
||||
|
||||
const startBatch = async () => {
|
||||
const startBatch = useCallback(async () => {
|
||||
const rows = selectedRowsRef.current;
|
||||
setIsRunning(true);
|
||||
for (let i = 0; i < selectedRows.length; i++) {
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
setCurrentRunning(i + 1);
|
||||
setTasks((prev) => {
|
||||
const next = [...prev];
|
||||
@@ -79,8 +90,7 @@ const BatchCloneModal = ({
|
||||
return next;
|
||||
});
|
||||
try {
|
||||
await processSingleRule({ payload: selectedRows[i] });
|
||||
|
||||
await processSingleRule({ payload: rows[i] });
|
||||
setTasks((prev) => {
|
||||
const next = [...prev];
|
||||
next[i].status = 'success';
|
||||
@@ -96,13 +106,13 @@ const BatchCloneModal = ({
|
||||
}
|
||||
}
|
||||
setIsRunning(false);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleReset = () => {
|
||||
const handleReset = useCallback(() => {
|
||||
setTasks([]);
|
||||
setIsRunning(false);
|
||||
setCurrentRunning(0);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
import { CheckCard, ProCard } from '@ant-design/pro-components';
|
||||
import { useRequest } from '@umijs/max';
|
||||
import { Col, Row, Spin } from 'antd';
|
||||
import { useContext, useState } from 'react';
|
||||
import { useContext, useEffect, useState } from 'react';
|
||||
import { getRuleList } from '@/services/api';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import { RuleCardBodyInfo } from '../../RuleCardBody';
|
||||
import { MultiCopyPopupContext } from '../MultiCopyPopup';
|
||||
import { MultiCopyPopupContext } from '../context';
|
||||
|
||||
type RuleCheckCardProps = {
|
||||
dataSourceId: string | number;
|
||||
onChange?: (id: string | number) => void;
|
||||
};
|
||||
const RuleCheckCard = ({ dataSourceId }: RuleCheckCardProps) => {
|
||||
const [ruleList, setRuleList] = useState<API.RuleListItem[]>([]);
|
||||
|
||||
const { ruleMeta, currentRuleType, setSelectRules } = useContext(
|
||||
MultiCopyPopupContext,
|
||||
);
|
||||
const [ruleList, setRuleList] = useState<API.RuleListItem[]>([]);
|
||||
|
||||
const { loading } = useRequest(
|
||||
() =>
|
||||
@@ -25,7 +23,6 @@ const RuleCheckCard = ({ dataSourceId }: RuleCheckCardProps) => {
|
||||
dataSourceId,
|
||||
}),
|
||||
{
|
||||
// manual: true,
|
||||
refreshDeps: [dataSourceId, currentRuleType],
|
||||
onSuccess: ({ data = [] }: { data: API.RuleListItem[] }) => {
|
||||
setRuleList(data);
|
||||
@@ -37,15 +34,17 @@ const RuleCheckCard = ({ dataSourceId }: RuleCheckCardProps) => {
|
||||
},
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
return () => setSelectRules([]);
|
||||
}, []);
|
||||
|
||||
if (!dataSourceId) return <div>{$t('pages.clones.step1.tips')}</div>;
|
||||
if (loading) return <Spin />;
|
||||
|
||||
// const
|
||||
|
||||
return (
|
||||
<ProCard
|
||||
title={$t('pages.clones.step1.sourceRules', {
|
||||
count: ruleList?.length,
|
||||
count: ruleList.length,
|
||||
ruleType: ruleMeta?.title || '-',
|
||||
})}
|
||||
collapsible
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ArrowDownOutlined } from '@ant-design/icons';
|
||||
import { ProFormDependency, ProFormSelect } from '@ant-design/pro-components';
|
||||
import { Divider, Tag } from 'antd';
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { Divider, Flex, Tag, Typography } from 'antd';
|
||||
import { useContext, useEffect, useMemo } from 'react';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import { MultiCopyPopupContext } from '../MultiCopyPopup';
|
||||
import { MultiCopyPopupContext } from '../context';
|
||||
import RuleCheckCard from './RuleCheckCard';
|
||||
|
||||
type Step1Props = {
|
||||
@@ -13,11 +13,52 @@ type Step1Props = {
|
||||
const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
const { dataSourceList } = useContext(MultiCopyPopupContext);
|
||||
|
||||
const buildOptions = (sourceId?: string | number) => {
|
||||
const sourceType = dataSourceList.find((item) => item.id === sourceId)
|
||||
?.sourceType;
|
||||
return dataSourceList.map((item) => ({
|
||||
...item,
|
||||
disabled: item.sourceType !== sourceType,
|
||||
label: (
|
||||
<Flex justify="space-between" align="center">
|
||||
<span>{item.sourceName}</span>
|
||||
<Typography.Text
|
||||
type="secondary"
|
||||
style={{ fontSize: 12, marginLeft: 8 }}
|
||||
>
|
||||
MT{item.sourceType}
|
||||
</Typography.Text>
|
||||
</Flex>
|
||||
),
|
||||
}));
|
||||
};
|
||||
|
||||
const sourceOptions = useMemo(
|
||||
() => dataSourceList.map((item) => ({
|
||||
...item,
|
||||
label: (
|
||||
<Flex justify="space-between" align="center">
|
||||
<span>{item.sourceName}</span>
|
||||
<Typography.Text
|
||||
type="secondary"
|
||||
style={{ fontSize: 12, marginLeft: 8 }}
|
||||
>
|
||||
MT{item.sourceType}
|
||||
</Typography.Text>
|
||||
</Flex>
|
||||
),
|
||||
})),
|
||||
[dataSourceList],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (dataSourceList?.length) {
|
||||
// waitTime(1000).then(() => {
|
||||
const sourceDataSourceId = dataSourceList[0]?.id || '';
|
||||
const targetDataSourceId = dataSourceList[1]?.id || '';
|
||||
const sourceItem = dataSourceList[0];
|
||||
const sourceDataSourceId = sourceItem?.id || '';
|
||||
const sameTypeItem = dataSourceList.find(
|
||||
(item) => item.id !== sourceDataSourceId && item.sourceType === sourceItem?.sourceType,
|
||||
);
|
||||
const targetDataSourceId = sameTypeItem?.id || sourceDataSourceId;
|
||||
const curFormRef = formMapRef?.current?.[0]?.current;
|
||||
if (curFormRef) {
|
||||
curFormRef?.setFieldsValue({
|
||||
@@ -26,7 +67,6 @@ const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
});
|
||||
setTargetDataSourceId(targetDataSourceId);
|
||||
}
|
||||
// });
|
||||
}
|
||||
}, [dataSourceList]);
|
||||
|
||||
@@ -35,14 +75,15 @@ const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
<ProFormSelect
|
||||
name="sourceDataSourceId"
|
||||
label={$t('pages.clones.step1.source')}
|
||||
options={dataSourceList}
|
||||
options={sourceOptions}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
label: 'label',
|
||||
value: 'id',
|
||||
},
|
||||
optionLabelProp: 'label',
|
||||
}}
|
||||
/>
|
||||
<ProFormDependency name={['sourceDataSourceId']}>
|
||||
@@ -61,21 +102,20 @@ const Step1 = ({ formMapRef, setTargetDataSourceId }: Step1Props) => {
|
||||
<ProFormDependency name={['sourceDataSourceId']}>
|
||||
{({ sourceDataSourceId }) => {
|
||||
if (!sourceDataSourceId) return null;
|
||||
const dataSourceOptions = dataSourceList.filter(
|
||||
(item) => item.id !== sourceDataSourceId,
|
||||
);
|
||||
const targetOptions = buildOptions(sourceDataSourceId);
|
||||
return (
|
||||
<ProFormSelect
|
||||
name="targetDataSourceId"
|
||||
label={$t('pages.clones.step1.target')}
|
||||
options={dataSourceOptions}
|
||||
options={targetOptions}
|
||||
rules={[{ required: true, message: $t('form.required') }]}
|
||||
fieldProps={{
|
||||
allowClear: false,
|
||||
fieldNames: {
|
||||
label: 'sourceName',
|
||||
label: 'label',
|
||||
value: 'id',
|
||||
},
|
||||
optionLabelProp: 'label',
|
||||
}}
|
||||
onChange={(value: string | number | null) => {
|
||||
setTargetDataSourceId(value || null);
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
import { useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { $t } from '@/utils/i18n';
|
||||
import { RuleCardBodyInfo } from '../../RuleCardBody';
|
||||
import { MultiCopyPopupContext } from '../MultiCopyPopup';
|
||||
import { MultiCopyPopupContext } from '../context';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
|
||||
21
src/pages/rules/components/CopyRule/context.ts
Normal file
21
src/pages/rules/components/CopyRule/context.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
type MultiCopyPopupContextValue = {
|
||||
ruleMeta: Record<string, any>;
|
||||
dataSourceList: API.DataSourceListItem[];
|
||||
currentRuleType: number;
|
||||
targetDataSourceId: string | number | null;
|
||||
selectRules: API.RuleListItem[];
|
||||
setSelectRules: (rules: API.RuleListItem[]) => void;
|
||||
currentSchemaMap: Record<string, any>;
|
||||
};
|
||||
|
||||
export const MultiCopyPopupContext = createContext<MultiCopyPopupContextValue>({
|
||||
ruleMeta: {},
|
||||
dataSourceList: [],
|
||||
currentRuleType: 0,
|
||||
targetDataSourceId: null,
|
||||
selectRules: [],
|
||||
setSelectRules: () => {},
|
||||
currentSchemaMap: {},
|
||||
});
|
||||
@@ -297,10 +297,6 @@ const RuleCommon: React.FC = () => {
|
||||
<Button
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() => {
|
||||
if (dataSourceList.length < 2) {
|
||||
message.warning($t('pages.rules.cloneRuleWarning'));
|
||||
return;
|
||||
}
|
||||
setFormValues(rule);
|
||||
setCopyVisible(true);
|
||||
}}
|
||||
@@ -459,10 +455,6 @@ const RuleCommon: React.FC = () => {
|
||||
<Button
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() => {
|
||||
if (dataSourceList.length < 2) {
|
||||
message.warning($t('pages.rules.cloneRuleWarning'));
|
||||
return;
|
||||
}
|
||||
setMultiCopyVisible(true);
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -614,6 +614,12 @@ export async function closeSSEWithApi(options?: ObjType) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPlatformList(options?: ObjType) {
|
||||
return request("/system/platform-list", {
|
||||
method: "GET",
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
export async function getDashboardTotal(options?: ObjType) {
|
||||
return request("/dashboard/total", {
|
||||
method: "GET",
|
||||
|
||||
7
src/services/typings.d.ts
vendored
7
src/services/typings.d.ts
vendored
@@ -116,6 +116,13 @@ declare namespace API {
|
||||
validityStartTime?: string | null;
|
||||
validityEndTime?: string | null;
|
||||
validityStatus?: number | null;
|
||||
|
||||
mt4Count: number;
|
||||
mt4Open: number;
|
||||
mt5Count: number;
|
||||
mt5Open: number;
|
||||
sourceType4Count: number;
|
||||
sourceType5Count: number;
|
||||
};
|
||||
|
||||
// "DataSource" Type
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"ignoreDeprecations": "6.0",
|
||||
"baseUrl": "./",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "node",
|
||||
|
||||
Reference in New Issue
Block a user