ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script lang="ts" setup>
import { computed, unref } from 'vue';
 
import { useAttrs } from '@jnpf/hooks';
 
import { Cascader } from 'ant-design-vue';
 
export interface FieldNames {
  children?: string;
  label?: string;
  value?: string;
}
 
defineOptions({ inheritAttrs: false, name: 'JnpfCascader' });
const props = defineProps({
  fieldNames: {
    default: () => ({ label: 'fullName', value: 'id', children: 'children' }),
    type: Object as PropType<FieldNames>,
  },
});
const attrs = useAttrs({ excludeDefaultKeys: false });
 
const getFieldNames = computed((): Required<FieldNames> => {
  const { fieldNames } = props;
  return {
    label: 'fullName',
    value: 'id',
    children: 'children',
    ...fieldNames,
  };
});
const getBindValue = computed(() => ({ ...unref(attrs), fieldNames: unref(getFieldNames), showCheckedStrategy: Cascader.SHOW_CHILD }));
</script>
 
<template>
  <Cascader v-bind="getBindValue">
    <template v-for="item in Object.keys($slots)" #[item]="data"><slot :name="item" v-bind="data || {}"></slot></template>
  </Cascader>
</template>