rayyy-vue-table-components 2.0.17 → 2.0.19

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.
@@ -8,7 +8,7 @@ import { default as TitleTable } from './components/tables/TitleTable.vue';
8
8
  import { default as SearchBar } from './components/items/SearchBar.vue';
9
9
  export * from './types';
10
10
  export * from './utils/tableHelper';
11
- export { useI18n, setLocale, useElementLocale, useComponentElementLocale } from './utils/i18n';
11
+ export { useI18n, setLocale, useComponentElementLocale } from './utils/i18n';
12
12
  export * from './locales';
13
13
  export { BaseTable, BaseBtn, BaseInput, BaseDialog, SortTable, TitleTable, SearchBar };
14
14
  export type { BaseTableProps, BaseTableEmits, BaseTableInstance, BaseBtnProps, BaseBtnEmits, BaseBtnInstance, BaseDialogProps, BaseDialogEmits, BaseDialogInstance, PluginOptions, VueTableComponentsPlugin, } from './types/components';
@@ -17,189 +17,7 @@ export declare function useComponentI18n(): {
17
17
  /**
18
18
  * 全域 i18n 實例(用於非組件環境)
19
19
  */
20
- export declare function useI18n(): Composer;
21
- /**
22
- * Element Plus locale composable
23
- * 返回響應式的 Element Plus locale 對象
24
- */
25
- export declare function useElementLocale(): import('vue').ComputedRef<{
26
- name: string;
27
- el: {
28
- breadcrumb: {
29
- label: string;
30
- };
31
- colorpicker: {
32
- confirm: string;
33
- clear: string;
34
- defaultLabel: string;
35
- description: string;
36
- alphaLabel: string;
37
- };
38
- datepicker: {
39
- now: string;
40
- today: string;
41
- cancel: string;
42
- clear: string;
43
- confirm: string;
44
- dateTablePrompt: string;
45
- monthTablePrompt: string;
46
- yearTablePrompt: string;
47
- selectedDate: string;
48
- selectDate: string;
49
- selectTime: string;
50
- startDate: string;
51
- startTime: string;
52
- endDate: string;
53
- endTime: string;
54
- prevYear: string;
55
- nextYear: string;
56
- prevMonth: string;
57
- nextMonth: string;
58
- year: string;
59
- month1: string;
60
- month2: string;
61
- month3: string;
62
- month4: string;
63
- month5: string;
64
- month6: string;
65
- month7: string;
66
- month8: string;
67
- month9: string;
68
- month10: string;
69
- month11: string;
70
- month12: string;
71
- weeks: {
72
- sun: string;
73
- mon: string;
74
- tue: string;
75
- wed: string;
76
- thu: string;
77
- fri: string;
78
- sat: string;
79
- };
80
- weeksFull: {
81
- sun: string;
82
- mon: string;
83
- tue: string;
84
- wed: string;
85
- thu: string;
86
- fri: string;
87
- sat: string;
88
- };
89
- months: {
90
- jan: string;
91
- feb: string;
92
- mar: string;
93
- apr: string;
94
- may: string;
95
- jun: string;
96
- jul: string;
97
- aug: string;
98
- sep: string;
99
- oct: string;
100
- nov: string;
101
- dec: string;
102
- };
103
- };
104
- inputNumber: {
105
- decrease: string;
106
- increase: string;
107
- };
108
- select: {
109
- loading: string;
110
- noMatch: string;
111
- noData: string;
112
- placeholder: string;
113
- };
114
- mention: {
115
- loading: string;
116
- };
117
- dropdown: {
118
- toggleDropdown: string;
119
- };
120
- cascader: {
121
- noMatch: string;
122
- loading: string;
123
- placeholder: string;
124
- noData: string;
125
- };
126
- pagination: {
127
- goto: string;
128
- pagesize: string;
129
- total: string;
130
- pageClassifier: string;
131
- page: string;
132
- prev: string;
133
- next: string;
134
- currentPage: string;
135
- prevPages: string;
136
- nextPages: string;
137
- deprecationWarning: string;
138
- };
139
- dialog: {
140
- close: string;
141
- };
142
- drawer: {
143
- close: string;
144
- };
145
- messagebox: {
146
- title: string;
147
- confirm: string;
148
- cancel: string;
149
- error: string;
150
- close: string;
151
- };
152
- upload: {
153
- deleteTip: string;
154
- delete: string;
155
- preview: string;
156
- continue: string;
157
- };
158
- slider: {
159
- defaultLabel: string;
160
- defaultRangeStartLabel: string;
161
- defaultRangeEndLabel: string;
162
- };
163
- table: {
164
- emptyText: string;
165
- confirmFilter: string;
166
- resetFilter: string;
167
- clearFilter: string;
168
- sumText: string;
169
- };
170
- tour: {
171
- next: string;
172
- previous: string;
173
- finish: string;
174
- };
175
- tree: {
176
- emptyText: string;
177
- };
178
- transfer: {
179
- noMatch: string;
180
- noData: string;
181
- titles: string[];
182
- filterPlaceholder: string;
183
- noCheckedFormat: string;
184
- hasCheckedFormat: string;
185
- };
186
- image: {
187
- error: string;
188
- };
189
- pageHeader: {
190
- title: string;
191
- };
192
- popconfirm: {
193
- confirmButtonText: string;
194
- cancelButtonText: string;
195
- };
196
- carousel: {
197
- leftArrow: string;
198
- rightArrow: string;
199
- indicator: string;
200
- };
201
- };
202
- }>;
20
+ export declare function useI18n(): Composer<{}, {}, {}, string, never, string>;
203
21
  /**
204
22
  * 組件庫內部使用的 Element Plus locale composable
205
23
  * 專門用於組件庫內部的 Element Plus 組件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rayyy-vue-table-components",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "description": "Vue 3 + Element Plus 表格組件庫",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
@@ -1,10 +1,9 @@
1
1
  <script setup lang="ts">
2
- import { toRefs, computed } from 'vue'
2
+ import { toRefs, computed, watch } from 'vue'
3
3
  import type { Pager } from '@/types'
4
4
  import { MainPanel, SearchBar } from '@/components'
5
5
  import { useComponentElementLocale } from '@/utils/i18n'
6
6
  import type { Language } from 'element-plus/es/locale'
7
- import zhTw from 'element-plus/es/locale/lang/zh-tw'
8
7
 
9
8
  const props = withDefaults(
10
9
  defineProps<{
@@ -56,14 +55,30 @@ const showPager = computed(() => {
56
55
  }
57
56
  })
58
57
 
58
+ // 在 computed 外部調用,保持引用穩定
59
+ const fallbackLocale = useComponentElementLocale()
60
+
61
+ // 監聽 fallbackLocale 的變化
62
+ watch(fallbackLocale, (newLocale, oldLocale) => {
63
+ console.log('🔄 [SearchableListPanel] fallbackLocale 變化:', {
64
+ old: oldLocale?.name,
65
+ new: newLocale?.name
66
+ })
67
+ }, { immediate: true })
68
+
59
69
  // 優先使用 prop,沒有 prop 則使用 composable
60
70
  const elementLocale = computed(() => {
71
+ console.log('🔍 [SearchableListPanel] elementLocale computed 執行')
72
+
61
73
  // 檢查 props.locale 是否為真正的 Language 對象(不是預設值)
62
74
  if (props.locale && typeof props.locale === 'object' && 'name' in props.locale) {
75
+ console.log('🔍 [SearchableListPanel] 使用 props.locale:', props.locale.name)
63
76
  return props.locale
64
77
  }
65
- // 回退:使用簡化的 composable
66
- return useComponentElementLocale().value
78
+
79
+ console.log('🔍 [SearchableListPanel] 使用 fallbackLocale:', fallbackLocale.value.name)
80
+ // 現在能正確追蹤響應式
81
+ return fallbackLocale.value
67
82
  })
68
83
  </script>
69
84
 
package/src/utils/i18n.ts CHANGED
@@ -42,30 +42,44 @@ export function setLocale(locale: string): void {
42
42
  * 會優先使用外部專案的 i18n,如果不存在則使用內部 i18n
43
43
  */
44
44
  export function useComponentI18n() {
45
+ console.log('🔍 [useComponentI18n] 開始執行')
46
+
45
47
  const instance = getCurrentInstance()
48
+ console.log('🔍 [useComponentI18n] 獲取 instance:', !!instance)
46
49
 
47
50
  // 嘗試取得外部專案的 i18n(支援 Composition API 模式)
48
51
  let externalI18n: Composer | undefined
49
52
  try {
53
+ console.log('🔍 [useComponentI18n] 嘗試獲取外部 i18n')
50
54
  const globalProperties = instance?.appContext.config.globalProperties
55
+ console.log('🔍 [useComponentI18n] globalProperties:', !!globalProperties)
56
+
51
57
  const externalI18nInstance = globalProperties?.$i18n as I18n | undefined
58
+ console.log('🔍 [useComponentI18n] externalI18nInstance:', !!externalI18nInstance)
52
59
 
53
60
  // 如果是 I18n 實例,取得其 global 屬性
54
61
  if (externalI18nInstance && 'global' in externalI18nInstance) {
55
62
  externalI18n = externalI18nInstance.global as Composer
63
+ console.log('🔍 [useComponentI18n] 成功獲取外部 i18n,locale:', externalI18n.locale.value)
64
+ } else {
65
+ console.log('🔍 [useComponentI18n] 外部 i18n 實例不存在或格式不正確')
56
66
  }
57
67
  } catch (e) {
68
+ console.log('❌ [useComponentI18n] 獲取外部 i18n 失敗:', e)
58
69
  // 如果取得失敗,繼續使用內部 i18n
59
70
  externalI18n = undefined
60
71
  }
61
72
 
62
73
  // 取得內部 i18n
74
+ console.log('🔍 [useComponentI18n] 獲取內部 i18n')
63
75
  const internalI18nInstance = getInternalI18n()
64
76
  const internalGlobal = internalI18nInstance.global as Composer
77
+ console.log('🔍 [useComponentI18n] 內部 i18n locale:', internalGlobal.locale.value)
65
78
 
66
79
  // 如果存在外部 i18n,優先使用外部的(因為外部可能有覆蓋的翻譯)
67
80
  // 但要支援回退到內部 i18n
68
81
  const currentI18n = externalI18n || internalGlobal
82
+ console.log('🔍 [useComponentI18n] 最終使用 i18n:', externalI18n ? '外部' : '內部', 'locale:', currentI18n.locale.value)
69
83
 
70
84
  // 直接使用 i18n 的 t 函數(它本身就是響應式的)
71
85
  // 如果需要回退邏輯,我們需要檢查 key 是否存在
@@ -82,24 +96,11 @@ export function useComponentI18n() {
82
96
  * 全域 i18n 實例(用於非組件環境)
83
97
  */
84
98
  export function useI18n() {
99
+ console.log('🔍 [useI18n] 開始執行')
85
100
  const i18n = getInternalI18n()
86
- return i18n.global as Composer
87
- }
88
-
89
- /**
90
- * Element Plus locale composable
91
- * 返回響應式的 Element Plus locale 對象
92
- */
93
- export function useElementLocale() {
94
- try {
95
- const { locale } = useI18n()
96
- return computed(() => {
97
- return locale.value === 'zh-TW' ? zhTw : enUs
98
- })
99
- } catch (e) {
100
- // 防呆:預設中文
101
- return computed(() => zhTw)
102
- }
101
+ const global = i18n.global as Composer
102
+ console.log('🔍 [useI18n] 返回內部 i18n,locale:', global.locale.value)
103
+ return global
103
104
  }
104
105
 
105
106
  /**
@@ -107,17 +108,28 @@ export function useElementLocale() {
107
108
  * 專門用於組件庫內部的 Element Plus 組件
108
109
  */
109
110
  export function useComponentElementLocale() {
111
+ console.log('🔍 [useComponentElementLocale] 開始執行')
112
+
110
113
  try {
114
+ console.log('🔍 [useComponentElementLocale] 嘗試獲取 useI18n()')
111
115
  const { locale } = useI18n()
116
+ console.log('🔍 [useComponentElementLocale] 成功獲取 locale:', locale.value)
117
+
112
118
  return computed(() => {
113
- return locale.value === 'zh-TW' ? zhTw : enUs
119
+ console.log('🔍 [useComponentElementLocale] computed 重新計算,locale.value:', locale.value)
120
+ const result = locale.value === 'zh-TW' ? zhTw : enUs
121
+ console.log('🔍 [useComponentElementLocale] 返回結果:', result.name)
122
+ return result
114
123
  })
115
124
  } catch (e) {
125
+ console.log('❌ [useComponentElementLocale] 獲取 useI18n() 失敗:', e)
116
126
  // 防呆:預設中文
117
- return computed(() => zhTw)
127
+ return computed(() => {
128
+ console.log('🔍 [useComponentElementLocale] 使用預設中文')
129
+ return zhTw
130
+ })
118
131
  }
119
132
  }
120
133
 
121
134
  // 導出類型
122
135
  export type { I18n, Composer }
123
-