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