cosey 0.4.45 → 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",
@@ -1,12 +1,12 @@
1
- import { createVNode, mergeProps, ref, isVNode } from 'vue';
2
- import { ElLink, ElSwitch, ElMessage, ElTag } from 'element-plus';
1
+ import { defineComponent, ref, createVNode, mergeProps, isVNode } from 'vue';
2
+ import { ElSwitch, ElMessage, ElLink, ElTag } from 'element-plus';
3
3
  import { get } from 'lodash-es';
4
4
  import { LongText as _LongText } from '../../long-text/index.js';
5
5
  import { MediaCard as _MediaCard } from '../../media-card/index.js';
6
6
  import { MediaCardGroup as _MediaCardGroup } from '../../media-card-group/index.js';
7
7
  import { isEmpty, isString } from '../../../utils/is.js';
8
- import { Scope, getVNodeText } from '../../../utils/vue.js';
9
8
  import { formatToDate, formatToDateTime } from '../../../utils/date.js';
9
+ import { getVNodeText } from '../../../utils/vue.js';
10
10
  import { toArray } from '../../../utils/array.js';
11
11
 
12
12
  function _isSlot(s) {
@@ -25,6 +25,37 @@ const mapRendererColumnProps = {
25
25
  className: "is-tag"
26
26
  }
27
27
  };
28
+ const AsyncSwitch = defineComponent({
29
+ props: {
30
+ value: [String, Number, Boolean],
31
+ props: Object,
32
+ api: Function,
33
+ row: Object,
34
+ t: Function
35
+ },
36
+ setup(props) {
37
+ const loading = ref(false);
38
+ const value = ref(props.value);
39
+ return () => createVNode(ElSwitch, mergeProps(props.props, {
40
+ "model-value": value.value,
41
+ "loading": loading.value,
42
+ "validateEvent": false,
43
+ "onChange": async val => {
44
+ if (loading.value) {
45
+ return;
46
+ }
47
+ loading.value = true;
48
+ try {
49
+ await props.api?.(val, props.row);
50
+ value.value = val;
51
+ ElMessage.success(props.t?.("co.common.editSuccess"));
52
+ } catch {} finally {
53
+ loading.value = false;
54
+ }
55
+ }
56
+ }), null);
57
+ }
58
+ });
28
59
  function renderer({
29
60
  cellValue,
30
61
  row,
@@ -74,28 +105,13 @@ function renderer({
74
105
  }, obj.props), null);
75
106
  case "switch":
76
107
  {
77
- const loading = ref(false);
78
- const value = ref(cellValue);
79
- return createVNode(Scope, null, {
80
- default: () => [createVNode(ElSwitch, mergeProps(obj.props, {
81
- "model-value": value.value,
82
- "loading": loading.value,
83
- "validateEvent": false,
84
- "onChange": async val => {
85
- if (loading.value) {
86
- return;
87
- }
88
- loading.value = true;
89
- try {
90
- await obj.api?.(val, row);
91
- value.value = val;
92
- ElMessage.success(t("co.common.editSuccess"));
93
- } catch {} finally {
94
- loading.value = false;
95
- }
96
- }
97
- }), null)]
98
- });
108
+ return createVNode(AsyncSwitch, {
109
+ "value": cellValue,
110
+ "props": obj.props,
111
+ "api": obj.api,
112
+ "row": row,
113
+ "t": t
114
+ }, null);
99
115
  }
100
116
  case "click":
101
117
  return createVNode(ElLink, mergeProps({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosey",
3
- "version": "0.4.45",
3
+ "version": "0.4.47",
4
4
  "description": "基于 Vue3 + vite 的后台管理系统框架",
5
5
  "type": "module",
6
6
  "main": "index.js",