mooho-base-admin-plus 0.4.1 → 0.4.2

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mooho-base-admin-plus",
3
3
  "description": "MOOHO basic framework for admin by Vue3",
4
- "version": "0.4.1",
4
+ "version": "0.4.2",
5
5
  "author": "jinyifan <jinyifan@mooho.com.cn>",
6
6
  "dotnetVersion": "1.4.0",
7
7
  "license": "MIT",
package/src/i18n/index.js CHANGED
@@ -1,9 +1,4 @@
1
1
  import { createI18n } from 'vue-i18n/index';
2
- import Setting from '../setting';
3
- import util from '../libs/util';
4
- import { pathInit } from '../store/modules/admin/modules/db';
5
-
6
- const savedLocaleKey = 'i18n-locale';
7
2
  //import store from '../store/index';
8
3
  //import messages from './locale';
9
4
 
@@ -11,42 +6,10 @@ const savedLocaleKey = 'i18n-locale';
11
6
 
12
7
  //const locale = store.state.admin.i18n.locale;
13
8
 
14
- let locale;
15
-
16
- const db = util.db.get(
17
- pathInit({
18
- dbName: 'database',
19
- path: '',
20
- user: false,
21
- defaultValue: {}
22
- })
23
- );
24
-
25
- const savedLocale = db.get(savedLocaleKey).value();
26
-
27
- console.log('savedLocale', savedLocale);
28
-
29
- // 先判断本地存储是否已有语言选择
30
- if (savedLocale) {
31
- locale = savedLocale;
32
- } else {
33
- // 判断是否开启自动识别语言
34
- if (Setting.i18n.auto) {
35
- // 如果自动识别的语言,本地没有该语言包,则设置为默认语言
36
- const navLang = navigator.language;
37
- locale = navLang;
38
- } else {
39
- locale = Setting.i18n.default;
40
- }
41
-
42
- // 将初次的语言保存在本地
43
- db.set(savedLocaleKey, locale).write();
44
- }
45
-
46
9
  export default createI18n({
47
10
  allowComposition: true,
48
11
  globalInjection: true,
49
- legacy: false,
50
- locale
12
+ legacy: false
13
+ // locale,
51
14
  // messages
52
15
  });
package/src/index.js CHANGED
@@ -163,9 +163,9 @@ Object.keys(files).forEach(key => {
163
163
  // 第一次进入时,取菜单数据用于更新
164
164
  let isFirstRouteChange = true;
165
165
 
166
- const created = async () => {
166
+ const created = async app => {
167
167
  // 加载多语言
168
- await store.dispatch('admin/i18n/load');
168
+ await store.dispatch('admin/i18n/load', app);
169
169
  // 初始化动态路由
170
170
  //let dynamicRoutes = await dynamicRouter.init(router, pages, layout);
171
171
  // 处理路由 得到每一级的路由设置
@@ -50,7 +50,9 @@ export default {
50
50
  * @description 加载语言
51
51
  * @param {Object} state vuex state
52
52
  */
53
- async load({ state }) {
53
+ async load({ state }, app) {
54
+ let locale;
55
+
54
56
  const db = util.db.get(
55
57
  pathInit({
56
58
  dbName: 'database',
@@ -60,7 +62,30 @@ export default {
60
62
  })
61
63
  );
62
64
 
63
- state.locale = db.get(savedLocaleKey).value();
65
+ const savedLocale = db.get(savedLocaleKey).value();
66
+
67
+ // 先判断本地存储是否已有语言选择
68
+ if (savedLocale) {
69
+ locale = savedLocale;
70
+ } else {
71
+ // 判断是否开启自动识别语言
72
+ if (Setting.i18n.auto) {
73
+ // 如果自动识别的语言,本地没有该语言包,则设置为默认语言
74
+ const navLang = navigator.language;
75
+ if (state.languages[navLang]) {
76
+ locale = navLang;
77
+ } else {
78
+ locale = Setting.i18n.default;
79
+ }
80
+ } else {
81
+ locale = Setting.i18n.default;
82
+ }
83
+
84
+ // 将初次的语言保存在本地
85
+ db.set(savedLocaleKey, locale).write();
86
+ }
87
+ state.locale = locale;
88
+ app.config.globalProperties.$i18n.locale = locale;
64
89
 
65
90
  // 导入 View UI Plus 语言包
66
91
  const ViewUIPlusLocale = import.meta.globEager('../../../../i18n/locale/*-*.js');
package/test/main.js CHANGED
@@ -33,7 +33,7 @@ const app = createApp({
33
33
  // mixins: [mixinApp],
34
34
  render: () => h(App),
35
35
  created() {
36
- created();
36
+ created(app);
37
37
 
38
38
  // 将根实例存全局,可在特殊场景下调用
39
39
  if (window) {