Commit 6b8f24675a1d375dbdac8b101f5a2f5658231346

Authored by 李婷
1 parent d05486a3

feat: formSelect兼容appId传入调取接口

1 ### 选择表单 1 ### 选择表单
2 2
  3 +### 外部传入options
3 ```tsx 4 ```tsx
4 import { request, QxFormSelect } from '@qx/common'; 5 import { request, QxFormSelect } from '@qx/common';
5 import React, { useState } from 'react'; 6 import React, { useState } from 'react';
@@ -243,4 +244,26 @@ export default () => { @@ -243,4 +244,26 @@ export default () => {
243 }; 244 };
244 ``` 245 ```
245 246
  247 +### 使用外部appId获取options
  248 +
  249 +```tsx
  250 +import { request, QxFormSelect } from '@qx/common';
  251 +import React, { useState } from 'react';
  252 +
  253 +export default () => {
  254 + const [value, setValue] = useState({});
  255 + return (
  256 + <QxFormSelect
  257 + optionId={'0lZK2gxUlpFD002WWKJ'}
  258 + value={value}
  259 + onChange={(datasource) => {
  260 + console.log(datasource, 'lllllll');
  261 + setValue(datasource);
  262 + }}
  263 + request={request}
  264 + />
  265 + );
  266 +};
  267 +```
  268 +
246 <API></API> 269 <API></API>
@@ -2,19 +2,17 @@ import { BlockOutlined } from '@ant-design/icons'; @@ -2,19 +2,17 @@ import { BlockOutlined } from '@ant-design/icons';
2 import { useSetState } from 'ahooks'; 2 import { useSetState } from 'ahooks';
3 import { Button } from 'antd'; 3 import { Button } from 'antd';
4 import cls from 'classnames'; 4 import cls from 'classnames';
5 -import React, { useCallback, useRef } from 'react'; 5 +import React, {useCallback, useEffect, useRef, useState} from 'react';
6 import { QxAppSelector } from '../qx-app-selector'; 6 import { QxAppSelector } from '../qx-app-selector';
7 import type { InputSelectProps } from '../qx-input-select'; 7 import type { InputSelectProps } from '../qx-input-select';
8 import { QxInputSelect } from '../qx-input-select'; 8 import { QxInputSelect } from '../qx-input-select';
9 9
10 import './styles.less'; 10 import './styles.less';
  11 +import {getAppFromList} from "./service";
11 12
12 const prefix = 'qx-form-select'; 13 const prefix = 'qx-form-select';
13 14
14 -/**  
15 - * 选择数据源  
16 - */  
17 -export const QxFormSelect: React.FC<FormSelectProps> = (props) => { 15 +const FormSelectMain: React.FC<FormSelectProps>= (props)=> {
18 const { 16 const {
19 className, 17 className,
20 options = [], 18 options = [],
@@ -106,6 +104,33 @@ export const QxFormSelect: React.FC<FormSelectProps> = (props) => { @@ -106,6 +104,33 @@ export const QxFormSelect: React.FC<FormSelectProps> = (props) => {
106 ) : null} 104 ) : null}
107 </div> 105 </div>
108 ); 106 );
  107 +}
  108 +
  109 +/**
  110 + * 选择数据源
  111 + */
  112 +export const QxFormSelect: React.FC<FormSelectProps> = (props) => {
  113 + const { options= [] as any , optionId } = props;
  114 + const [selectOptions, setSelectOptions] = useState([])
  115 +
  116 + useEffect(() => {
  117 + console.log(optionId,'llllloptions')
  118 + if(optionId && !options?.length) {
  119 + getAppFromList(optionId).then((res: any)=> {
  120 + if(res?.length){
  121 + setSelectOptions(res)
  122 + } else {
  123 + setSelectOptions([])
  124 + }
  125 + }).catch(()=> {
  126 + setSelectOptions([])
  127 + })
  128 + } else {
  129 + setSelectOptions(options)
  130 + }
  131 + }, []);
  132 +
  133 + return <FormSelectMain {...props} options={selectOptions}/>
109 }; 134 };
110 135
111 interface FormSelectProps extends InputSelectProps { 136 interface FormSelectProps extends InputSelectProps {
@@ -115,6 +140,7 @@ interface FormSelectProps extends InputSelectProps { @@ -115,6 +140,7 @@ interface FormSelectProps extends InputSelectProps {
115 request?: any; 140 request?: any;
116 disabled?: boolean; 141 disabled?: boolean;
117 popupOnBody?: boolean; 142 popupOnBody?: boolean;
  143 + optionId?: string; // 获取options传入表单的appId
118 } 144 }
119 interface FormSelectState { 145 interface FormSelectState {
120 visible: boolean; 146 visible: boolean;
  1 +import { request } from '@qx/common';
  2 +
  3 +/**
  4 + * 获取所选项集数据常量
  5 + */
  6 +export function getAppFromList(appId: string) {
  7 + return request.get(`/qx-apaas-lowcode/app/${appId}/option`);
  8 +}