trithuc-mvc-react 2.6.3 → 2.6.4
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 +56 -21
- package/package.json +1 -1
package/api/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import axios from "axios";
|
|
|
3
3
|
let baseUrl = "";
|
|
4
4
|
let apiUrl = "";
|
|
5
5
|
|
|
6
|
-
export function configure({ customBaseUrl,customApiUrl }) {
|
|
6
|
+
export function configure({ customBaseUrl, customApiUrl }) {
|
|
7
7
|
if (customBaseUrl) {
|
|
8
8
|
baseUrl = customBaseUrl;
|
|
9
9
|
apiUrl = customApiUrl;
|
|
@@ -66,7 +66,7 @@ export const getDatasFromTable = async ({ tableName, page, pageSize, data }) =>
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
export const getDataFromTable = async ({ tableName, id }) => {
|
|
69
|
-
try {
|
|
69
|
+
try {
|
|
70
70
|
if (!apiUrl) {
|
|
71
71
|
const url = `${getBaseUrl()}/Admin/${tableName}/GetDetail`;
|
|
72
72
|
const res = await api.get(url, {
|
|
@@ -75,7 +75,7 @@ export const getDataFromTable = async ({ tableName, id }) => {
|
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
return res.data;
|
|
78
|
-
}else{
|
|
78
|
+
} else {
|
|
79
79
|
const url = `${getBaseUrl()}/${apiUrl}/${tableName}/${id}`;
|
|
80
80
|
const res = await api.get(url, {
|
|
81
81
|
params: {
|
|
@@ -103,7 +103,7 @@ export const deleteDataFromTable = async ({ tableName, id }) => {
|
|
|
103
103
|
const res = await api.delete(`${getBaseUrl()}/${apiUrl}/${tableName}`, {
|
|
104
104
|
data: ids, // Truyền ids như là dữ liệu của body
|
|
105
105
|
headers: {
|
|
106
|
-
|
|
106
|
+
"Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
109
|
return res.data;
|
|
@@ -119,7 +119,7 @@ export const deleteMultipleDataFromTable = async ({ tableName, ids }) => {
|
|
|
119
119
|
const res = await api.delete(`${getBaseUrl()}/${apiUrl}/${tableName}`, {
|
|
120
120
|
data: ids, // Truyền ids như là dữ liệu của body
|
|
121
121
|
headers: {
|
|
122
|
-
|
|
122
|
+
"Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
return res.data;
|
|
@@ -144,26 +144,61 @@ export const saveDataToTable = async ({ tableName, data }) => {
|
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
export const changeStatusDataToTable = async ({ tableName, id }) => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
if (!apiUrl) {
|
|
148
|
+
const res = await api.post(`${getBaseUrl()}/Admin/${tableName}/ChangeStatus`, {
|
|
149
|
+
id
|
|
150
|
+
});
|
|
151
|
+
return res.data;
|
|
152
|
+
} else {
|
|
153
|
+
const res = await api.post(`${getBaseUrl()}/${apiUrl}/${tableName}/ChangeStatus`, id, {
|
|
154
|
+
headers: {
|
|
155
|
+
"Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return res.data;
|
|
159
|
+
}
|
|
151
160
|
};
|
|
152
161
|
|
|
153
162
|
export const exportExcel = async ({ tableName, data }) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
if (!apiUrl) {
|
|
164
|
+
const res = await api.get(`${getBaseUrl()}/Admin/${tableName}/ExportData`, {
|
|
165
|
+
params: {
|
|
166
|
+
json: JSON.stringify(data)
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return res.data;
|
|
170
|
+
} else {
|
|
171
|
+
const res = await api.get(
|
|
172
|
+
`${getBaseUrl()}/${apiUrl}/${tableName}/ExportData`,
|
|
173
|
+
{
|
|
174
|
+
params: {
|
|
175
|
+
...data
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
headers: {
|
|
180
|
+
"Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
return res.data;
|
|
185
|
+
}
|
|
160
186
|
};
|
|
161
187
|
|
|
162
188
|
export const uploadFile = async (formData) => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
189
|
+
if (!apiUrl) {
|
|
190
|
+
const res = await api.post(`${getBaseUrl()}/Handler/fileUploader.ashx`, formData, {
|
|
191
|
+
headers: {
|
|
192
|
+
"Content-Type": "multipart/form-data"
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return res.data;
|
|
196
|
+
} else {
|
|
197
|
+
const res = await api.post(`${getBaseUrl()}/${apiUrl}/FileUploader`, formData, {
|
|
198
|
+
headers: {
|
|
199
|
+
"Content-Type": "multipart/form-data"
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return res.data;
|
|
203
|
+
}
|
|
169
204
|
};
|