trithuc-mvc-react 2.7.4 → 2.7.5

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/api/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { storeGetToken } from "@/utils/storage";
1
+ import { storeGetlanguage, storeGetToken } from "@/utils/storage";
2
2
  import axios from "axios";
3
3
 
4
4
  let baseUrl = "";
@@ -35,6 +35,21 @@ const token = storeGetToken();
35
35
  if (token) {
36
36
  setAuthToken(token);
37
37
  }
38
+ // Sử dụng interceptor để thêm ngôn ngữ vào headers
39
+ api.interceptors.request.use((config) => {
40
+ const token = storeGetToken();
41
+ const language = storeGetlanguage(); // Lấy ngôn ngữ từ local storage
42
+
43
+ if (token) {
44
+ config.headers["Authorization"] = `Bearer ${token}`; // Gán token vào headers
45
+ }
46
+
47
+ if (language) {
48
+ config.headers["Accept-Language"] = language; // Gán ngôn ngữ vào headers
49
+ }
50
+
51
+ return config;
52
+ });
38
53
  export default api;
39
54
 
40
55
  export const getDatasFromTable = async ({ tableName, page, pageSize, data }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "2.7.4",
3
+ "version": "2.7.5",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/storage.js CHANGED
@@ -1,32 +1,44 @@
1
1
  import CryptoJS from "crypto-js";
2
+ import moment from "moment";
2
3
 
3
4
  // Khóa bí mật để mã hóa và giải mã MD5 https://zozo.vn/ws/tools/md5encode
4
5
  const secretKey = "b0dc70c6a34c0555ac9c63907617f5a5"; // Bạn nên lưu trữ key này an toàn
5
6
 
6
7
  // Hàm mã hóa dữ liệu
7
8
  const encryptData = (data) => {
9
+ if (!data) {
10
+ return null;
11
+ }
12
+
8
13
  try {
9
14
  return CryptoJS.AES.encrypt(JSON.stringify(data), secretKey).toString();
10
15
  } catch (error) {
11
16
  console.log("Error encrypting data:", error);
17
+ return null;
12
18
  }
13
19
  };
14
20
 
15
- // Hàm giải mã dữ liệu
16
21
  const decryptData = (ciphertext) => {
22
+ if (!ciphertext) {
23
+ return null;
24
+ }
25
+
17
26
  try {
18
27
  const bytes = CryptoJS.AES.decrypt(ciphertext, secretKey);
19
28
  const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
29
+
20
30
  if (!decryptedData) {
21
31
  throw new Error("Decrypted data is null or invalid.");
22
32
  }
33
+
23
34
  return JSON.parse(decryptedData);
24
35
  } catch (error) {
25
- console.log("Error decrypting data:", error);
36
+ console.error("Error decrypting data:", error, "Ciphertext:", ciphertext);
26
37
  return null;
27
38
  }
28
39
  };
29
40
 
41
+
30
42
  export const storeUserData = (data) => {
31
43
  if (!data) return;
32
44
 
@@ -118,3 +130,49 @@ export const storeGetThamSoHeThong = (TenThamSo) => {
118
130
  const getCurrentInfor =decryptData(encryptedData) || {};
119
131
  return getCurrentInfor?.ThamSoHeThong?.find((item) => item.TenThamSo === TenThamSo)?.GiaTri || "";
120
132
  };
133
+ export const storeGetcolor= () => {
134
+ const encryptedData = localStorage.getItem("color");
135
+ if (!encryptedData) return "defaultColor";
136
+ return decryptData(encryptedData);
137
+ };
138
+ export const storeSetcolor = (data) => {
139
+ if (!data) return;
140
+ const encryptedData = encryptData(data);
141
+ localStorage.setItem("color",encryptedData);
142
+ };
143
+ export const storeGetlanguage = () => {
144
+ const encryptedData = localStorage.getItem("language");
145
+ if (!encryptedData) return "vi";
146
+ return decryptData(encryptedData);
147
+ };
148
+ export const storeSetlanguage = (data) => {
149
+ if (!data) return;
150
+ const encryptedData = encryptData(data);
151
+ localStorage.setItem("language",encryptedData);
152
+ };
153
+ export const storeGetlanguageVersion = () => {
154
+ const encryptedData = localStorage.getItem("languageVersion");
155
+ if (!encryptedData) return moment(Date.now()).format("DD/MM/YYYY HH:mm:ss");
156
+ return decryptData(encryptedData);
157
+ };
158
+ export const storeSetlanguageVersion = (data) => {
159
+ if (!data) return;
160
+ const encryptedData = encryptData(data);
161
+ localStorage.setItem("languageVersion",encryptedData);
162
+ };
163
+ export const storeGetlanguageData = () => {
164
+ const encryptedData = localStorage.getItem("languageData");
165
+ if (!encryptedData) return null;
166
+ return decryptData(encryptedData);
167
+ };
168
+ export const storeSetlanguageData = (data) => {
169
+ if (!data) return;
170
+ const encryptedData = encryptData(data);
171
+ localStorage.setItem("languageData",encryptedData);
172
+ };
173
+ export const storeGetlanguageSystemKey = (TypeKey,SystemKey,TypeLanguage) => {
174
+ const encryptedData = localStorage.getItem("languageData");
175
+ if (!encryptedData) return null;
176
+ const languageData =decryptData(encryptedData) || {};
177
+ return languageData?.find((item) => item.TypeKey === TypeKey && item.SystemKey === SystemKey && item.TypeLanguage === TypeLanguage)?.Description || "";
178
+ };