gc_i18n 1.0.1 → 1.0.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,6 +1,6 @@
1
1
  {
2
2
  "name": "gc_i18n",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "gc_i18n": {
5
5
  "appCode": "TEST"
6
6
  },
@@ -10,7 +10,8 @@
10
10
  "scripts": {
11
11
  "dev": "vite",
12
12
  "build": "vite build",
13
- "preview": "vite preview"
13
+ "preview": "vite preview",
14
+ "cnpm": "cnpm sync gc_i18n"
14
15
  },
15
16
  "dependencies": {
16
17
  "axios": "^1.7.9",
@@ -47,7 +47,12 @@ export default {
47
47
  return arr;
48
48
  }
49
49
  },
50
- props: { appCode: String, name: String, setLanguage: Function },
50
+ props: {
51
+ appCode: String,
52
+ name: String,
53
+ setLanguage: Function,
54
+ token: String
55
+ },
51
56
  methods: {
52
57
  closeModal() {
53
58
  this.searchText = "";
@@ -92,11 +97,14 @@ export default {
92
97
  const diff = this.findShallowStringDiff(value, original);
93
98
  arr = _.concat(arr, diff);
94
99
  }
95
- const res = await saveTranslate({
96
- appCode: this.appCode,
97
- language: this.language,
98
- data: arr
99
- });
100
+ const res = await saveTranslate(
101
+ {
102
+ appCode: this.appCode,
103
+ language: this.language,
104
+ data: arr
105
+ },
106
+ this.token
107
+ );
100
108
  if (res && res.result === 0) {
101
109
  Message.success(msg ? msg : res.msg);
102
110
  // 更新到本地缓存
@@ -123,14 +131,14 @@ export default {
123
131
  pageSize: 10,
124
132
  ...data
125
133
  };
126
- const res = await getAllTranslate(options);
134
+ const res = await getAllTranslate(options, this.token);
127
135
  if (res) {
128
136
  this.initialData = _.cloneDeep(res.retVal);
129
137
  this.data = res.retVal;
130
138
  }
131
139
  },
132
140
  async init() {
133
- const res = await getLanguages();
141
+ const res = await getLanguages(this.token);
134
142
  if (res && res.result == 0) {
135
143
  this.languages = res.retVal;
136
144
  this.search();
package/packages/index.js CHANGED
@@ -9,14 +9,16 @@ import { getTranslate } from "./libs/service";
9
9
  import { convertArrayToObject } from "./libs/utils";
10
10
  import "./libs/http";
11
11
  import _ from "lodash-es";
12
+ import store2 from "store2";
12
13
  export default class I18n {
13
14
  constructor(options = {}) {
14
- const { router } = options;
15
- this.appCode = options.appCode;
15
+ const { router, appCode, messages, token } = options;
16
+ this.token = token || store2.get("token");
17
+ this.appCode = appCode;
16
18
  this.router = router;
17
19
  this.locale = navigator.language || "zh-CN";
18
20
  this.modalLoad = false;
19
- this.messages = options.messages || {};
21
+ this.messages = messages || {};
20
22
  this.i18n = createI18n({
21
23
  locale: "zh-CN",
22
24
  allowComposition: true,
@@ -60,7 +62,8 @@ export default class I18n {
60
62
  };
61
63
 
62
64
  router.afterEach((to, from) => {
63
- const { language } = to.query;
65
+ const { language, token } = to.query;
66
+ token && this.setToken(token);
64
67
  this.setLanguage(language);
65
68
 
66
69
  nextTick(() => {
@@ -72,11 +75,15 @@ export default class I18n {
72
75
  });
73
76
  });
74
77
  }
78
+ setToken(token) {
79
+ this.token = token;
80
+ }
75
81
  async setLanguage(language = "zh-CN") {
76
82
  this.locale = language;
77
83
  const res = await getTranslate({
78
84
  appCode: this.appCode,
79
- language
85
+ language,
86
+ token: this.token
80
87
  });
81
88
 
82
89
  if (res) {
@@ -93,6 +100,7 @@ export default class I18n {
93
100
  // 创建 config 组件的实例
94
101
  this.configInstance = createApp(configVue, {
95
102
  appCode: this.appCode,
103
+ token: this.token,
96
104
  setLanguage: this.setLanguage.bind(this),
97
105
  name
98
106
  })
@@ -11,11 +11,6 @@ axios.defaults.timeout = 60000;
11
11
 
12
12
  axios.interceptors.request.use(
13
13
  (config) => {
14
- //这边可根据自己的需求设置headers,我司采用basic基本认证
15
- const authToken = localStorage.getItem("token");
16
- if (!_.isEmpty(authToken)) {
17
- config.headers["Authorization"] = authToken;
18
- }
19
14
  config.headers["Content-Type"] = "application/json";
20
15
  return config;
21
16
  },
@@ -4,12 +4,10 @@ import _ from "lodash-es";
4
4
  import { mergeArraysByKey } from "./utils";
5
5
  export const service = "https://test.ihotel.cn";
6
6
 
7
- const Authorization =
8
- "eyJhbGciOiJIUzUxMiJ9.eyJkZXZpY2VUeXBlIjoiQ09NUFVURVIiLCJtYWluQXBwQ29kZSI6IlNTTyIsIm9yZ0NvZGUiOiJHQ0JaRyIsInVjU2VydmVyVXJsIjoiaHR0cHM6Ly90ZXN0Lmlob3RlbC5jbi91Yy13ZWIvIiwiYXBwQ29kZSI6IlNTTyIsInVzZXJUeXBlIjoiTk9STUFMIiwibG9naW5BdCI6MTczODczNTczOTAwMCwicHJpbmNpcGFsVXNlckNvZGUiOiJHQ0JaR19BRE1JTiIsImV4cCI6MzI1MDM2NTEyMDAsInVzZXJDb2RlIjoiR0NCWkdfQURNSU4iLCJzc28iOiJTU09fU0VSVkVSIn0.KQt1YbUdJ7DfqrfXEVYT0Ux-7Zlo2GQBiIoq0rxK0cv1LHqOOMtBkv8kmChM6VavtdnlyXM2GkW6YMvIIHvu0Q";
9
- export const getLanguages = async () => {
7
+ export const getLanguages = async (token) => {
10
8
  return axios.get(service + "/i18n-web/sysoption/getsupportedlangs", {
11
9
  headers: {
12
- Authorization
10
+ Authorization: token
13
11
  }
14
12
  });
15
13
  };
@@ -17,7 +15,8 @@ export const fetchTranslate = async ({
17
15
  appCode,
18
16
  language = "zh-CN",
19
17
  page,
20
- lastPullDate
18
+ lastPullDate,
19
+ token
21
20
  }) => {
22
21
  return new Promise(async (resolve, reject) => {
23
22
  const serverURI = service + "/i18n-web/kv_translate/kv_translates";
@@ -30,7 +29,8 @@ export const fetchTranslate = async ({
30
29
  headers: {
31
30
  appCode,
32
31
  page,
33
- language
32
+ language,
33
+ Authorization: token
34
34
  }
35
35
  });
36
36
  if (res && res.result == 0) {
@@ -41,29 +41,30 @@ export const fetchTranslate = async ({
41
41
  });
42
42
  };
43
43
 
44
- export const getAllTranslate = async (data) => {
44
+ export const getAllTranslate = async (data, token) => {
45
45
  return axios({
46
46
  url: service + "/i18n-web/kv_translate/kv_translates",
47
47
  method: "POST",
48
48
  data,
49
- headers: { token: Authorization }
49
+ headers: { token }
50
50
  });
51
51
  };
52
- export const saveTranslate = async (data) => {
52
+ export const saveTranslate = async (data, token) => {
53
53
  return axios({
54
54
  url: service + "/i18n-web/kv_translate/batch",
55
55
  method: "POST",
56
56
  data,
57
- headers: { token: Authorization }
57
+ headers: { token }
58
58
  });
59
59
  };
60
- export const getTranslate = async ({ appCode, language = "zh-CN" }) => {
60
+ export const getTranslate = async ({ appCode, language = "zh-CN", token }) => {
61
61
  return new Promise(async (resolve, reject) => {
62
62
  // const appCodeStore = i18nStore.get(appCode);
63
63
  const languageStore = store2.namespace(`i18n_${appCode}`);
64
64
  const options = {
65
65
  appCode,
66
- language
66
+ language,
67
+ token
67
68
  };
68
69
  const lastData = languageStore.get(language);
69
70