yc-pro-components 0.0.11 → 0.0.13

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.
Files changed (194) hide show
  1. package/es/components/check-card/index.d.ts +61 -61
  2. package/es/components/check-card/src/index.vue.d.ts +4 -4
  3. package/es/components/check-card-group/index.d.ts +43 -43
  4. package/es/components/check-card-group/src/index.vue.d.ts +3 -3
  5. package/es/components/date-picker/index.d.ts +10 -10
  6. package/es/components/date-picker/src/index.vue.d.ts +2 -2
  7. package/es/components/dialog/index.d.ts +26 -26
  8. package/es/components/dialog/src/index.vue.d.ts +2 -2
  9. package/es/components/dialog-form/index.d.ts +44 -32
  10. package/es/components/dialog-form/src/index.vue.d.ts +22 -10
  11. package/es/components/display-item/index.d.ts +80 -44
  12. package/es/components/display-item/src/index.vue.d.ts +61 -25
  13. package/es/components/drawer-form/index.d.ts +63 -51
  14. package/es/components/drawer-form/src/index.vue.d.ts +23 -11
  15. package/es/components/form/index.d.ts +71 -47
  16. package/es/components/form/src/form-content.vue.d.ts +60 -24
  17. package/es/components/form/src/index.vue.d.ts +43 -19
  18. package/es/components/form-item/index.d.ts +129 -57
  19. package/es/components/form-item/src/index.vue.d.ts +46 -15
  20. package/es/components/form-item/src/index.vue2.mjs +1 -0
  21. package/es/components/header/index.d.ts +19 -19
  22. package/es/components/header/src/index.vue.d.ts +1 -1
  23. package/es/components/input-tag/index.d.ts +20 -20
  24. package/es/components/input-tag/src/index.vue.d.ts +8 -8
  25. package/es/components/layout/index.d.ts +30 -30
  26. package/es/components/layout/src/index.vue.d.ts +10 -10
  27. package/es/components/page/index.d.ts +751 -469
  28. package/es/components/page/src/index.vue.d.ts +263 -161
  29. package/es/components/page/src/index.vue2.mjs +1 -1
  30. package/es/components/pagination/index.d.ts +42 -42
  31. package/es/components/pagination/src/index.vue.d.ts +3 -3
  32. package/es/components/radio/index.d.ts +35 -35
  33. package/es/components/radio/src/index.vue.d.ts +27 -27
  34. package/es/components/render/index.d.ts +6 -6
  35. package/es/components/render/src/index.vue.d.ts +2 -2
  36. package/es/components/search/index.d.ts +284 -162
  37. package/es/components/search/src/index.vue.d.ts +95 -53
  38. package/es/components/search/src/index.vue2.mjs +14 -4
  39. package/es/components/search/src/type.d.ts +9 -0
  40. package/es/components/sidebar/index.d.ts +15 -15
  41. package/es/components/sidebar/src/index.vue.d.ts +5 -5
  42. package/es/components/steps-form/index.d.ts +23 -23
  43. package/es/components/steps-form/src/index.vue.d.ts +2 -2
  44. package/es/components/table/index.d.ts +54 -54
  45. package/es/components/table/src/index.vue.d.ts +18 -18
  46. package/es/components/table/src/table-action-bar.vue2.mjs +1 -1
  47. package/es/components/table/src/table-column-drag-sort.vue.d.ts +18 -18
  48. package/es/components/table/src/table-column.vue.d.ts +76 -40
  49. package/es/components/utils/index.d.ts +2 -2
  50. package/es/components/yc-dialog/index.d.ts +24 -24
  51. package/es/components/yc-download-dialog/index.d.ts +19 -19
  52. package/es/components/yc-download-dialog/src/index.vue.d.ts +1 -1
  53. package/es/components/yc-form-container-header/index.d.ts +12 -12
  54. package/es/components/yc-more-actions/index.d.ts +46 -46
  55. package/es/components/yc-more-actions/src/index.vue.d.ts +3 -3
  56. package/es/components/yc-plus-page/src/index.vue.d.ts +588 -529
  57. package/es/components/yc-plus-page/src/index.vue.mjs +1 -1
  58. package/es/components/yc-plus-page/src/index.vue2.mjs +8 -2
  59. package/es/components/yc-segmented/index.d.ts +2 -2
  60. package/es/components/yc-segmented/src/index.d.ts +2 -2
  61. package/es/components/yc-select-v2/src/index.vue.d.ts +3 -3
  62. package/es/components/yc-status-dialog/src/index.vue.d.ts +1 -1
  63. package/es/components/yc-tabs-with-filter/index.d.ts +16 -16
  64. package/es/components/yc-text/src/index.vue.d.ts +2 -2
  65. package/es/constants/dict.d.ts +78 -0
  66. package/es/constants/dict.mjs +3 -0
  67. package/es/constants/index.d.ts +1 -0
  68. package/es/constants/index.mjs +1 -0
  69. package/es/hooks/index.d.ts +1 -0
  70. package/es/hooks/index.mjs +1 -0
  71. package/es/hooks/useDictInjection.d.ts +38 -0
  72. package/es/hooks/useDictInjection.mjs +18 -0
  73. package/es/hooks/useGetOptions.mjs +118 -30
  74. package/es/hooks/usePlusFormReset.d.ts +286 -214
  75. package/es/index.css +1 -1
  76. package/es/index.d.ts +1 -1
  77. package/es/index.mjs +2 -0
  78. package/es/types/plus.d.ts +74 -0
  79. package/es/version.d.ts +1 -1
  80. package/es/version.mjs +1 -1
  81. package/es/yc-components/index.d.ts +1 -1
  82. package/es/yc-components/version.d.ts +1 -1
  83. package/index.css +9 -5
  84. package/index.js +187 -65
  85. package/index.min.css +1 -1
  86. package/index.min.js +7 -7
  87. package/index.min.mjs +7 -7
  88. package/index.mjs +187 -67
  89. package/lib/components/check-card/index.d.ts +61 -61
  90. package/lib/components/check-card/src/index.vue.d.ts +4 -4
  91. package/lib/components/check-card-group/index.d.ts +43 -43
  92. package/lib/components/check-card-group/src/index.vue.d.ts +3 -3
  93. package/lib/components/date-picker/index.d.ts +10 -10
  94. package/lib/components/date-picker/src/index.vue.d.ts +2 -2
  95. package/lib/components/dialog/index.d.ts +26 -26
  96. package/lib/components/dialog/src/index.vue.d.ts +2 -2
  97. package/lib/components/dialog-form/index.d.ts +44 -32
  98. package/lib/components/dialog-form/src/index.vue.d.ts +22 -10
  99. package/lib/components/display-item/index.d.ts +80 -44
  100. package/lib/components/display-item/src/index.vue.d.ts +61 -25
  101. package/lib/components/drawer-form/index.d.ts +63 -51
  102. package/lib/components/drawer-form/src/index.vue.d.ts +23 -11
  103. package/lib/components/form/index.d.ts +71 -47
  104. package/lib/components/form/src/form-content.vue.d.ts +60 -24
  105. package/lib/components/form/src/index.vue.d.ts +43 -19
  106. package/lib/components/form-item/index.d.ts +129 -57
  107. package/lib/components/form-item/src/index.vue.d.ts +46 -15
  108. package/lib/components/form-item/src/index.vue2.js +1 -0
  109. package/lib/components/header/index.d.ts +19 -19
  110. package/lib/components/header/src/index.vue.d.ts +1 -1
  111. package/lib/components/input-tag/index.d.ts +20 -20
  112. package/lib/components/input-tag/src/index.vue.d.ts +8 -8
  113. package/lib/components/layout/index.d.ts +30 -30
  114. package/lib/components/layout/src/index.vue.d.ts +10 -10
  115. package/lib/components/page/index.d.ts +751 -469
  116. package/lib/components/page/src/index.vue.d.ts +263 -161
  117. package/lib/components/page/src/index.vue2.js +1 -1
  118. package/lib/components/pagination/index.d.ts +42 -42
  119. package/lib/components/pagination/src/index.vue.d.ts +3 -3
  120. package/lib/components/radio/index.d.ts +35 -35
  121. package/lib/components/radio/src/index.vue.d.ts +27 -27
  122. package/lib/components/render/index.d.ts +6 -6
  123. package/lib/components/render/src/index.vue.d.ts +2 -2
  124. package/lib/components/search/index.d.ts +284 -162
  125. package/lib/components/search/src/index.vue.d.ts +95 -53
  126. package/lib/components/search/src/index.vue2.js +13 -3
  127. package/lib/components/search/src/type.d.ts +9 -0
  128. package/lib/components/sidebar/index.d.ts +15 -15
  129. package/lib/components/sidebar/src/index.vue.d.ts +5 -5
  130. package/lib/components/steps-form/index.d.ts +23 -23
  131. package/lib/components/steps-form/src/index.vue.d.ts +2 -2
  132. package/lib/components/table/index.d.ts +54 -54
  133. package/lib/components/table/src/index.vue.d.ts +18 -18
  134. package/lib/components/table/src/table-action-bar.vue2.js +1 -1
  135. package/lib/components/table/src/table-column-drag-sort.vue.d.ts +18 -18
  136. package/lib/components/table/src/table-column.vue.d.ts +76 -40
  137. package/lib/components/utils/index.d.ts +2 -2
  138. package/lib/components/yc-dialog/index.d.ts +24 -24
  139. package/lib/components/yc-download-dialog/index.d.ts +19 -19
  140. package/lib/components/yc-download-dialog/src/index.vue.d.ts +1 -1
  141. package/lib/components/yc-form-container-header/index.d.ts +12 -12
  142. package/lib/components/yc-more-actions/index.d.ts +46 -46
  143. package/lib/components/yc-more-actions/src/index.vue.d.ts +3 -3
  144. package/lib/components/yc-plus-page/src/index.vue.d.ts +588 -529
  145. package/lib/components/yc-plus-page/src/index.vue.js +1 -1
  146. package/lib/components/yc-plus-page/src/index.vue2.js +8 -2
  147. package/lib/components/yc-segmented/index.d.ts +2 -2
  148. package/lib/components/yc-segmented/src/index.d.ts +2 -2
  149. package/lib/components/yc-select-v2/src/index.vue.d.ts +3 -3
  150. package/lib/components/yc-status-dialog/src/index.vue.d.ts +1 -1
  151. package/lib/components/yc-tabs-with-filter/index.d.ts +16 -16
  152. package/lib/components/yc-text/src/index.vue.d.ts +2 -2
  153. package/lib/constants/dict.d.ts +78 -0
  154. package/lib/constants/dict.js +5 -0
  155. package/lib/constants/index.d.ts +1 -0
  156. package/lib/constants/index.js +2 -0
  157. package/lib/hooks/index.d.ts +1 -0
  158. package/lib/hooks/index.js +2 -0
  159. package/lib/hooks/useDictInjection.d.ts +38 -0
  160. package/lib/hooks/useDictInjection.js +20 -0
  161. package/lib/hooks/useGetOptions.js +117 -29
  162. package/lib/hooks/usePlusFormReset.d.ts +286 -214
  163. package/lib/index.css +1 -1
  164. package/lib/index.d.ts +1 -1
  165. package/lib/index.js +4 -0
  166. package/lib/types/plus.d.ts +74 -0
  167. package/lib/version.d.ts +1 -1
  168. package/lib/version.js +1 -1
  169. package/lib/yc-components/index.d.ts +1 -1
  170. package/lib/yc-components/version.d.ts +1 -1
  171. package/locale/en.js +1 -1
  172. package/locale/en.min.js +1 -1
  173. package/locale/en.min.mjs +1 -1
  174. package/locale/en.mjs +1 -1
  175. package/locale/ja.js +1 -1
  176. package/locale/ja.min.js +1 -1
  177. package/locale/ja.min.mjs +1 -1
  178. package/locale/ja.mjs +1 -1
  179. package/locale/ko.js +1 -1
  180. package/locale/ko.min.js +1 -1
  181. package/locale/ko.min.mjs +1 -1
  182. package/locale/ko.mjs +1 -1
  183. package/locale/zh-cn.js +1 -1
  184. package/locale/zh-cn.min.js +1 -1
  185. package/locale/zh-cn.min.mjs +1 -1
  186. package/locale/zh-cn.mjs +1 -1
  187. package/locale/zh-tw.js +1 -1
  188. package/locale/zh-tw.min.js +1 -1
  189. package/locale/zh-tw.min.mjs +1 -1
  190. package/locale/zh-tw.mjs +1 -1
  191. package/package.json +1 -1
  192. package/theme-chalk/index.css +1 -1
  193. package/theme-chalk/plus-page.css +1 -1
  194. package/theme-chalk/src/page.scss +1 -1
