rayyy-vue-table-components 2.0.14 → 2.0.16

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<{}>;
@@ -31,6 +33,7 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}
31
33
  onUpdatePage?: ((page: number) => any) | undefined;
32
34
  onUpdatePageSize?: ((limit: number) => any) | undefined;
33
35
  }>, {
36
+ locale: Language;
34
37
  pageSizeList: number[];
35
38
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
36
39
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
@@ -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.14",
3
+ "version": "2.0.16",
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,9 +14,11 @@ 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],
21
+ locale: () => zhTw, // 預設值:中文
18
22
  },
19
23
  )
20
24
 
@@ -53,8 +57,14 @@ return props.pagination.totalCount > 0
53
57
  }
54
58
  })
55
59
 
56
- // 取得響應式的 Element Plus locale
57
- const elementLocale = useComponentElementLocale()
60
+ // 優先使用 prop,沒有 prop 則使用 composable
61
+ const elementLocale = computed(() => {
62
+ if (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,35 +91,15 @@ export function useI18n() {
91
91
  * 返回響應式的 Element Plus locale 對象
92
92
  */
93
93
  export function useElementLocale() {
94
- const instance = getCurrentInstance()
95
-
96
- // 嘗試取得外部專案的 i18n(支援 Composition API 模式)
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,優先使用外部的,否則使用內部的
116
- const currentI18n = externalI18n || internalGlobal
117
-
118
- // 返回響應式的 Element Plus locale
119
- return computed(() => {
120
- const locale = currentI18n.locale.value
121
- return locale === 'zh-TW' ? zhTw : enUs
122
- })
123
103
  }
124
104
 
125
105
  /**
@@ -127,34 +107,15 @@ export function useElementLocale() {
127
107
  * 專門用於組件庫內部的 Element Plus 組件
128
108
  */
129
109
  export function useComponentElementLocale() {
130
- const instance = getCurrentInstance()
131
-
132
- // 取得內部 i18n
133
- const internalI18nInstance = getInternalI18n()
134
- const internalGlobal = internalI18nInstance.global as Composer
135
-
136
- // 返回響應式的 Element Plus locale
137
- return computed(() => {
138
- // 每次計算時都重新嘗試取得外部專案的 i18n
139
- let externalI18n: Composer | undefined
140
- try {
141
- const globalProperties = instance?.appContext.config.globalProperties
142
- const externalI18nInstance = globalProperties?.$i18n as I18n | undefined
143
-
144
- // 如果是 I18n 實例,取得其 global 屬性
145
- if (externalI18nInstance && 'global' in externalI18nInstance) {
146
- externalI18n = externalI18nInstance.global as Composer
147
- }
148
- } catch (e) {
149
- // 如果取得失敗,繼續使用內部 i18n
150
- externalI18n = undefined
151
- }
152
-
153
- // 如果存在外部 i18n,優先使用外部的,否則使用內部的
154
- const currentI18n = externalI18n || internalGlobal
155
- const locale = currentI18n.locale.value
156
- return locale === 'zh-TW' ? zhTw : enUs
157
- })
110
+ try {
111
+ const { locale } = useI18n()
112
+ return computed(() => {
113
+ return locale.value === 'zh-TW' ? zhTw : enUs
114
+ })
115
+ } catch (e) {
116
+ // 防呆:預設中文
117
+ return computed(() => zhTw)
118
+ }
158
119
  }
159
120
 
160
121
  // 導出類型