icve-sso 0.0.13 → 0.0.14

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.
@@ -71042,13 +71042,9 @@ const messages = {
71042
71042
  },
71043
71043
  };
71044
71044
 
71045
- // 创建一个 i18n 实例(不在这里使用 Vue.use,在 install 方法中处理)
71045
+ // 创建一个 i18n 实例
71046
+ // 注意:Vue.use(VueI18n) 应该在调用此函数之前已经执行
71046
71047
  const createI18n = (Vue) => {
71047
- // 如果还没有安装 VueI18n,则安装
71048
- if (!Vue.prototype.$t) {
71049
- Vue.use(vue_i18n_esm);
71050
- }
71051
-
71052
71048
  const i18n = new vue_i18n_esm({
71053
71049
  locale: localStorage.getItem('language') || 'cn',
71054
71050
  messages,
@@ -71063,6 +71059,7 @@ const createI18n = (Vue) => {
71063
71059
 
71064
71060
 
71065
71061
 
71062
+
71066
71063
  // 导出组件
71067
71064
 
71068
71065
 
@@ -71076,37 +71073,83 @@ let i18nInstance = null;
71076
71073
  Vue.component('userCenterCompleteInformation', userCenterCompleteInformation);
71077
71074
  Vue.component('userCenterLogin', userCenterLogin);
71078
71075
 
71079
- // 如果主应用已经安装了 i18n,则使用主应用的 i18n
71080
- // 否则创建并注册组件库自己的 i18n 实例
71081
- if (Vue.prototype.$t && Vue.prototype.$i18n) {
71082
- // 主应用已经有 i18n,无需额外处理
71083
- // 组件可以直接使用 this.$t this.$i18n
71084
- i18nInstance = Vue.prototype.$i18n;
71076
+ // 检查主应用是否已经配置了 i18n
71077
+ // 方式1:检查 $t 方法是否存在(VueI18n 安装后会自动添加)
71078
+ // 方式2:检查 $i18n getter 是否存在(更可靠的方式)
71079
+ const hasI18nMethod = Vue.prototype.$t && typeof Vue.prototype.$t === 'function';
71080
+ const hasI18nGetter = Object.getOwnPropertyDescriptor(Vue.prototype, '$i18n') !== undefined;
71081
+
71082
+ // 如果主应用已经安装了 i18n,则完全使用主应用的 i18n,不做任何操作
71083
+ if (hasI18nMethod || hasI18nGetter) {
71084
+ // 主应用已经有 i18n,组件可以直接使用 this.$t 和 this.$i18n
71085
+ // 不需要创建新的 i18n 实例,避免冲突
71085
71086
  return;
71086
71087
  }
71087
71088
 
71088
- // 创建 i18n 实例
71089
+ // 确保 VueI18n 插件已安装(如果还没有安装的话)
71090
+ // 注意:Vue.use() 是幂等的,多次调用不会重复安装
71091
+ Vue.use(vue_i18n_esm);
71092
+
71093
+ // 创建组件库自己的 i18n 实例
71089
71094
  i18nInstance = utils_i18n(Vue);
71095
+
71090
71096
  // 通过 mixin 确保所有组件实例都能访问 i18n
71091
- // VueI18n $i18n getter 会查找组件实例的 _i18n 属性
71097
+ // 注意:使用 beforeCreate 钩子,并且检查 _i18n 是否已存在
71098
+ // 这样可以避免与主应用或其他插件的 i18n 冲突
71092
71099
  Vue.mixin({
71093
71100
  beforeCreate() {
71094
- // 为所有组件(包括根实例)设置 _i18n
71095
- // VueI18n 会通过 $i18n getter 访问这个属性
71101
+ // 只有在组件实例还没有 _i18n 时才设置
71102
+ // 这样可以确保不会覆盖主应用或其他插件已经设置的 i18n
71096
71103
  if (!this._i18n) {
71097
71104
  this._i18n = i18nInstance;
71098
71105
  }
71099
71106
  },
71100
71107
  });
71101
71108
 
71102
- // 如果 $t 方法不存在,则定义它
71103
- if (!Vue.prototype.$t) {
71104
- Vue.prototype.$t = function (key, values) {
71105
- const i18n = this.$i18n || (this.$root && this.$root.$i18n) || i18nInstance;
71106
- return i18n ? i18n.t(key, values) : key;
71107
- };
71109
+ // 确保 $i18n getter 可用
71110
+ // 如果 VueI18n 已经添加了 $i18n getter,我们不覆盖它
71111
+ // 如果还没有,我们手动添加一个
71112
+ const i18nDescriptor = Object.getOwnPropertyDescriptor(Vue.prototype, '$i18n');
71113
+ if (!i18nDescriptor) {
71114
+ Object.defineProperty(Vue.prototype, '$i18n', {
71115
+ get() {
71116
+ // 优先使用组件实例的 _i18n,然后是根实例的 _i18n,最后才是我们的 i18n 实例
71117
+ return this._i18n || (this.$root && this.$root._i18n) || i18nInstance;
71118
+ },
71119
+ configurable: true,
71120
+ });
71108
71121
  }
71109
71122
 
71123
+ // 确保所有 i18n 方法都可用
71124
+ // 这些方法会智能地使用组件实例的 i18n(优先使用主应用的 i18n)
71125
+ // 如果组件实例没有 i18n,则回退到我们的 i18n 实例
71126
+ Vue.prototype.$t = function (key, ...args) {
71127
+ // 优先使用组件实例的 $i18n(可能是主应用的 i18n)
71128
+ // 如果组件实例没有,则使用根实例的 $i18n,最后才使用我们的 i18n 实例
71129
+ const i18n = this.$i18n || (this.$root && this.$root.$i18n) || i18nInstance;
71130
+ return i18n && i18n.t ? i18n.t(key, ...args) : key;
71131
+ };
71132
+
71133
+ Vue.prototype.$tc = function (key, choice, ...args) {
71134
+ const i18n = this.$i18n || (this.$root && this.$root.$i18n) || i18nInstance;
71135
+ return i18n && i18n.tc ? i18n.tc(key, choice, ...args) : key;
71136
+ };
71137
+
71138
+ Vue.prototype.$te = function (key, locale) {
71139
+ const i18n = this.$i18n || (this.$root && this.$root.$i18n) || i18nInstance;
71140
+ return i18n && i18n.te ? i18n.te(key, locale) : false;
71141
+ };
71142
+
71143
+ Vue.prototype.$d = function (value, ...args) {
71144
+ const i18n = this.$i18n || (this.$root && this.$root.$i18n) || i18nInstance;
71145
+ return i18n && i18n.d ? i18n.d(value, ...args) : value;
71146
+ };
71147
+
71148
+ Vue.prototype.$n = function (value, ...args) {
71149
+ const i18n = this.$i18n || (this.$root && this.$root.$i18n) || i18nInstance;
71150
+ return i18n && i18n.n ? i18n.n(value, ...args) : value;
71151
+ };
71152
+
71110
71153
  },
71111
71154
  });
71112
71155