trithuc-mvc-react 2.7.4 → 2.7.6
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 +16 -1
- package/package.json +20 -20
- package/utils/storage.js +60 -2
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.
|
|
3
|
+
"version": "2.7.6",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -13,36 +13,36 @@
|
|
|
13
13
|
},
|
|
14
14
|
"description": "",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@emotion/react": "^11.
|
|
17
|
-
"@emotion/styled": "^11.
|
|
18
|
-
"@hookform/resolvers": "^3.
|
|
19
|
-
"@iconify/react": "^
|
|
20
|
-
"axios": "^1.
|
|
21
|
-
"date-fns": "^
|
|
16
|
+
"@emotion/react": "^11.13.3",
|
|
17
|
+
"@emotion/styled": "^11.13.0",
|
|
18
|
+
"@hookform/resolvers": "^3.9.1",
|
|
19
|
+
"@iconify/react": "^5.0.2",
|
|
20
|
+
"axios": "^1.7.7",
|
|
21
|
+
"date-fns": "^4.1.0",
|
|
22
22
|
"lodash": "^4.17.21",
|
|
23
|
-
"moment": "^2.
|
|
23
|
+
"moment": "^2.30.1",
|
|
24
24
|
"prop-types": "^15.8.1",
|
|
25
|
-
"yup": "^1.
|
|
25
|
+
"yup": "^1.4.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/react": "^18.
|
|
29
|
-
"@types/react-dom": "^18.
|
|
30
|
-
"eslint": "^
|
|
31
|
-
"eslint-plugin-react": "^7.
|
|
32
|
-
"eslint-plugin-react-hooks": "^
|
|
33
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
34
|
-
"react": "^18.
|
|
35
|
-
"react-dom": "^18.
|
|
28
|
+
"@types/react": "^18.3.12",
|
|
29
|
+
"@types/react-dom": "^18.3.1",
|
|
30
|
+
"eslint": "^9.14.0",
|
|
31
|
+
"eslint-plugin-react": "^7.37.2",
|
|
32
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
33
|
+
"eslint-plugin-react-refresh": "^0.4.14",
|
|
34
|
+
"react": "^18.3.1",
|
|
35
|
+
"react-dom": "^18.3.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@mui/
|
|
39
|
-
"@mui/material": "^5.14.
|
|
38
|
+
"@mui/material": "^5.14.17",
|
|
39
|
+
"@mui/icons-material": "^5.14.17",
|
|
40
40
|
"react": ">=16",
|
|
41
41
|
"react-dom": ">=16",
|
|
42
42
|
"react-query": "^3.39.3",
|
|
43
43
|
"react-toastify": "^9.1.3",
|
|
44
44
|
"material-ui-confirm": "^3.0.9",
|
|
45
|
-
"@mui/x-date-pickers": "^6.
|
|
45
|
+
"@mui/x-date-pickers": "^6.20.2",
|
|
46
46
|
"react-hook-form": "^7.45.2"
|
|
47
47
|
}
|
|
48
48
|
}
|
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.
|
|
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
|
+
};
|