|
|
@@ -14,8 +14,9 @@ import {
|
|
|
Select,
|
|
|
} from '@formily/antd';
|
|
|
import type { ISchema } from '@formily/json-schema';
|
|
|
-import { useEffect, useMemo, useRef } from 'react';
|
|
|
-import { Field, FieldDataSource, onFormInit } from '@formily/core';
|
|
|
+import { useMemo, useRef } from 'react';
|
|
|
+import type { Field, FieldDataSource } from '@formily/core';
|
|
|
+import { onFormInit } from '@formily/core';
|
|
|
import { createForm, onFieldReact, onFieldValueChange } from '@formily/core';
|
|
|
import { Card, Col, Row } from 'antd';
|
|
|
import styles from './index.less';
|
|
|
@@ -58,16 +59,6 @@ const Save = observer(() => {
|
|
|
|
|
|
const configRef = useRef([]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- service.getResourcesCurrent().then((resp) => {
|
|
|
- if (resp.status === 200) {
|
|
|
- // setConfig(resp.result);
|
|
|
- // console.log('test', resp);
|
|
|
- configRef.current = resp.result;
|
|
|
- }
|
|
|
- });
|
|
|
- }, []);
|
|
|
-
|
|
|
const useAsyncData = (services: (arg0: Field) => Promise<FieldDataSource>) => (field: Field) => {
|
|
|
field.loading = true;
|
|
|
services(field).then(
|
|
|
@@ -122,6 +113,10 @@ const Save = observer(() => {
|
|
|
// initialValues: {},
|
|
|
effects() {
|
|
|
onFormInit(async (form1) => {
|
|
|
+ const response = await service.getResourcesCurrent();
|
|
|
+ if (response.status === 200) {
|
|
|
+ configRef.current = response.result;
|
|
|
+ }
|
|
|
if (param?.id && param.id !== ':id') {
|
|
|
const resp = await service.detail(param.id);
|
|
|
const data = resp?.result || {};
|
|
|
@@ -156,7 +151,7 @@ const Save = observer(() => {
|
|
|
f.setFieldState('grid.configuration.panel1.layout2.host', (state) => {
|
|
|
state.dataSource = _host.map((item) => ({ label: item.host, value: item.host }));
|
|
|
});
|
|
|
- f.setFieldState('cluster.config.*.host', (state) => {
|
|
|
+ f.setFieldState('grid.cluster.cluster.*.layout2.host', (state) => {
|
|
|
state.dataSource = _host.map((item) => ({ label: item.host, value: item.host }));
|
|
|
});
|
|
|
});
|
|
|
@@ -173,26 +168,25 @@ const Save = observer(() => {
|
|
|
});
|
|
|
onFieldValueChange('shareCluster', (field, f5) => {
|
|
|
const value = (field as Field).value;
|
|
|
- if (f5.modified) {
|
|
|
- if (value) {
|
|
|
- // 共享配置
|
|
|
- f5.setFieldState('grid.configuration.panel1.layout2.host', (state) => {
|
|
|
- state.value = '0.0.0.0';
|
|
|
- state.disabled = true;
|
|
|
- });
|
|
|
- } else {
|
|
|
- // 独立配置
|
|
|
- f5.setFieldState('grid.cluster.cluster', (state) => {
|
|
|
- state.value = [{}];
|
|
|
- });
|
|
|
- f5.setFieldState('grid.cluster.cluster.*.layout2.host', (state) => {
|
|
|
- state.value = undefined;
|
|
|
- state.disabled = false;
|
|
|
- });
|
|
|
- }
|
|
|
+ if (value) {
|
|
|
+ // 共享配置
|
|
|
+ f5.setFieldState('grid.configuration.panel1.layout2.host', (state) => {
|
|
|
+ state.value = '0.0.0.0';
|
|
|
+ state.disabled = true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (f5.modified && !value) {
|
|
|
+ // 独立配置
|
|
|
+ f5.setFieldState('grid.cluster.cluster', (state) => {
|
|
|
+ state.value = [{}];
|
|
|
+ });
|
|
|
+ f5.setFieldState('grid.cluster.cluster.*.layout2.host', (state) => {
|
|
|
+ state.value = undefined;
|
|
|
+ state.disabled = false;
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
- onFieldValueChange('grid.cluster.cluster.*.layout2.serverId', async (field, f3) => {
|
|
|
+ onFieldReact('grid.cluster.cluster.*.layout2.serverId', async (field, f3) => {
|
|
|
const value = (field as Field).value;
|
|
|
const type = (field.query('type').take() as Field).value;
|
|
|
const response = await getResourceById(value, type);
|
|
|
@@ -200,7 +194,7 @@ const Save = observer(() => {
|
|
|
state.dataSource = response.map((item) => ({ label: item.host, value: item.host }));
|
|
|
});
|
|
|
});
|
|
|
- onFieldValueChange('grid.cluster.cluster.*.layout2.host', async (field, f4) => {
|
|
|
+ onFieldReact('grid.cluster.cluster.*.layout2.host', async (field, f4) => {
|
|
|
const host = (field as Field).value;
|
|
|
const value = (field.query('.serverId').take() as Field)?.value;
|
|
|
const type = (field.query('type').take() as Field)?.value;
|
|
|
@@ -215,24 +209,6 @@ const Save = observer(() => {
|
|
|
[],
|
|
|
);
|
|
|
|
|
|
- // useEffect(() => {
|
|
|
- // console.log(Store.get('current-network-data'));
|
|
|
- // // const subscription = Store.subscribe('current-network-data', (data) => {
|
|
|
- // // if (!data) return;
|
|
|
- // // // form.readPretty = true;
|
|
|
- // // const _data = _.cloneDeep(data);
|
|
|
- // // // 处理一下集群模式数据
|
|
|
- // // if (!_data.shareCluster) {
|
|
|
- // // _data.cluster = _data.cluster?.map((item: any) => ({ ...item.configuration }));
|
|
|
- // // }
|
|
|
- // // form.setValues({ ..._data });
|
|
|
- // // });
|
|
|
- // // return () => {
|
|
|
- // // subscription.unsubscribe();
|
|
|
- // // // Store.set('current-network-data', undefined);
|
|
|
- // // };
|
|
|
- // }, []);
|
|
|
-
|
|
|
const SchemaField = createSchemaField({
|
|
|
components: {
|
|
|
FormItem,
|
|
|
@@ -299,8 +275,6 @@ const Save = observer(() => {
|
|
|
'x-component-props': {
|
|
|
placeholder: '请选择本地地址',
|
|
|
},
|
|
|
- default: '0.0.0.0',
|
|
|
- 'x-disabled': true,
|
|
|
'x-decorator-props': {
|
|
|
gridSpan: 1,
|
|
|
labelAlign: 'left',
|