You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

7 months ago
<template>
<a-cascader :load-data="loadData" :options="options">
7 months ago
<template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
<slot :name="item" v-bind="data || {}"> </slot>
</template>
</a-cascader>
</template>
<script lang="ts">
import { defineComponent, ref, toRefs } from 'vue';
7 months ago
import type { CascaderProps } from 'ant-design-vue';
import { http } from '/nerv-lib/util';
import { AxiosRequestConfig } from 'axios';
import { useApi } from '/nerv-lib/use';
import { get } from 'lodash-es';
const { httpRequest } = useApi();
7 months ago
export default defineComponent({
name: 'NsCascader',
props: {
api: [Function, String, Object],
options: Array,
listField: {
type: String,
default: 'data',
},
defaultParams: Object,
},
7 months ago
setup(props, { attrs }) {
console.log(props, attrs);
const requestConfig: AxiosRequestConfig = { method: 'get' };
let options = ref<any[]>(props['options'] || []);
if (props.api) {
// eslint-disable-next-line vue/no-setup-props-destructure
const { api, defaultParams, listField } = props;
httpRequest({
api,
params: defaultParams,
pathParams: {},
requestConfig,
}).then((res) => {
options.value = get(res, listField);
});
}
7 months ago
let loadData: CascaderProps['loadData'] | null = (selectOptions) => {
attrs['loadData'](selectOptions, options, attrs);
};
if (attrs['loadData']) {
loadData(options);
} else {
loadData = null;
}
return {
loadData,
options,
};
},
});
</script>
<style lang="less" scoped></style>