Explorar o código

feat: 由于版本升级 vue-i18n 调用出错问题修复

lanceJiang hai 1 ano
pai
achega
e3fc85cbb1
Modificáronse 2 ficheiros con 14 adicións e 3 borrados
  1. 3 3
      src/components/Table/hooks/useColumns.tsx
  2. 11 0
      src/utils/index.ts

+ 3 - 3
src/components/Table/hooks/useColumns.tsx

@@ -1,13 +1,13 @@
 import type { LeTableColumnProps, LeTableOptions, LeTableProps, LeColumnSlots } from '../index.d'
 import { ComputedRef, Slots, computed, Ref, unref, watch, nextTick } from 'vue'
-import { useI18n } from 'vue-i18n'
-import { getPropValue, $log } from '@/utils'
+// import { useI18n } from 'vue-i18n'
+import { getPropValue, t, $log } from '@/utils'
 // import { cloneDeep, isEqual } from 'lodash-es'
 
 /**针对 header 展示添加默认的slot*/
 const slotHeaderDefault = function (titleHelp: any = {}, props: any) {
 	// console.error(props, 'props.column...', titleHelp)
-	const { t } = useI18n()
+	// const { t } = useI18n()
 	const { t_label, label } = props.column || {}
 	const label_ = t_label ? t(t_label) : label
 	// const { titleHelp, label } = props.column

+ 11 - 0
src/utils/index.ts

@@ -3,6 +3,17 @@ import { ElMessage } from 'element-plus'
 // vue Storage 使用
 export { ls } from './vueStorage'
 import { get, set } from 'lodash-unified'
+import i18n from '@/lang/index'
+
+// 多语言翻译
+export const t = (key: string, ...args: any[]) => {
+	if (!i18n) return key
+	const hasKey = i18n.global.te(key)
+	// eslint-disable-next-line
+	// @ts-ignore
+	return hasKey ? i18n.global.t(key, ...args) : key
+}
+
 export type Arrayable<T> = T | T[]
 export const getPropValue = <T = any>(obj: Record<string, any>, path: Arrayable<string>, defaultValue?: any): { value: T } => {
 	return {