trithuc-mvc-react 1.6.11 → 1.6.13
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,6 +1,21 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
let baseUrl = "";
|
|
4
|
+
|
|
5
|
+
export function configure({ customBaseUrl }) {
|
|
6
|
+
if (customBaseUrl) {
|
|
7
|
+
baseUrl = customBaseUrl;
|
|
8
|
+
} else {
|
|
9
|
+
console.warn("baseUrl chưa được định cấu hình. Sử dụng giá trị mặc định.");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getBaseUrl() {
|
|
14
|
+
return baseUrl;
|
|
15
|
+
}
|
|
16
|
+
|
|
2
17
|
const api = axios.create({
|
|
3
|
-
baseURL:
|
|
18
|
+
baseURL: getBaseUrl()??'/',
|
|
4
19
|
transitional: {
|
|
5
20
|
silentJSONParsing: false
|
|
6
21
|
},
|
|
@@ -9,7 +24,7 @@ const api = axios.create({
|
|
|
9
24
|
export default api;
|
|
10
25
|
|
|
11
26
|
export const getDatasFromTable = async ({ tableName, page, pageSize, data }) => {
|
|
12
|
-
const res = await api.get(
|
|
27
|
+
const res = await api.get(`${getBaseUrl()}/Admin/${tableName}/LoadData`, {
|
|
13
28
|
params: {
|
|
14
29
|
json: JSON.stringify(data),
|
|
15
30
|
page,
|
|
@@ -20,7 +35,7 @@ export const getDatasFromTable = async ({ tableName, page, pageSize, data }) =>
|
|
|
20
35
|
};
|
|
21
36
|
|
|
22
37
|
export const getDataFromTable = async ({ tableName, id }) => {
|
|
23
|
-
const res = await api.get(
|
|
38
|
+
const res = await api.get(`${getBaseUrl()}/Admin/${tableName}/GetDetail`, {
|
|
24
39
|
params: {
|
|
25
40
|
id
|
|
26
41
|
}
|
|
@@ -28,32 +43,32 @@ export const getDataFromTable = async ({ tableName, id }) => {
|
|
|
28
43
|
return res.data;
|
|
29
44
|
};
|
|
30
45
|
export const deleteDataFromTable = async ({ tableName, id }) => {
|
|
31
|
-
const res = await api.post(
|
|
46
|
+
const res = await api.post(`${getBaseUrl()}/Admin/${tableName}/Delete`, {
|
|
32
47
|
id
|
|
33
48
|
});
|
|
34
49
|
return res.data;
|
|
35
50
|
};
|
|
36
51
|
export const deleteMultipleDataFromTable = async ({ tableName, ids }) => {
|
|
37
|
-
const res = await api.post(
|
|
52
|
+
const res = await api.post(`${getBaseUrl()}/Admin/${tableName}/DeleteMulti`, {
|
|
38
53
|
ids
|
|
39
54
|
});
|
|
40
55
|
return res.data;
|
|
41
56
|
};
|
|
42
57
|
export const saveDataToTable = async ({ tableName, data }) => {
|
|
43
|
-
const res = await api.post(
|
|
58
|
+
const res = await api.post(`${getBaseUrl()}/Admin/${tableName}/SaveData`, {
|
|
44
59
|
json: JSON.stringify({ ...data })
|
|
45
60
|
});
|
|
46
61
|
return res.data;
|
|
47
62
|
};
|
|
48
63
|
export const changeStatusDataToTable = async ({ tableName, id }) => {
|
|
49
|
-
const res = await api.post(
|
|
64
|
+
const res = await api.post(`${getBaseUrl()}/Admin/${tableName}/ChangeStatus`, {
|
|
50
65
|
id
|
|
51
66
|
});
|
|
52
67
|
return res.data;
|
|
53
68
|
};
|
|
54
69
|
|
|
55
70
|
export const exportExcel = async ({ tableName,data }) => {
|
|
56
|
-
const res = await api.get(
|
|
71
|
+
const res = await api.get(`${getBaseUrl()}/Admin/${tableName}/ExportData`,{
|
|
57
72
|
params: {
|
|
58
73
|
json: JSON.stringify(data),
|
|
59
74
|
}
|
|
@@ -62,7 +77,7 @@ export const exportExcel = async ({ tableName,data }) => {
|
|
|
62
77
|
};
|
|
63
78
|
|
|
64
79
|
export const uploadFile = async (formData) => {
|
|
65
|
-
const res = await api.post(
|
|
80
|
+
const res = await api.post(`${getBaseUrl()}/Handler/fileUploader.ashx`, formData, {
|
|
66
81
|
headers: {
|
|
67
82
|
"Content-Type": "multipart/form-data"
|
|
68
83
|
}
|
|
@@ -28,7 +28,7 @@ function EditorForm({ fields, submitRef }) {
|
|
|
28
28
|
if (selectedEditItem) {
|
|
29
29
|
setValue("Id", selectedEditItem.Id);
|
|
30
30
|
|
|
31
|
-
fields.forEach(({ field, onChange, type, keyValue, keyValueLabel, defaultValue }) => {
|
|
31
|
+
fields.forEach(({ field, onChange, type, keyValue, keyValueLabel, defaultValue, }) => {
|
|
32
32
|
if (type == "autocomplete") {
|
|
33
33
|
onChange?.({
|
|
34
34
|
[keyValue]: selectedEditItem[field]
|
|
@@ -54,10 +54,17 @@ function EditorForm({ fields, submitRef }) {
|
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
} else {
|
|
57
|
-
fields.forEach(({ field, defaultValue, type }) => {
|
|
57
|
+
fields.forEach(({ field, defaultValue, type, keyValue, onChange }) => {
|
|
58
|
+
if (type == "autocomplete" && defaultValue) {
|
|
59
|
+
onChange?.({
|
|
60
|
+
[keyValue]: defaultValue
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
58
64
|
if (type === "switch" && defaultValue === undefined) {
|
|
59
65
|
methods.setValue(field, true);
|
|
60
66
|
} else {
|
|
67
|
+
|
|
61
68
|
methods.setValue(field, defaultValue);
|
|
62
69
|
}
|
|
63
70
|
});
|