@@ -1,6 +1,6 @@
1
1
  import _sfc_main from './index.vue2.mjs';
2
2
  import _export_sfc from '../../../_virtual/_plugin-vue_export-helper.mjs';
3
3
 
4
- var YcPlusPageComponent = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-4486eb75"], ["__file", "index.vue"]]);
4
+ var YcPlusPageComponent = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-7c1490fd"], ["__file", "index.vue"]]);
5
5
 
6
6
  export { YcPlusPageComponent as default };
@@ -146,7 +146,10 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
146
146
  hasUnfold: false,
147
147
  rowProps: { gutter: 0 },
148
148
  colProps: { span: getSpanByCount(searchableFieldsCount.value) },
149
- labelSuffix: ""
149
+ labelSuffix: "",
150
+ labelPosition: "right",
151
+ searchIcon: null,
152
+ resetIcon: null
150
153
  };
151
154
  return merge({}, defaultSearchConfig, props.search);
152
155
  }
@@ -154,7 +157,10 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
154
157
  hasUnfold: false,
155
158
  rowProps: { gutter: 0 },
156
159
  colProps: { span: getSpanByCount(searchableFieldsCount.value) },
157
- labelSuffix: ""
160
+ labelSuffix: "",
161
+ labelPosition: "right",
162
+ searchIcon: null,
163
+ resetIcon: null
158
164
  };
