|
|
@@ -18,7 +18,7 @@ import {
|
|
|
ArrayTable,
|
|
|
} from '@formily/antd';
|
|
|
import { TreeSelect as ATreeSelect } from 'antd';
|
|
|
-import { useEffect, useRef, useState } from 'react';
|
|
|
+import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
import { createSchemaField } from '@formily/react';
|
|
|
import { createForm, Field, onFieldReact, onFieldValueChange, onFormInit } from '@formily/core';
|
|
|
import { onlyMessage, randomString, testIP, useAsyncDataSource } from '@/utils/util';
|
|
|
@@ -32,6 +32,7 @@ import { getMenuPathByCode } from '@/utils/menu';
|
|
|
import MenuPage from '../Menu';
|
|
|
import _ from 'lodash';
|
|
|
import { UploadImage } from '@/components';
|
|
|
+import Doc from './doc';
|
|
|
|
|
|
const Save = () => {
|
|
|
const location = useLocation();
|
|
|
@@ -44,6 +45,8 @@ const Save = () => {
|
|
|
const [visible, setVisiable] = useState<boolean>(false);
|
|
|
const [detail, setDetail] = useState<any>({});
|
|
|
const accessRef = useRef<any>([]);
|
|
|
+ const [type, setType] = useState<any>('');
|
|
|
+ const typeRef = useRef<any>('');
|
|
|
|
|
|
const provider1 = require('/public/images/apply/provider1.png');
|
|
|
const provider2 = require('/public/images/apply/provider2.png');
|
|
|
@@ -138,16 +141,6 @@ const Save = () => {
|
|
|
},
|
|
|
});
|
|
|
|
|
|
- // const getProvidersAll = () => {
|
|
|
- // return service.getProvidersAll().then((res) => {
|
|
|
- // if (res.status === 200) {
|
|
|
- // return res.result.map((item: any) => ({
|
|
|
- // label: createImageLabel(providerType.get(item.provider), item.name),
|
|
|
- // value: item.provider,
|
|
|
- // }));
|
|
|
- // }
|
|
|
- // });
|
|
|
- // };
|
|
|
const getRole = () => service.queryRoleList();
|
|
|
const getOrg = () => service.queryOrgList();
|
|
|
|
|
|
@@ -165,103 +158,116 @@ const Save = () => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- const form = createForm({
|
|
|
- validateFirst: true,
|
|
|
- effects() {
|
|
|
- onFormInit(async (formInit) => {
|
|
|
- if (!id) return;
|
|
|
- const resp = await service.detail(id);
|
|
|
- const integrationModes = resp.result.integrationModes.map((item: any) => item.value);
|
|
|
- // setAccess(integrationModes)
|
|
|
- accessRef.current = integrationModes;
|
|
|
- formInit.setInitialValues({
|
|
|
- ...resp.result,
|
|
|
- integrationModes,
|
|
|
- 'apiServer.appId': id,
|
|
|
- });
|
|
|
- });
|
|
|
- onFieldValueChange('provider', (field, form1) => {
|
|
|
- const value = field.value;
|
|
|
- // console.log(value);
|
|
|
- if (field.modified) {
|
|
|
- switch (value) {
|
|
|
- case 'internal-standalone':
|
|
|
- form1.setFieldState('integrationModes', (f1) => {
|
|
|
- f1.value = [];
|
|
|
- f1.dataSource = integrationModesList;
|
|
|
- });
|
|
|
- break;
|
|
|
- case 'internal-integrated':
|
|
|
- form1.setFieldState('integrationModes', (f2) => {
|
|
|
- f2.value = [];
|
|
|
- f2.dataSource = integrationModesList?.filter(
|
|
|
- (item) => item.value === 'apiClient' || item.value === 'page',
|
|
|
- );
|
|
|
- });
|
|
|
- break;
|
|
|
- case 'dingtalk-ent-app':
|
|
|
- form1.setFieldState('integrationModes', (f3) => {
|
|
|
- f3.value = ['ssoClient'];
|
|
|
- f3.dataSource = integrationModesList?.filter((item) => item.value === 'ssoClient');
|
|
|
- });
|
|
|
- break;
|
|
|
- case 'wechat-webapp':
|
|
|
- form1.setFieldState('integrationModes', (f4) => {
|
|
|
- f4.value = ['ssoClient'];
|
|
|
- f4.dataSource = integrationModesList?.filter((item) => item.value === 'ssoClient');
|
|
|
+ const form = useMemo(
|
|
|
+ () =>
|
|
|
+ createForm({
|
|
|
+ validateFirst: true,
|
|
|
+ effects() {
|
|
|
+ onFormInit(async (formInit) => {
|
|
|
+ if (!id) return;
|
|
|
+ const resp = await service.detail(id);
|
|
|
+ const integrationModes = resp.result.integrationModes.map((item: any) => item.value);
|
|
|
+ // setAccess(integrationModes)
|
|
|
+ accessRef.current = integrationModes;
|
|
|
+ formInit.setInitialValues({
|
|
|
+ ...resp.result,
|
|
|
+ integrationModes,
|
|
|
+ 'apiServer.appId': id,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ onFieldValueChange('provider', (field, form1) => {
|
|
|
+ const value = field.value;
|
|
|
+ setType(value);
|
|
|
+ // console.log(value);
|
|
|
+ if (field.modified) {
|
|
|
+ switch (value) {
|
|
|
+ case 'internal-standalone':
|
|
|
+ form1.setFieldState('integrationModes', (f1) => {
|
|
|
+ f1.value = [];
|
|
|
+ f1.dataSource = integrationModesList;
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 'internal-integrated':
|
|
|
+ form1.setFieldState('integrationModes', (f2) => {
|
|
|
+ f2.value = [];
|
|
|
+ f2.dataSource = integrationModesList?.filter(
|
|
|
+ (item) => item.value === 'apiClient' || item.value === 'page',
|
|
|
+ );
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 'dingtalk-ent-app':
|
|
|
+ form1.setFieldState('integrationModes', (f3) => {
|
|
|
+ f3.value = ['ssoClient'];
|
|
|
+ f3.dataSource = integrationModesList?.filter(
|
|
|
+ (item) => item.value === 'ssoClient',
|
|
|
+ );
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 'wechat-webapp':
|
|
|
+ form1.setFieldState('integrationModes', (f4) => {
|
|
|
+ f4.value = ['ssoClient'];
|
|
|
+ f4.dataSource = integrationModesList?.filter(
|
|
|
+ (item) => item.value === 'ssoClient',
|
|
|
+ );
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 'third-party':
|
|
|
+ form1.setFieldState('integrationModes', (f5) => {
|
|
|
+ f5.value = [];
|
|
|
+ f5.dataSource = integrationModesList;
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ onFieldValueChange('integrationModes', (field, form2) => {
|
|
|
+ const value = field.value;
|
|
|
+ formCollapse.activeKeys = field.value;
|
|
|
+ const modes = ['page', 'apiClient', 'apiServer', 'ssoClient'];
|
|
|
+ const items = modes.concat(field.value).filter((item) => !value?.includes(item)); //未被选中
|
|
|
+ // console.log(value);
|
|
|
+ items.forEach((i) => {
|
|
|
+ form2.setFieldState(`config.${i}`, (state) => {
|
|
|
+ state.visible = false;
|
|
|
});
|
|
|
- break;
|
|
|
- case 'third-party':
|
|
|
- form1.setFieldState('integrationModes', (f5) => {
|
|
|
- f5.value = [];
|
|
|
- f5.dataSource = integrationModesList;
|
|
|
+ });
|
|
|
+ field.value?.forEach((parms: any) => {
|
|
|
+ form2.setFieldState(`config.${parms}`, (state) => {
|
|
|
+ state.visible = true;
|
|
|
});
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- onFieldValueChange('integrationModes', (field, form2) => {
|
|
|
- const value = field.value;
|
|
|
- formCollapse.activeKeys = field.value;
|
|
|
- const modes = ['page', 'apiClient', 'apiServer', 'ssoClient'];
|
|
|
- const items = modes.concat(field.value).filter((item) => !value?.includes(item)); //未被选中
|
|
|
- // console.log(value);
|
|
|
- items.forEach((i) => {
|
|
|
- form2.setFieldState(`config.${i}`, (state) => {
|
|
|
- state.visible = false;
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
- field.value?.forEach((parms: any) => {
|
|
|
- form2.setFieldState(`config.${parms}`, (state) => {
|
|
|
- state.visible = true;
|
|
|
+ onFieldReact('apiClient.authConfig.oauth2.clientId', (field) => {
|
|
|
+ if (id && accessRef.current?.includes('apiClient')) {
|
|
|
+ field.componentProps = {
|
|
|
+ disabled: true,
|
|
|
+ };
|
|
|
+ }
|
|
|
});
|
|
|
- });
|
|
|
- });
|
|
|
- onFieldReact('apiClient.authConfig.oauth2.clientId', (field) => {
|
|
|
- if (id && accessRef.current?.includes('apiClient')) {
|
|
|
- field.componentProps = {
|
|
|
- disabled: true,
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
- onFieldReact('apiServer.ipWhiteList', (field: any) => {
|
|
|
- const value = (field as Field).value;
|
|
|
- if (value) {
|
|
|
- const str = value?.split(/[\n,]/g).filter((i: any) => i && i.trim());
|
|
|
- const NoIP = str.find((item: any) => !testIP(item.replace(/\s*/g, '')));
|
|
|
- if (NoIP) {
|
|
|
- field.selfErrors = `[${NoIP}]不是正确的IP地址`;
|
|
|
- } else {
|
|
|
- field.selfErrors = '';
|
|
|
- }
|
|
|
- } else {
|
|
|
- field.selfErrors = '';
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- });
|
|
|
+ onFieldReact('apiServer.ipWhiteList', (field: any) => {
|
|
|
+ const value = (field as Field).value;
|
|
|
+ if (value) {
|
|
|
+ const str = value?.split(/[\n,]/g).filter((i: any) => i && i.trim());
|
|
|
+ const NoIP = str.find((item: any) => !testIP(item.replace(/\s*/g, '')));
|
|
|
+ if (NoIP) {
|
|
|
+ field.selfErrors = `[${NoIP}]不是正确的IP地址`;
|
|
|
+ } else {
|
|
|
+ field.selfErrors = '';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ field.selfErrors = '';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ [id],
|
|
|
+ );
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ console.log('_________', typeRef.current);
|
|
|
+ }, [typeRef.current]);
|
|
|
|
|
|
const handleSave = async () => {
|
|
|
const data: any = await form.submit();
|
|
|
@@ -1947,7 +1953,7 @@ const Save = () => {
|
|
|
</Form>
|
|
|
</Col>
|
|
|
<Col span={10} className={styles.apply}>
|
|
|
- <div className={styles.doc}></div>
|
|
|
+ <Doc type={type} />
|
|
|
</Col>
|
|
|
</Row>
|
|
|
</Card>
|