|
|
@ -1,17 +1,46 @@ |
|
|
|
<template> |
|
|
|
<a-cascader :load-data="loadData" :options="options" change-on-select> |
|
|
|
<a-cascader :load-data="loadData" :options="options"> |
|
|
|
<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 } from 'vue'; |
|
|
|
import { defineComponent, ref, toRefs } from 'vue'; |
|
|
|
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(); |
|
|
|
export default defineComponent({ |
|
|
|
name: 'NsCascader', |
|
|
|
props: { |
|
|
|
api: [Function, String, Object], |
|
|
|
options: Array, |
|
|
|
listField: { |
|
|
|
type: String, |
|
|
|
default: 'data', |
|
|
|
}, |
|
|
|
defaultParams: Object, |
|
|
|
}, |
|
|
|
setup(props, { attrs }) { |
|
|
|
let options = ref<any[]>(attrs['options'] || []); |
|
|
|
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); |
|
|
|
}); |
|
|
|
} |
|
|
|
let loadData: CascaderProps['loadData'] | null = (selectOptions) => { |
|
|
|
attrs['loadData'](selectOptions, options, attrs); |
|
|
|
}; |
|
|
|