159
165
  });
160
166
  const mergedSearchCardProps = computed(() => {
@@ -54,12 +54,12 @@ export declare const YcSegmentedWithInstall: SFCWithInstall<DefineComponent<{
54
54
  default: boolean;
55
55
  };
56
56
  }>> & {
57
- "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
58
57
  onChange?: ((...args: any[]) => any) | undefined;
58
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
59
59
  }, {
60
- modelValue: string | number;
61
60
  disabled: boolean;
62
61
  options: YcSegmentedOption[];
62
+ modelValue: string | number;
63
63
  resize: boolean;
64
64
  block: boolean;
65
65
  }, {}>>;
@@ -62,12 +62,12 @@ declare const _default: DefineComponent<{
62
62
  default: boolean;
63
63
  };
64
64
  }>> & {
65
- "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
66
65
  onChange?: ((...args: any[]) => any) | undefined;
66
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
67
67
  }, {
68
- modelValue: string | number;
69
68
  disabled: boolean;
70
69
  options: YcSegmentedOption[];
70
+ modelValue: string | number;
71
71
  resize: boolean;
72
72
  block: boolean;
73
73
  }, {}>;
@@ -44,14 +44,14 @@ declare const _default: DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRunt
44
44
  initialOptions: () => never[];
45
45
  allSelect: boolean;
