cosey 0.4.46 → 0.4.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { ElSelect, ElOptionGroup, ElOption } from 'element-plus';
2
2
  import { defineComponent, computed, unref, h, mergeProps } from 'vue';
3
3
  import { fieldSelectOmitKeys, flatGroup } from './select.js';
4
4
  import { omit } from 'lodash-es';
5
- import { isFunction } from '../../../../utils/is.js';
5
+ import { isFunction, isObject } from '../../../../utils/is.js';
6
6
  import { useLocale } from '../../../../hooks/useLocale.js';
7
7
  import { addNullablePlaceholder } from '../../../../utils/vue.js';
8
8
  import { getLabelByValue } from '../../../../utils/collection.js';
@@ -43,7 +43,7 @@ var stdin_default = defineComponent((props, {
43
43
  const optionProps = componentProps.value.optionProps;
44
44
  return h(ElOption, {
45
45
  ...option,
46
- key: option.value,
46
+ key: isObject(option.value) && componentProps.value.valueKey ? option.value[componentProps.value.valueKey] : option.value,
47
47
  ...(isFunction(optionProps) ? optionProps(option, index) : optionProps)
48
48
  }, slots.option ? () => slots.option(option, index) : void 0);
49
49
  }
@@ -13,6 +13,7 @@ export interface FieldSelectV2Props extends FieldComponentCommonProps {
13
13
  } & {
14
14
  labelKey?: string;
15
15
  valueKey?: string;
16
+ optionProps?: (props: Record<PropertyKey, any>, index: number) => Record<PropertyKey, any>;
16
17
  };
17
18
  componentSlots?: Partial<FieldSelectV2Slots>;
18
19
  }
@@ -1,5 +1,5 @@
1
1
  import { ElSelectV2 } from 'element-plus';
2
- import { defineComponent, computed, h, mergeProps } from 'vue';
2
+ import { defineComponent, computed, unref, h, mergeProps } from 'vue';
3
3
  import { flatGroup } from './select-v2.js';
4
4
  import { useLocale } from '../../../../hooks/useLocale.js';
5
5
  import { addNullablePlaceholder } from '../../../../utils/vue.js';
@@ -12,6 +12,22 @@ var stdin_default = defineComponent((props, {
12
12
  t
13
13
  } = useLocale();
14
14
  const componentProps = computed(() => props.componentProps || {});
15
+ const childrenKey = computed(() => componentProps.value.props?.options || "children");
16
+ const optionProps = computed(() => componentProps.value.optionProps || (option => option));
17
+ function convertRecur(options) {
18
+ return options.map((option, index) => {
19
+ if (childrenKey.value in option) {
20
+ return {
21
+ ...optionProps.value(option, index),
22
+ [childrenKey.value]: convertRecur(option[childrenKey.value])
23
+ };
24
+ }
25
+ return optionProps.value(option, index);
26
+ });
27
+ }
28
+ const convertedOptions = computed(() => {
29
+ return convertRecur(unref(componentProps.value.options) ?? []);
30
+ });
15
31
  return () => {
16
32
  if (props.readonly) {
17
33
  const value = componentProps.value.modelValue;
@@ -26,7 +42,9 @@ var stdin_default = defineComponent((props, {
26
42
  style: {
27
43
  verticalAlign: "top"
28
44
  }
29
- }, componentProps.value), slots);
45
+ }, componentProps.value, {
46
+ options: convertedOptions.value
47
+ }), slots);
30
48
  };
31
49
  }, {
32
50
  name: "FieldSelectV2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosey",
3
- "version": "0.4.46",
3
+ "version": "0.4.47",
4
4
  "description": "基于 Vue3 + vite 的后台管理系统框架",
5
5
  "type": "module",
6
6
  "main": "index.js",