aq-fe-framework 0.1.19 → 0.1.21
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/dist/utils/index.d.mts +6 -1
- package/dist/utils/index.mjs +17 -0
- package/package.json +1 -1
- package/dist/index.d.mts +0 -4
- package/dist/index.mjs +0 -267
package/dist/utils/index.d.mts
CHANGED
|
@@ -38,6 +38,11 @@ declare function utils_excel_download({ workbook, name }: {
|
|
|
38
38
|
}): Promise<void>;
|
|
39
39
|
|
|
40
40
|
declare function utils_file_fileToAQDocumentType(file: File): Promise<any>;
|
|
41
|
+
declare function utils_file_docxtemplaterDownload({ data, filePath, fileName }: {
|
|
42
|
+
data: any;
|
|
43
|
+
filePath: string;
|
|
44
|
+
fileName?: string;
|
|
45
|
+
}): Promise<void>;
|
|
41
46
|
|
|
42
47
|
interface I {
|
|
43
48
|
crudType?: "delete" | "update" | "create" | "error" | "importSucess";
|
|
@@ -54,4 +59,4 @@ declare const utils_time_getCurrentTimeString: () => string;
|
|
|
54
59
|
declare function U0MyValidateEmpty(message?: string): (value: unknown) => string | number | bigint | true | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null;
|
|
55
60
|
declare function U0MyValidateEmail(value?: string): "Email không đúng định dạng" | null;
|
|
56
61
|
|
|
57
|
-
export { type IUtils_Excel_ColumnConfig, U0DateToDDMMYYYString, U0MyValidateEmail, U0MyValidateEmpty, utils_converter_enumToOptions, utils_converter_enumToSelectOptions, utils_converter_getKeyByValue, utils_converter_getLabelByValue, utils_date_dateToDDMMYYYString, utils_excel_download, utils_excel_exportExcel, utils_file_fileToAQDocumentType, utils_notification_show, utils_pdf_download, utils_time_convertTimeStringToSeconds, utils_time_getCurrentTimeString };
|
|
62
|
+
export { type IUtils_Excel_ColumnConfig, U0DateToDDMMYYYString, U0MyValidateEmail, U0MyValidateEmpty, utils_converter_enumToOptions, utils_converter_enumToSelectOptions, utils_converter_getKeyByValue, utils_converter_getLabelByValue, utils_date_dateToDDMMYYYString, utils_excel_download, utils_excel_exportExcel, utils_file_docxtemplaterDownload, utils_file_fileToAQDocumentType, utils_notification_show, utils_pdf_download, utils_time_convertTimeStringToSeconds, utils_time_getCurrentTimeString };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -132,6 +132,9 @@ async function utils_excel_download({
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// src/utils/file.ts
|
|
135
|
+
import Docxtemplater from "docxtemplater";
|
|
136
|
+
import { saveAs as saveAs2 } from "file-saver";
|
|
137
|
+
import PizZip from "pizzip";
|
|
135
138
|
function utils_file_fileToAQDocumentType(file) {
|
|
136
139
|
return new Promise((resolve, reject) => {
|
|
137
140
|
const fileReader = new FileReader();
|
|
@@ -150,6 +153,19 @@ function utils_file_fileToAQDocumentType(file) {
|
|
|
150
153
|
fileReader.readAsDataURL(file);
|
|
151
154
|
});
|
|
152
155
|
}
|
|
156
|
+
async function utils_file_docxtemplaterDownload({
|
|
157
|
+
data,
|
|
158
|
+
filePath,
|
|
159
|
+
fileName
|
|
160
|
+
}) {
|
|
161
|
+
const response = await fetch(filePath);
|
|
162
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
163
|
+
const zip = new PizZip(arrayBuffer);
|
|
164
|
+
const doc = new Docxtemplater(zip);
|
|
165
|
+
doc.render(data);
|
|
166
|
+
const buffer = doc.getZip().generate({ type: "base64" });
|
|
167
|
+
saveAs2(buffer, fileName || "output.docx");
|
|
168
|
+
}
|
|
153
169
|
|
|
154
170
|
// src/utils/notification.ts
|
|
155
171
|
import { notifications } from "@mantine/notifications";
|
|
@@ -244,6 +260,7 @@ export {
|
|
|
244
260
|
utils_date_dateToDDMMYYYString,
|
|
245
261
|
utils_excel_download,
|
|
246
262
|
utils_excel_exportExcel,
|
|
263
|
+
utils_file_docxtemplaterDownload,
|
|
247
264
|
utils_file_fileToAQDocumentType,
|
|
248
265
|
utils_notification_show,
|
|
249
266
|
utils_pdf_download,
|
package/package.json
CHANGED
package/dist/index.d.mts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { IUtils_Excel_ColumnConfig, U0DateToDDMMYYYString, U0MyValidateEmail, U0MyValidateEmpty, utils_converter_enumToOptions, utils_converter_enumToSelectOptions, utils_converter_getKeyByValue, utils_converter_getLabelByValue, utils_date_dateToDDMMYYYString, utils_excel_download, utils_excel_exportExcel, utils_file_fileToAQDocumentType, utils_notification_show, utils_pdf_download, utils_time_convertTimeStringToSeconds, utils_time_getCurrentTimeString } from './utils/index.mjs';
|
|
2
|
-
import 'exceljs';
|
|
3
|
-
import '@mantine/core';
|
|
4
|
-
import 'react';
|
package/dist/index.mjs
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
// src/components/Layouts/FlexColumn/MyFlexColumn.tsx
|
|
2
|
-
import { Flex } from "@mantine/core";
|
|
3
|
-
|
|
4
|
-
// src/utils/notification.ts
|
|
5
|
-
import { notifications } from "@mantine/notifications";
|
|
6
|
-
function utils_notification_show({ crudType = "create", message, color }) {
|
|
7
|
-
if (crudType == "create") {
|
|
8
|
-
notifications.show({
|
|
9
|
-
message: message ? message : "Th\xEAm th\xE0nh c\xF4ng!",
|
|
10
|
-
color: color ? color : "green"
|
|
11
|
-
});
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (crudType == "update") {
|
|
15
|
-
notifications.show({
|
|
16
|
-
message: message ? message : "C\u1EADp nh\u1EADt th\xE0nh c\xF4ng!",
|
|
17
|
-
color: color ? color : "green"
|
|
18
|
-
});
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (crudType == "delete") {
|
|
22
|
-
notifications.show({
|
|
23
|
-
message: message ? message : "X\xF3a th\xE0nh c\xF4ng!",
|
|
24
|
-
color: color ? color : "green"
|
|
25
|
-
});
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (crudType == "error") {
|
|
29
|
-
notifications.show({
|
|
30
|
-
message: message ? message : "L\u1ED7i!",
|
|
31
|
-
color: color ? color : "red"
|
|
32
|
-
});
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (crudType == "importSucess") {
|
|
36
|
-
notifications.show({
|
|
37
|
-
message: message ? message : "Import th\xE0nh c\xF4ng!"
|
|
38
|
-
});
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/components/Buttons/ButtonCRUD/MyButtonCreate.tsx
|
|
44
|
-
import { useDisclosure } from "@mantine/hooks";
|
|
45
|
-
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
46
|
-
|
|
47
|
-
// src/components/Buttons/Button/MyButton.tsx
|
|
48
|
-
import { Button } from "@mantine/core";
|
|
49
|
-
import { IconDeviceFloppy, IconEdit, IconFileExport, IconFileImport, IconPlus, IconPrinter, IconTrash, IconX } from "@tabler/icons-react";
|
|
50
|
-
|
|
51
|
-
// src/components/Buttons/ButtonModal/MyButtonModal.tsx
|
|
52
|
-
import { Button as Button2, Modal } from "@mantine/core";
|
|
53
|
-
import { IconEdit as IconEdit2, IconPlus as IconPlus2, IconTrash as IconTrash2 } from "@tabler/icons-react";
|
|
54
|
-
|
|
55
|
-
// src/utils/converter.ts
|
|
56
|
-
var utils_converter_enumToOptions = (enumObj) => {
|
|
57
|
-
return Object.entries(enumObj).filter(([key]) => isNaN(Number(key))).map(([label, value]) => ({ value: String(value), label }));
|
|
58
|
-
};
|
|
59
|
-
var utils_converter_getLabelByValue = (data, value) => {
|
|
60
|
-
const numericValue = Number(value);
|
|
61
|
-
return data[numericValue] || "Kh\xF4ng x\xE1c \u0111\u1ECBnh";
|
|
62
|
-
};
|
|
63
|
-
var utils_converter_getKeyByValue = (obj, value) => {
|
|
64
|
-
var _a;
|
|
65
|
-
return (_a = Object.entries(obj).find(([_, v]) => v === value)) == null ? void 0 : _a[0];
|
|
66
|
-
};
|
|
67
|
-
function utils_converter_enumToSelectOptions(enumObject) {
|
|
68
|
-
const result = [];
|
|
69
|
-
const numericEnumKeys = Object.keys(enumObject).filter((key) => isNaN(Number(key)));
|
|
70
|
-
for (const key of numericEnumKeys) {
|
|
71
|
-
const enumValue = enumObject[key];
|
|
72
|
-
if (typeof enumValue === "number") {
|
|
73
|
-
result.push({
|
|
74
|
-
value: String(enumValue),
|
|
75
|
-
label: key
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/utils/date.ts
|
|
83
|
-
function U0DateToDDMMYYYString(date) {
|
|
84
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
85
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
86
|
-
const year = date.getFullYear();
|
|
87
|
-
return `${day}/${month}/${year}`;
|
|
88
|
-
}
|
|
89
|
-
function utils_date_dateToDDMMYYYString(date) {
|
|
90
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
91
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
92
|
-
const year = date.getFullYear();
|
|
93
|
-
return `${day}/${month}/${year}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/utils/excel.ts
|
|
97
|
-
import saveAs from "file-saver";
|
|
98
|
-
async function utils_excel_exportExcel({
|
|
99
|
-
workbook,
|
|
100
|
-
sheetName,
|
|
101
|
-
data,
|
|
102
|
-
config
|
|
103
|
-
}) {
|
|
104
|
-
const sheet = workbook.addWorksheet(sheetName);
|
|
105
|
-
const fieldNames = config.map((item) => String(item.fieldKey));
|
|
106
|
-
const headerMappings = {};
|
|
107
|
-
const markedColumns = [];
|
|
108
|
-
config.forEach((item) => {
|
|
109
|
-
const fieldKeyStr = String(item.fieldKey);
|
|
110
|
-
headerMappings[fieldKeyStr] = item.fieldName;
|
|
111
|
-
if (item.isRequired) {
|
|
112
|
-
markedColumns.push(fieldKeyStr);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
const columns = fieldNames.map((fieldName) => {
|
|
116
|
-
return {
|
|
117
|
-
key: fieldName,
|
|
118
|
-
width: 20
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
sheet.columns = columns;
|
|
122
|
-
const displayRow = sheet.addRow(
|
|
123
|
-
fieldNames.map((fieldName) => {
|
|
124
|
-
const displayName = headerMappings[fieldName] || fieldName;
|
|
125
|
-
return markedColumns.includes(fieldName) ? `${displayName} *` : displayName;
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
const keyRow = sheet.addRow(fieldNames);
|
|
129
|
-
data.forEach((item) => {
|
|
130
|
-
const rowData = {};
|
|
131
|
-
fieldNames.forEach((field) => {
|
|
132
|
-
rowData[field] = item[field];
|
|
133
|
-
});
|
|
134
|
-
sheet.addRow(rowData);
|
|
135
|
-
});
|
|
136
|
-
for (let i = 1; i <= fieldNames.length; i++) {
|
|
137
|
-
const cell = displayRow.getCell(i);
|
|
138
|
-
cell.font = { bold: true };
|
|
139
|
-
cell.fill = {
|
|
140
|
-
type: "pattern",
|
|
141
|
-
pattern: "solid",
|
|
142
|
-
fgColor: { argb: "FFE0E0E0" }
|
|
143
|
-
// Light gray background
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
for (let i = 1; i <= fieldNames.length; i++) {
|
|
147
|
-
const cell = keyRow.getCell(i);
|
|
148
|
-
cell.font = { italic: true };
|
|
149
|
-
cell.fill = {
|
|
150
|
-
type: "pattern",
|
|
151
|
-
pattern: "solid",
|
|
152
|
-
fgColor: { argb: "FFF0F0F0" }
|
|
153
|
-
// Lighter gray background
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if (markedColumns.length > 0) {
|
|
157
|
-
for (let i = 1; i <= fieldNames.length; i++) {
|
|
158
|
-
const cell = displayRow.getCell(i);
|
|
159
|
-
const text = cell.value;
|
|
160
|
-
if (typeof text === "string" && text.endsWith(" *")) {
|
|
161
|
-
cell.value = {
|
|
162
|
-
richText: [
|
|
163
|
-
{
|
|
164
|
-
text: text.substring(0, text.length - 2),
|
|
165
|
-
font: { bold: true }
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
text: " *",
|
|
169
|
-
font: { bold: true, color: { argb: "FFFF0000" } }
|
|
170
|
-
// Red color
|
|
171
|
-
}
|
|
172
|
-
]
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return workbook;
|
|
178
|
-
}
|
|
179
|
-
async function utils_excel_download({
|
|
180
|
-
workbook,
|
|
181
|
-
name
|
|
182
|
-
}) {
|
|
183
|
-
const buffer = await workbook.xlsx.writeBuffer();
|
|
184
|
-
const blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
|
|
185
|
-
saveAs(blob, name);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// src/utils/file.ts
|
|
189
|
-
function utils_file_fileToAQDocumentType(file) {
|
|
190
|
-
return new Promise((resolve, reject) => {
|
|
191
|
-
const fileReader = new FileReader();
|
|
192
|
-
fileReader.onloadend = () => {
|
|
193
|
-
const fileName = file.name;
|
|
194
|
-
const fileExtension = file.name.split(".").pop();
|
|
195
|
-
const fileBase64String = fileReader.result;
|
|
196
|
-
resolve({
|
|
197
|
-
fileName,
|
|
198
|
-
fileExtension,
|
|
199
|
-
fileBase64String: fileBase64String.split(",")[1]
|
|
200
|
-
// Chỉ lấy phần base64 sau dấu phẩy
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
fileReader.onerror = reject;
|
|
204
|
-
fileReader.readAsDataURL(file);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// src/utils/pdf.ts
|
|
209
|
-
import axios from "axios";
|
|
210
|
-
async function utils_pdf_download(url) {
|
|
211
|
-
try {
|
|
212
|
-
const response = await axios.get(url, {
|
|
213
|
-
responseType: "blob"
|
|
214
|
-
// Đảm bảo nhận dữ liệu dạng blob để tải file
|
|
215
|
-
});
|
|
216
|
-
const blob = new Blob([response.data], { type: "application/pdf" });
|
|
217
|
-
const link = document.createElement("a");
|
|
218
|
-
link.href = window.URL.createObjectURL(blob);
|
|
219
|
-
link.download = "file.pdf";
|
|
220
|
-
link.click();
|
|
221
|
-
window.URL.revokeObjectURL(link.href);
|
|
222
|
-
} catch (error) {
|
|
223
|
-
console.error("Error downloading PDF:", error);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// src/utils/time.ts
|
|
228
|
-
var utils_time_convertTimeStringToSeconds = (time) => {
|
|
229
|
-
const [hours, minutes, seconds] = time.split(":").map(Number);
|
|
230
|
-
return hours * 3600 + minutes * 60 + seconds;
|
|
231
|
-
};
|
|
232
|
-
var utils_time_getCurrentTimeString = () => {
|
|
233
|
-
const formatTime = (number) => {
|
|
234
|
-
return number < 10 ? "0" + number : number;
|
|
235
|
-
};
|
|
236
|
-
const now = /* @__PURE__ */ new Date();
|
|
237
|
-
const hours = formatTime(now.getHours());
|
|
238
|
-
const minutes = formatTime(now.getMinutes());
|
|
239
|
-
const seconds = formatTime(now.getSeconds());
|
|
240
|
-
return `${hours}:${minutes}:${seconds}`;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// src/utils/validateForm.ts
|
|
244
|
-
import { isNotEmpty } from "@mantine/form";
|
|
245
|
-
function U0MyValidateEmpty(message) {
|
|
246
|
-
return isNotEmpty(message ? message : "Kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng");
|
|
247
|
-
}
|
|
248
|
-
function U0MyValidateEmail(value) {
|
|
249
|
-
return /^\S+@\S+$/.test(value) ? null : "Email kh\xF4ng \u0111\xFAng \u0111\u1ECBnh d\u1EA1ng";
|
|
250
|
-
}
|
|
251
|
-
export {
|
|
252
|
-
U0DateToDDMMYYYString,
|
|
253
|
-
U0MyValidateEmail,
|
|
254
|
-
U0MyValidateEmpty,
|
|
255
|
-
utils_converter_enumToOptions,
|
|
256
|
-
utils_converter_enumToSelectOptions,
|
|
257
|
-
utils_converter_getKeyByValue,
|
|
258
|
-
utils_converter_getLabelByValue,
|
|
259
|
-
utils_date_dateToDDMMYYYString,
|
|
260
|
-
utils_excel_download,
|
|
261
|
-
utils_excel_exportExcel,
|
|
262
|
-
utils_file_fileToAQDocumentType,
|
|
263
|
-
utils_notification_show,
|
|
264
|
-
utils_pdf_download,
|
|
265
|
-
utils_time_convertTimeStringToSeconds,
|
|
266
|
-
utils_time_getCurrentTimeString
|
|
267
|
-
};
|