rayyy-vue-table-components 2.0.15 → 2.0.17

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.
@@ -1,4 +1,5 @@
1
1
  import { Pager } from '../../types';
2
+ import { Language } from 'element-plus/es/locale';
2
3
  type __VLS_Props = {
3
4
  title: string;
4
5
  pagination: Pager;
@@ -6,6 +7,7 @@ type __VLS_Props = {
6
7
  showSearch?: boolean;
7
8
  pageSizeList?: number[];
8
9
  showPagination?: boolean;
10
+ locale?: Language;
9
11
  };
10
12
  declare function __VLS_template(): {
11
13
  attrs: Partial<{}>;
@@ -447,6 +447,10 @@ export interface SearchableListPanelProps {
447
447
  showSearch?: boolean
448
448
  /** 分頁大小選項列表 */
449
449
  pageSizeList?: number[]
450
+ /** 是否顯示分頁 */
451
+ showPagination?: boolean
452
+ /** Element Plus 語系設定 */
453
+ locale?: import('element-plus/es/locale').Language
450
454
  }
451
455
 
452
456
  /** SearchableListPanel 組件 Emits 類型 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rayyy-vue-table-components",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "Vue 3 + Element Plus 表格組件庫",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
@@ -3,6 +3,8 @@ import { toRefs, computed } from 'vue'
3
3
  import type { Pager } from '@/types'
4
4
  import { MainPanel, SearchBar } from '@/components'
5
5
  import { useComponentElementLocale } from '@/utils/i18n'
6
+ import type { Language } from 'element-plus/es/locale'
7
+ import zhTw from 'element-plus/es/locale/lang/zh-tw'
6
8
 
7
9
  const props = withDefaults(
8
10
  defineProps<{
@@ -12,6 +14,7 @@ const props = withDefaults(
12
14
  showSearch?: boolean
13
15
  pageSizeList?: number[]
14
16
  showPagination?: boolean
17
+ locale?: Language // 新增:Element Plus locale
15
18
  }>(),
16
19
  {
17
20
  pageSizeList: () => [10, 25, 50, 100, 200],
@@ -49,12 +52,19 @@ const showPager = computed(() => {
49
52
  if (props.showPagination) {
50
53
  return props.showPagination
51
54
  } else {
52
- return props.pagination.totalCount > 0
55
+ return props.pagination.totalCount > 0
53
56
  }
54
57
  })
55
58
 
56
- // 取得響應式的 Element Plus locale
57
- const elementLocale = useComponentElementLocale()
59
+ // 優先使用 prop,沒有 prop 則使用 composable
60
+ const elementLocale = computed(() => {
61
+ // 檢查 props.locale 是否為真正的 Language 對象(不是預設值)
62
+ if (props.locale && typeof props.locale === 'object' && 'name' in props.locale) {
63
+ return props.locale
64
+ }
65
+ // 回退:使用簡化的 composable
66
+ return useComponentElementLocale().value
67
+ })
58
68
  </script>
59
69
 
60
70
  <template>
@@ -448,6 +448,10 @@ export interface SearchableListPanelProps {
448
448
  showSearch?: boolean
449
449
  /** 分頁大小選項列表 */
450
450
  pageSizeList?: number[]
451
+ /** 是否顯示分頁 */
452
+ showPagination?: boolean
453
+ /** Element Plus 語系設定 */
454
+ locale?: import('element-plus/es/locale').Language
451
455
  }
452
456
 
453
457
  /** SearchableListPanel 組件 Emits 類型 */
package/src/utils/i18n.ts CHANGED
@@ -91,36 +91,15 @@ export function useI18n() {
91
91
  * 返回響應式的 Element Plus locale 對象
92
92
  */
93
93
  export function useElementLocale() {
94
- const instance = getCurrentInstance()
95
-
96
- // 在 computed 外部一次性獲取 i18n 引用
97
- let externalI18n: Composer | undefined
98
94
  try {
99
- const globalProperties = instance?.appContext.config.globalProperties
100
- const externalI18nInstance = globalProperties?.$i18n as I18n | undefined
101
-
102
- // 如果是 I18n 實例,取得其 global 屬性
103
- if (externalI18nInstance && 'global' in externalI18nInstance) {
104
- externalI18n = externalI18nInstance.global as Composer
105
- }
95
+ const { locale } = useI18n()
96
+ return computed(() => {
97
+ return locale.value === 'zh-TW' ? zhTw : enUs
98
+ })
106
99
  } catch (e) {
107
- // 如果取得失敗,繼續使用內部 i18n
108
- externalI18n = undefined
100
+ // 防呆:預設中文
101
+ return computed(() => zhTw)
109
102
  }
110
-
111
- // 取得內部 i18n
112
- const internalI18nInstance = getInternalI18n()
113
- const internalGlobal = internalI18nInstance.global as Composer
114
-
115
- // 決定使用哪個 i18n(在 computed 外部決定)
116
- const currentI18n = externalI18n || internalGlobal
117
-
118
- // 返回響應式的 Element Plus locale
119
- // 現在 Vue 可以正確追蹤 currentI18n.locale.value 的變化
120
- return computed(() => {
121
- const locale = currentI18n.locale.value // ✅ Vue 可以追蹤!
122
- return locale === 'zh-TW' ? zhTw : enUs
123
- })
124
103
  }
125
104
 
126
105
  /**
@@ -128,34 +107,15 @@ export function useElementLocale() {
128
107
  * 專門用於組件庫內部的 Element Plus 組件
129
108
  */
130
109
  export function useComponentElementLocale() {
131
- const instance = getCurrentInstance()
132
-
133
- // 在 computed 外部一次性獲取 i18n 引用
134
- let externalI18n: Composer | undefined
135
110
  try {
136
- const globalProperties = instance?.appContext.config.globalProperties
137
- const externalI18nInstance = globalProperties?.$i18n as I18n | undefined
138
-
139
- if (externalI18nInstance && 'global' in externalI18nInstance) {
140
- externalI18n = externalI18nInstance.global as Composer
141
- }
111
+ const { locale } = useI18n()
112
+ return computed(() => {
113
+ return locale.value === 'zh-TW' ? zhTw : enUs
114
+ })
142
115
  } catch (e) {
143
- externalI18n = undefined
116
+ // 防呆:預設中文
117
+ return computed(() => zhTw)
144
118
  }
145
-
146
- // 取得內部 i18n
147
- const internalI18nInstance = getInternalI18n()
148
- const internalGlobal = internalI18nInstance.global as Composer
149
-
150
- // 決定使用哪個 i18n(在 computed 外部決定)
151
- const currentI18n = externalI18n || internalGlobal
152
-
153
- // 返回響應式的 Element Plus locale
154
- // 現在 Vue 可以正確追蹤 currentI18n.locale.value 的變化
155
- return computed(() => {
156
- const locale = currentI18n.locale.value // ✅ Vue 可以追蹤!
157
- return locale === 'zh-TW' ? zhTw : enUs
158
- })
159
119
  }
160
120
 
161
121
  // 導出類型