Skip to content

Commit

Permalink
feat(type->api): resultField推断api的返回值应该包含object类型
Browse files Browse the repository at this point in the history
  • Loading branch information
electroluxcode committed Mar 28, 2024
1 parent 05030ee commit f5a0287
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Form/src/components/ApiCascader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
type: Array,
},
api: {
type: Function as PropType<(arg?: any) => Promise<Option[]>>,
type: Function as PropType<(arg?: any) => Promise<Option[]>> | PropType<(arg?: any) => Promise<Recordable<any>>>,
default: null,
},
numberToString: propTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/src/components/ApiRadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
const props = defineProps({
api: {
type: Function as PropType<(arg?: any) => Promise<OptionsItem[]>>,
type: Function as PropType<(arg?: any) => Promise<OptionsItem[]>> | PropType<(arg?: any) => Promise<Recordable<any>>>,
default: null,
},
params: {
Expand Down
9 changes: 8 additions & 1 deletion src/components/Form/src/components/ApiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
value: { type: [Array, Object, String, Number] as PropType<SelectValue> },
numberToString: propTypes.bool,
api: {
type: Function as PropType<(arg?: any) => Promise<OptionsItem[]>>,
type: Function as PropType<(arg?: any) => Promise<OptionsItem[]>> | PropType<(arg?: any) => Promise<Recordable<any>>>,
default: null,
},
// api params
Expand Down Expand Up @@ -103,20 +103,27 @@
);
async function fetch() {
const api = props.api;
if (!api || !isFunction(api) || loading.value) return;
optionsRef.value = [];
try {
loading.value = true;
const res = await api(props.params);
console.log("fetch:")
isFirstLoaded.value = true;
if (Array.isArray(res)) {
optionsRef.value = res;
emitChange();
return;
}
console.log("fetch:")
console.log("props:",props)
if (props.resultField) {
optionsRef.value = get(res, props.resultField) || [];
console.log("optionsRef.value:",optionsRef.value)
}
emitChange();
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/src/components/ApiTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
const props = defineProps({
value: { type: Array as PropType<Array<string>> },
api: {
type: Function as PropType<(arg) => Promise<TransferItem[]>>,
type: Function as PropType<(arg) => Promise<TransferItem[]>> | PropType<(arg?: any) => Promise<Recordable<any>>>,
default: null,
},
params: { type: Object },
Expand Down

0 comments on commit f5a0287

Please sign in to comment.