diff --git a/src/components/r-form/utils/index.tsx b/src/components/r-form/utils/index.tsx index 868bbd2..971be25 100644 --- a/src/components/r-form/utils/index.tsx +++ b/src/components/r-form/utils/index.tsx @@ -8,13 +8,13 @@ import { has, get } from 'lodash' import { mapTree } from '@/utils/tree.ts' -const getValueType = (column: RFormTypes.IColumn) => { +const getValueType = (column: ProColumns) => { return column.valueType } //根据type返回对应的组件 -const getComponent = (column: RFormTypes.IColumn) => { +const getComponent = (column: ProColumns) => { const type = getValueType(column) as any switch (type) { case 'input': @@ -40,7 +40,7 @@ const getComponent = (column: RFormTypes.IColumn) => { } -export const transformAntdTableProColumns = (columns: RFormTypes.IColumn[], overwriteColumns?: ProColumns[]) => { +export const transformAntdTableProColumns = (columns: ProColumns[], overwriteColumns?: ProColumns[]) => { const overwriteKeys = [] as string[] @@ -51,29 +51,38 @@ export const transformAntdTableProColumns = (columns: RFormTypes.IColumn[], over const overwrite = overwriteColumns?.find(i => i.dataIndex === item.dataIndex || item.name) if (overwrite) { - overwriteKeys.push(item.prop) + overwriteKeys.push(item.dataIndex) } return { ...item, - request: item.dicUrl ? async (params, props) => { - const { fieldProps: { dataFiledNames } } = props - const { value, res: resKey, label, disabled: disabledKey, children } = dataFiledNames || {} - const url = `/${item.dicUrl.replace(/^:/, '/')}` - return request[item.dicMethod || 'get'](url, params).then(res => { - const data = has(res.data, resKey) ? get(res.data, resKey) : res.data - - return mapTree(data || [], (i: any) => { - const disabled = has(i, disabledKey) ? get(i, disabledKey) : ('status' in i ? !convertToBool(i.status) : false) - return { - title: i[label || 'label'], - label: i[label || 'label'], - value: i[value || 'id'], - disabled, - data: i - } - - }, { children }) + request: item.request ? async (params) => { + const { url: _url, method, params: p, fieldNames, resultPath } = item.request as unknown as RFormTypes.IRequest + const { value, label, disabled: disabledKey, children = 'children' } = fieldNames || {} + const url = (_url.startsWith('/') || _url.startsWith('http')) ? _url : `/${_url}` + return request[method?.toLowerCase() || 'get'](url, { + ...params, + ...p, + }).then(res => { + try { + const data = resultPath && has(res.data, resultPath) ? get(res.data, resultPath) : res.data + + return mapTree(data || [], (i: any) => { + const disabled = disabledKey && has(i, disabledKey) ? get(i, disabledKey) : ('status' in i ? !convertToBool(i.status) : false) + return { + title: i.label || i[label || 'name'], + label: i.label || i[label || 'name'], + value: i.value || i[value || 'id'], + disabled, + data: i + } + + }, { children }) + + } catch (e) { + console.log(`${url}请求异常:`, e) + return [] + } }) } : undefined, // renderFormItem: (_scheam, config, dom) => { diff --git a/src/types/r-form/model.d.ts b/src/types/r-form/model.d.ts index 4cebee0..b5c1cc3 100644 --- a/src/types/r-form/model.d.ts +++ b/src/types/r-form/model.d.ts @@ -21,5 +21,19 @@ export namespace RFormTypes { } + export interface IRequest { + url: string; + method: 'GET' | 'POST' | 'PUT' | 'DELETE'; + params?: any; + resultPath?: string; + + fieldNames?: { + label: string; + value: string; + children: string; + disabled: string; + } + } + }