trithuc-mvc-react 2.6.3 → 2.6.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 +56 -21
- package/components/DataManagement/index.jsx +18 -2
- 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
|
};
|
|
@@ -37,6 +37,7 @@ DataManagement.propTypes = {
|
|
|
37
37
|
disableStatus: PropTypes.bool,
|
|
38
38
|
disableAdd: PropTypes.bool,
|
|
39
39
|
disableCellThaoTac: PropTypes.bool,
|
|
40
|
+
reserPage: PropTypes.string,
|
|
40
41
|
statusKey: PropTypes.string,
|
|
41
42
|
tableActions: PropTypes.array,
|
|
42
43
|
disableEditor: PropTypes.bool,
|
|
@@ -52,6 +53,7 @@ const getDefaultValues = (filters = []) => {
|
|
|
52
53
|
return defaultValues;
|
|
53
54
|
};
|
|
54
55
|
function DataManagement({
|
|
56
|
+
reserPage = false,
|
|
55
57
|
sttLuyKe = false,
|
|
56
58
|
columns = [],
|
|
57
59
|
title,
|
|
@@ -87,7 +89,7 @@ function DataManagement({
|
|
|
87
89
|
const [selectedEditItem, setSelectedEditItem] = useState(null);
|
|
88
90
|
const [openViewDialog, setOpenViewDialog] = useState(false);
|
|
89
91
|
|
|
90
|
-
const { canCreate } = usePermission(apiUrl?apiUrl:tableName);
|
|
92
|
+
const { canCreate } = usePermission(apiUrl ? apiUrl : tableName);
|
|
91
93
|
const { defaults, filters } = useMemo(() => {
|
|
92
94
|
const filters = tableFilters.filter(({ type }) => type !== "default");
|
|
93
95
|
const defaultFilters = tableFilters.filter(({ type }) => type === "default");
|
|
@@ -113,9 +115,16 @@ function DataManagement({
|
|
|
113
115
|
const [dataSearch, setDataSearch] = useState({ ...defaults, ...getDefaultValues(filters) });
|
|
114
116
|
const [page, setPage] = useState(0);
|
|
115
117
|
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (reserPage) {
|
|
120
|
+
setPage(0);
|
|
121
|
+
}
|
|
122
|
+
}, [reserPage]);
|
|
123
|
+
|
|
116
124
|
const values = useMemo(() => {
|
|
117
125
|
const hasTabpanel = !!tabPanel;
|
|
118
126
|
return {
|
|
127
|
+
reserPage,
|
|
119
128
|
sttLuyKe,
|
|
120
129
|
apiUrl,
|
|
121
130
|
tableName,
|
|
@@ -140,6 +149,7 @@ function DataManagement({
|
|
|
140
149
|
defaultRowsPerPage
|
|
141
150
|
};
|
|
142
151
|
}, [
|
|
152
|
+
reserPage,
|
|
143
153
|
sttLuyKe,
|
|
144
154
|
apiUrl,
|
|
145
155
|
tableName,
|
|
@@ -215,7 +225,13 @@ function DataManagement({
|
|
|
215
225
|
{tabPanel}
|
|
216
226
|
<FilterGod filters={filters} elementSize={elementSize} setPage={setPage} />
|
|
217
227
|
{backParentNavigator}
|
|
218
|
-
<DataTable
|
|
228
|
+
<DataTable
|
|
229
|
+
multipleActions={multipleActions}
|
|
230
|
+
page={page}
|
|
231
|
+
setPage={setPage}
|
|
232
|
+
disableEdit={disableEdit}
|
|
233
|
+
disableDelete={disableDelete}
|
|
234
|
+
/>
|
|
219
235
|
</Card>
|
|
220
236
|
</FormProvider>
|
|
221
237
|
|