46
46
  }>>> & {
47
- "onUpdate:modelValue"?: ((value: FieldValueType) => any) | undefined;
48
47
  onChange?: ((value: SelectValueType) => any) | undefined;
48
+ "onUpdate:modelValue"?: ((value: FieldValueType) => any) | undefined;
49
49
  }, {
50
- modelValue: string | number | boolean | string[] | [string, string] | boolean[] | RecordType | Date | number[] | Date[] | [Date, Date] | [number, number] | string[][] | number[][] | null;
51
- filterable: boolean;
52
50
  disabled: boolean;
51
+ filterable: boolean;
53
52
  options: SelectOption[];
54
53
  pageSize: number;
54
+ modelValue: string | number | boolean | string[] | [string, string] | number[] | Date | RecordType | boolean[] | Date[] | [Date, Date] | [number, number] | string[][] | number[][] | null;
55
55
  multiple: boolean;
56
56
  clearable: boolean;
57
57
  placeholder: string;
@@ -28,9 +28,9 @@ declare const _default: __VLS_WithTemplateSlots< DefineComponent<__VLS_WithDefau
28
28
  onCancel?: (() => any) | undefined;
29
29
  onConfirm?: (() => any) | undefined;
30
30
  }, {
31
+ content: string;
31
32
  title: string;
32
33
  width: string | number;
33
- content: string;
34
34
  visible: boolean;
35
35
  status: StatusType;
36
36
  cancelText: string;
@@ -5,14 +5,14 @@ import { default as YcTabsWithFilter } from './src/index.vue';
5
5
  /** 带筛选按钮的 Tabs 组件 */
6
6
  export declare const YcTabsWithFilterWithInstall: SFCWithInstall<{
7
7
  new (...args: any[]): CreateComponentPublicInstance<Readonly< ExtractPropTypes<{
8
- filterText: {
9
- type: PropType<string>;
10
- default: undefined;
11
- };
12
8
  modelValue: {
13
9
  type: PropType<string>;
14
10
  required: true;
15
11
  };
12
+ filterText: {
13
+ type: PropType<string>;
14
+ default: undefined;
15
+ };
16
16
  showFilter: {
17
17
  type: PropType<boolean>;
18
18
  default: boolean;
@@ -38,14 +38,14 @@ export declare const YcTabsWithFilterWithInstall: SFCWithInstall<{
38
38
  "update:modelValue": (value: string) => void;
39
39
  "filter-toggle": (visible: boolean) => void;
40
40
  }, VNodeProps & AllowedComponentProps & ComponentCustomProps & Readonly< ExtractPropTypes<{
41
- filterText: {
42
- type: PropType<string>;
43
- default: undefined;
44
- };
45
41
  modelValue: {
46
42
  type: PropType<string>;
47
43
  required: true;
48
44
  };
45
+ filterText: {
46
+ type: PropType<string>;
47
+ default: undefined;
48
+ };
49
49
  showFilter: {
50
50
  type: PropType<boolean>;
51
51
  default: boolean;
@@ -79,14 +79,14 @@ export declare const YcTabsWithFilterWithInstall: SFCWithInstall<{
79
79
  M: {};
80
80
  Defaults: {};
81
81
  }, Readonly< ExtractPropTypes<{
82
- filterText: {
83
- type: PropType<string>;
84
- default: undefined;
85
- };
86
82
  modelValue: {
87
83
  type: PropType<string>;
88
84
  required: true;
89
85
  };
86
+ filterText: {
87
+ type: PropType<string>;
88
+ default: undefined;
89
+ };
90
90
  showFilter: {
91
91
  type: PropType<boolean>;
92
92
  default: boolean;
@@ -119,14 +119,14 @@ export declare const YcTabsWithFilterWithInstall: SFCWithInstall<{
119
119
  __isTeleport?: undefined;
120
120
  __isSuspense?: undefined;
121
121
  } & ComponentOptionsBase<Readonly< ExtractPropTypes<{
122
- filterText: {
123
- type: PropType<string>;
124
- default: undefined;
125
- };
126
122
  modelValue: {
127
123
  type: PropType<string>;
128
124
  required: true;
129
125
  };
126
+ filterText: {
127
+ type: PropType<string>;
128
+ default: undefined;
129
+ };
130
130
  showFilter: {
131
131
  type: PropType<boolean>;
132
132
  default: boolean;
@@ -9,7 +9,7 @@ interface TippyOptions {
9
9
  declare const _default: __VLS_WithTemplateSlots< DefineComponent<{
10
10
  /** 行数限制 */
11
11
  lineClamp: {
12
- type: (NumberConstructor | StringConstructor)[];
12
+ type: (StringConstructor | NumberConstructor)[];
13
13
  };
14
14
  /** Tippy 配置 */
15
15
  tippyProps: {
@@ -19,7 +19,7 @@ declare const _default: __VLS_WithTemplateSlots< DefineComponent<{
19
19
  }, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
20
20
  /** 行数限制 */
21
21
  lineClamp: {
22
- type: (NumberConstructor | StringConstructor)[];
22
+ type: (StringConstructor | NumberConstructor)[];
23
23
  };
24
24
  /** Tippy 配置 */
25
25
  tippyProps: {
@@ -0,0 +1,78 @@
1
+ import { OptionsRow } from 'yc-pro-components/es/types';
2
+ import { InjectionKey } from 'vue';
3
+
4
+ /**
5
+ * 字典 Store 标准接口
6
+ * @description 所有项目的字典 Store 必须实现此接口才能使用自动字典注入功能
7
+ * @version v0.2.0
8
+ * @example
9
+ * ```ts
10
+ * import type { DictStoreInterface } from 'yc-components'
11
+ *
12
+ * export const useDictStore = defineStore('dict', () => {
13
+ * const getDictData = (field: string): OptionsRow[] => {
14
+ * // 返回字典数据
15
+ * return dictData.value[field] || []
16
+ * }
17
+ *
18
+ * const hasDict = (field: string): boolean => {
19
+ * return !!dictData.value[field]
20
+ * }
21
+ *
22
+ * const getDictLabel = (field: string, value: string | number): string => {
23
+ * const items = dictData.value[field] || []
24
+ * const item = items.find(item => item.value === value)
25
+ * return item?.label || String(value)
26
+ * }
27
+ *
28
+ * return { getDictData, hasDict, getDictLabel }
29
+ * })
30
+ * ```
31
+ */
32
+ export interface DictStoreInterface {
33
+ /**
34
+ * 根据字段名或字典 code 获取字典数据
35
+ * @param field 字段名(如 "status")或字典 code(如 "ORDER_STATUS")
36
+ * @returns 字典选项数组
37
+ * @description 此方法是核心方法,必须实现
38
+ */
39
+ getDictData: (field: string) => OptionsRow[];
40
+ /**
41
+ * 检查字段是否有字典映射
42
+ * @param field 字段名或字典 code
43
+ * @returns 是否存在字典数据
44
+ * @description 可选方法,用于优化性能
45
+ */
46
+ hasDict?: (field: string) => boolean;
47
+ /**
48
+ * 获取字典标签
49
+ * @param field 字段名或字典 code
50
+ * @param value 字典值
51
+ * @returns 字典标签
52
+ * @description 可选方法,用于显示字典标签
53
+ */
54
+ getDictLabel?: (field: string, value: string | number) => string;
55
+ }
56
+ /**
57
+ * 字典 Store 注入 Key
58
+ * @description 用于 provide/inject 传递字典 Store 实例
59
+ * @version v0.2.0
60
+ * @example
61
+ * ```ts
62
+ * // 提供字典 Store
63
+ * import { provide } from 'vue'
64
+ * import { DictStoreInjectionKey } from 'yc-components'
65
+ *
66
+ * const dictStore = useDictStore()
67
+ * provide(DictStoreInjectionKey, dictStore)
68
+ * ```
69
+ *
70
+ * ```ts
71
+ * // 注入字典 Store
72
+ * import { inject } from 'vue'
73
+ * import { DictStoreInjectionKey } from 'yc-components'
74
+ *
75
+ * const dictStore = inject(DictStoreInjectionKey)
76
+ * ```
77
+ */
78
+ export declare const DictStoreInjectionKey: InjectionKey<DictStoreInterface>;
@@ -0,0 +1,3 @@
1
+ const DictStoreInjectionKey = Symbol("DictStore");
2
+
3
+ export { DictStoreInjectionKey };
@@ -1,3 +1,4 @@
1
1
  export * from './page';
2
2
  export * from './form';
3
3
  export * from './display-item';
4
+ export * from './dict';
@@ -1,3 +1,4 @@
1
1
  export { DefaultPageInfo, DefaultPageSizeList } from './page.mjs';
2
2
  export { DatePickerValueIsArrayList, TableFormFieldRefInjectionKey, TableFormRefInjectionKey, TableFormRowInfoInjectionKey, ValueIsArrayList, ValueIsBooleanList, ValueIsNumberList } from './form.mjs';
3
3
  export { selectValueTypeList } from './display-item.mjs';
4
+ export { DictStoreInjectionKey } from './dict.mjs';
@@ -6,3 +6,4 @@ export * from './usePlusProConfig';
6
6
  export * from './useSortableDrag';
7
7
  export * from './usePlusFormReset';
8
8
  export * from './useSelectWithPagination';
9
+ export * from './useDictInjection';
@@ -6,3 +6,4 @@ export { providePlusProConfig, useDialogFormConfig, useDrawerFormConfig, usePlus
6
6
  export { useSortableDrag } from './useSortableDrag.mjs';
7
7
  export { usePlusFormClearValidate, usePlusFormFullReset, usePlusFormReset } from './usePlusFormReset.mjs';
8
8
  export { useSelectWithPagination } from './useSelectWithPagination.mjs';
9
+ export { useDictInjection } from './useDictInjection.mjs';
@@ -0,0 +1,38 @@
1
+ import { DictStoreInterface } from 'yc-pro-components/es/constants';
2
+
3
+ /**
4
+ * 提供字典 Store 给子组件
5
+ * @param dictStore 字典 Store 实例,必须实现 DictStoreInterface 接口
6
+ * @description 在父组件中调用此函数,将字典 Store 提供给所有子组件使用
7
+ * @version v0.2.0
8
+ * @example
9
+ * ```vue
10
+ * <!-- 在父组件中提供字典 Store -->
11
+ * <script setup lang="ts">
12
+ * import { useDictInjection } from 'yc-components'
13
+ * import { useFieldCatalogStore } from '@/store/modules/fieldCatalog'
14
+ *
15
+ * const fieldCatalogStore = useFieldCatalogStore()
16
+ *
17
+ * // 提供字典 Store 给所有子组件
18
+ * useDictInjection(fieldCatalogStore)
19
+ * </script>
20
+ *
21
+ * <template>
22
+ * <PlusPage :columns="columns" />
23
+ * </template>
24
+ * ```
25
+ *
26
+ * ```ts
27
+ * // 子组件中使用 autoDict
28
+ * const columns: PlusColumn[] = [
29
+ * {
30
+ * label: '状态',
31
+ * prop: 'status',
32
+ * valueType: 'select',
33
+ * autoDict: true // 自动从父组件注入的 dictStore 获取
34
+ * }
35
+ * ]
36
+ * ```
37
+ */
38
+ export declare function useDictInjection(dictStore: DictStoreInterface): void;
@@ -0,0 +1,18 @@
1
+ import { provide } from 'vue';
2
+ import { DictStoreInjectionKey } from '../constants/dict.mjs';
3
+
4
+ function useDictInjection(dictStore) {
5
+ if (!dictStore) {
6
+ console.warn("[yc-components] useDictInjection: dictStore is required");
7
+ return;
8
+ }
9
+ if (typeof dictStore.getDictData !== "function") {
10
+ console.error(
11
+ "[yc-components] useDictInjection: dictStore must implement getDictData method. Please ensure your dictStore implements DictStoreInterface."
12
+ );
13
+ return;
14
+ }
15
+ provide(DictStoreInjectionKey, dictStore);
16
+ }
17
+
18
+ export { useDictInjection };
@@ -1,4 +1,5 @@
1
- import { ref, isRef, isReactive, watch } from 'vue';
1
+ import { ref, inject, isRef, isReactive, watch } from 'vue';
2
+ import { DictStoreInjectionKey } from '../constants/dict.mjs';
2
3
  import { isPlainObject, isArray, isFunction, isPromise, toRawType } from '../components/utils/is.mjs';
3
4
 
4
5
  const throwError = (data) => {
@@ -27,27 +28,53 @@ const getOptionsByOptionsMap = (options, props) => {
27
28
  const useGetOptions = (props) => {
28
29
  const options = ref([]);
29
30
  const optionsIsReady = ref(false);
30
- if (!props.options) {
31
+ const injectedDictStore = inject(DictStoreInjectionKey, null);
32
+ const hasValidOptions = props.options && (!isArray(props.options) || props.options.length > 0);
33
+ if (hasValidOptions) {
34
+ handleOptions();
35
+ } else if (props.autoDict) {
36
+ handleAutoDict();
37
+ } else {
31
38
  options.value = [];
32
39
  optionsIsReady.value = true;
33
- } else if (isRef(props.options) || isReactive(props.options) || isArray(props.options)) {
34
- watch(
35
- () => props.options,
36
- (val) => {
37
- const value = isRef(val) ? val.value : val;
38
- options.value = getOptionsByOptionsMap(value, props);
40
+ }
41
+ function handleOptions() {
42
+ if (!props.options) {
43
+ options.value = [];
44
+ optionsIsReady.value = true;
45
+ return;
46
+ }
47
+ if (isRef(props.options) || isReactive(props.options) || isArray(props.options)) {
48
+ watch(
49
+ () => props.options,
50
+ (val) => {
51
+ const value = isRef(val) ? val.value : val;
52
+ options.value = getOptionsByOptionsMap(value, props);
53
+ optionsIsReady.value = true;
54
+ },
55
+ {
56
+ immediate: true,
57
+ deep: true
58
+ }
59
+ );
60
+ } else if (isFunction(props.options)) {
61
+ const getValue = props.options;
62
+ const result = getValue(props);
63
+ if (isPromise(result)) {
64
+ result.then((value) => {
65
+ options.value = getOptionsByOptionsMap(value, props);
66
+ optionsIsReady.value = true;
67
+ throwError(options.value);
68
+ }).catch((err) => {
69
+ throw err;
70
+ });
71
+ } else {
72
+ options.value = getOptionsByOptionsMap(result, props);
39
73
  optionsIsReady.value = true;
40
- },
41
- {
42
- immediate: true,
43
- deep: true
44
74
  }
45
- );
46
- } else if (isFunction(props.options)) {
47
- const getValue = props.options;
48
- const result = getValue(props);
49
- if (isPromise(result)) {
50
- result.then((value) => {
75
+ } else if (isPromise(props.options)) {
76
+ const getValue = props.options;
77
+ getValue.then((value) => {
51
78
  options.value = getOptionsByOptionsMap(value, props);
52
79
  optionsIsReady.value = true;
53
80
  throwError(options.value);
@@ -55,21 +82,82 @@ const useGetOptions = (props) => {
55
82
  throw err;
56
83
  });
57
84
  } else {
58
- options.value = getOptionsByOptionsMap(result, props);
59
85
  optionsIsReady.value = true;
86
+ throwError(props.options);
60
87
  }
61
- } else if (isPromise(props.options)) {
62
- const getValue = props.options;
63
- getValue.then((value) => {
64
- options.value = getOptionsByOptionsMap(value, props);
88
+ }
89
+ function handleAutoDict() {
90
+ if (isFunction(props.autoDict)) {
91
+ const autoDictFn = props.autoDict;
92
+ watch(
93
+ () => {
94
+ return autoDictFn(props);
95
+ },
96
+ (result) => {
97
+ if (isPromise(result)) {
98
+ result.then((value) => {
99
+ options.value = getOptionsByOptionsMap(value, props);
100
+ optionsIsReady.value = true;
101
+ }).catch((err) => {
102
+ console.error("[yc-components] autoDict function error:", err);
103
+ options.value = [];
104
+ optionsIsReady.value = true;
105
+ });
106
+ } else {
107
+ options.value = getOptionsByOptionsMap(result, props);
108
+ optionsIsReady.value = true;
109
+ }
110
+ },
111
+ { immediate: true }
112
+ );
113
+ } else if (typeof props.autoDict === "object" && props.autoDict !== null) {
114
+ const { store, method = "getDictData", transform, dictCode } = props.autoDict;
115
+ const dictStore = store || injectedDictStore;
116
+ const fieldOrCode = dictCode || props.prop;
117
+ if (dictStore && isFunction(dictStore[method])) {
118
+ watch(
119
+ () => dictStore[method](fieldOrCode),
120
+ (val) => {
121
+ try {
122
+ const data = transform && isFunction(transform) ? transform(val) : val;
123
+ options.value = getOptionsByOptionsMap(data, props);
124
+ optionsIsReady.value = true;
125
+ } catch (err) {
126
+ console.error("[yc-components] autoDict transform error:", err);
127
+ options.value = [];
128
+ optionsIsReady.value = true;
129
+ }
130
+ },
131
+ { immediate: true }
132
+ );
133
+ } else {
134
+ console.warn(
135
+ `[yc-components] autoDict: DictStore or method "${method}" not found for field "${fieldOrCode}"`
136
+ );
137
+ options.value = [];
138
+ optionsIsReady.value = true;
139
+ }
140
+ } else if (props.autoDict === true) {
141
+ if (injectedDictStore && isFunction(injectedDictStore.getDictData)) {
142
+ watch(
143
+ () => injectedDictStore.getDictData(props.prop),
144
+ (val) => {
145
+ options.value = getOptionsByOptionsMap(val, props);
146
+ optionsIsReady.value = true;
147
+ },
148
+ { immediate: true }
149
+ );
150
+ } else {
151
+ console.warn(
152
+ `[yc-components] autoDict: DictStore not provided via inject for field "${props.prop}". Please use useDictInjection() in parent component.`
153
+ );
154
+ options.value = [];
155
+ optionsIsReady.value = true;
156
+ }
157
+ } else {
158
+ options.value = [];
65
159
  optionsIsReady.value = true;
66
- throwError(options.value);
67
- }).catch((err) => {
68
- throw err;
69
- });
70
- } else {
71
- optionsIsReady.value = true;
72
- throwError(props.options);
160
+ }
73
161
  }
74
162
  return { customOptions: options, customOptionsIsReady: optionsIsReady };
75
163
  };