@amirjalili1374/ui-kit 1.6.5 → 1.6.7

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/ui-kit.es.js CHANGED
@@ -33096,99 +33096,125 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent$1({
33096
33096
  const handleExportClientSide = () => {
33097
33097
  const sourceItems = (props.items && props.items.length ? props.items : items.value) ?? [];
33098
33098
  if (!sourceItems.length) return;
33099
- const validHeaders = props.headers.filter((h2) => !!h2.key && !!h2.title);
33100
- const excelData = sourceItems.map((item) => {
33099
+ const headers = props.headers.filter((h2) => h2.key && h2.title);
33100
+ const now = /* @__PURE__ */ new Date();
33101
+ const exportDate = now.toLocaleDateString("fa-IR") + " " + now.toLocaleTimeString("fa-IR", { hour: "2-digit", minute: "2-digit" });
33102
+ const title = props.exportFileName || "گزارش";
33103
+ const moneyTotals = {};
33104
+ const rows = sourceItems.map((item) => {
33101
33105
  const row = {};
33102
- validHeaders.forEach((header) => {
33106
+ headers.forEach((h2) => {
33103
33107
  var _a;
33104
- let value2 = header.nestedKey ? (_a = item[header.key]) == null ? void 0 : _a[header.nestedKey] : item[header.key];
33105
- if (header.type === "money") {
33108
+ let value2 = h2.nestedKey ? (_a = item[h2.key]) == null ? void 0 : _a[h2.nestedKey] : item[h2.key];
33109
+ if (h2.type === "money") {
33106
33110
  const num = Number(value2);
33107
33111
  value2 = !isNaN(num) ? num : 0;
33112
+ moneyTotals[h2.title] = (moneyTotals[h2.title] || 0) + value2;
33108
33113
  }
33109
- if (typeof value2 === "boolean") {
33110
- value2 = value2 ? "بله" : "خیر";
33111
- }
33112
- row[header.title] = value2 ?? "";
33114
+ if (typeof value2 === "boolean") value2 = value2 ? "بله" : "خیر";
33115
+ row[h2.title] = value2 ?? "";
33113
33116
  });
33114
33117
  return row;
33115
33118
  });
33116
33119
  const totalRow = {};
33117
- validHeaders.forEach((header) => {
33118
- if (header.type === "money") {
33119
- totalRow[header.title] = excelData.reduce((sum2, r) => sum2 + (Number(r[header.title]) || 0), 0);
33120
- } else if (header === validHeaders[0]) {
33121
- totalRow[header.title] = "جمع کل";
33122
- } else {
33123
- totalRow[header.title] = "";
33124
- }
33120
+ headers.forEach((h2, i) => {
33121
+ if (h2.type === "money") totalRow[h2.title] = moneyTotals[h2.title] || 0;
33122
+ else if (i === 0) totalRow[h2.title] = "جمع کل";
33123
+ else totalRow[h2.title] = "";
33125
33124
  });
33126
- excelData.push(totalRow);
33127
- const worksheet = xlsx_minExports.utils.json_to_sheet(excelData);
33128
- const range = xlsx_minExports.utils.decode_range(worksheet["!ref"]);
33129
- worksheet["!rtl"] = true;
33130
- worksheet["!cols"] = validHeaders.map((header, colIdx) => {
33131
- let maxLength = header.title.length;
33132
- excelData.forEach((row) => {
33133
- const val2 = row[header.title];
33134
- if (val2) {
33135
- maxLength = Math.max(maxLength, String(val2).length);
33136
- }
33125
+ rows.push(totalRow);
33126
+ const ws = xlsx_minExports.utils.json_to_sheet(rows, { origin: "A4" });
33127
+ const range = xlsx_minExports.utils.decode_range(ws["!ref"]);
33128
+ ws["!freeze"] = { xSplit: 0, ySplit: 3 };
33129
+ ws["!autofilter"] = {
33130
+ ref: xlsx_minExports.utils.encode_range({
33131
+ s: { r: 3, c: 0 },
33132
+ e: range.e
33133
+ })
33134
+ };
33135
+ ws["!cols"] = headers.map((h2) => {
33136
+ let max = h2.title.length;
33137
+ rows.forEach((r) => {
33138
+ const len = String(r[h2.title] ?? "").length;
33139
+ if (len > max) max = len;
33137
33140
  });
33138
- return { wch: maxLength + 3 };
33141
+ return { wch: max + 4 };
33139
33142
  });
33140
- validHeaders.forEach((_, colIdx) => {
33141
- const addr = xlsx_minExports.utils.encode_cell({ r: 0, c: colIdx });
33142
- const cell = worksheet[addr];
33143
- if (cell) {
33143
+ xlsx_minExports.utils.sheet_add_aoa(
33144
+ ws,
33145
+ [
33146
+ [title],
33147
+ [`تاریخ چاپ: ${exportDate}`],
33148
+ []
33149
+ ],
33150
+ { origin: "A1" }
33151
+ );
33152
+ ws["!merges"] = [
33153
+ {
33154
+ s: { r: 0, c: 0 },
33155
+ e: { r: 0, c: headers.length - 1 }
33156
+ }
33157
+ ];
33158
+ ws["A1"].s = {
33159
+ font: { bold: true, sz: 16, name: "B Nazanin" },
33160
+ alignment: { horizontal: "center", vertical: "center" }
33161
+ };
33162
+ ws["A2"].s = {
33163
+ font: { name: "B Nazanin", sz: 12 },
33164
+ alignment: { horizontal: "left" }
33165
+ };
33166
+ const headerStyle = {
33167
+ font: { bold: true, name: "B Nazanin" },
33168
+ alignment: { horizontal: "center", vertical: "center" },
33169
+ fill: { fgColor: { rgb: "D9D9D9" } },
33170
+ border: {
33171
+ top: { style: "thin" },
33172
+ bottom: { style: "thin" },
33173
+ left: { style: "thin" },
33174
+ right: { style: "thin" }
33175
+ }
33176
+ };
33177
+ const zebraFill = { fgColor: { rgb: "F7F7F7" } };
33178
+ headers.forEach((h2, c) => {
33179
+ const headerCell = xlsx_minExports.utils.encode_cell({ r: 3, c });
33180
+ if (ws[headerCell]) ws[headerCell].s = headerStyle;
33181
+ for (let r = 4; r <= rows.length + 3; r++) {
33182
+ const addr = xlsx_minExports.utils.encode_cell({ r, c });
33183
+ const cell = ws[addr];
33184
+ if (!cell) continue;
33185
+ const isTotalRow = r === rows.length + 3;
33186
+ const zebra = r % 2 === 0;
33144
33187
  cell.s = {
33145
- font: { bold: true, name: "B Nazanin", sz: 12 },
33146
- alignment: { horizontal: "center", vertical: "center" },
33147
- fill: { fgColor: { rgb: "D9D9D9" } },
33188
+ font: { name: "B Nazanin" },
33189
+ alignment: {
33190
+ horizontal: h2.type === "money" ? "center" : "right",
33191
+ vertical: "center"
33192
+ },
33148
33193
  border: {
33149
33194
  top: { style: "thin" },
33150
33195
  bottom: { style: "thin" },
33151
33196
  left: { style: "thin" },
33152
33197
  right: { style: "thin" }
33153
- }
33198
+ },
33199
+ fill: zebra && !isTotalRow ? zebraFill : void 0
33154
33200
  };
33155
- }
33156
- });
33157
- validHeaders.forEach((header, colIdx) => {
33158
- if (header.type === "money") {
33159
- for (let rowIdx = 1; rowIdx <= excelData.length; rowIdx++) {
33160
- const addr = xlsx_minExports.utils.encode_cell({ r: rowIdx, c: colIdx });
33161
- const cell = worksheet[addr];
33162
- if (cell && typeof cell.v === "number") {
33163
- cell.z = "#,##0;[Red]-#,##0";
33164
- cell.s = {
33165
- font: { name: "B Nazanin" },
33166
- alignment: { horizontal: "center" }
33167
- };
33168
- }
33201
+ if (h2.type === "money" && typeof cell.v === "number") {
33202
+ cell.z = "#,##0;[Red]-#,##0";
33203
+ }
33204
+ if (isTotalRow) {
33205
+ cell.s.font = { bold: true, name: "B Nazanin" };
33206
+ cell.s.fill = { fgColor: { rgb: "EFEFEF" } };
33169
33207
  }
33170
33208
  }
33171
33209
  });
33172
- const totalRowIndex = excelData.length;
33173
- validHeaders.forEach((_, colIdx) => {
33174
- const addr = xlsx_minExports.utils.encode_cell({ r: totalRowIndex, c: colIdx });
33175
- const cell = worksheet[addr];
33176
- if (cell) {
33177
- cell.s = {
33178
- font: { bold: true, name: "B Nazanin" },
33179
- fill: { fgColor: { rgb: "EFEFEF" } },
33180
- alignment: { horizontal: "center" }
33181
- };
33182
- }
33183
- });
33184
- worksheet["!freeze"] = { xSplit: 0, ySplit: 1 };
33185
- worksheet["!autofilter"] = {
33186
- ref: xlsx_minExports.utils.encode_range(range)
33210
+ const wb = xlsx_minExports.utils.book_new();
33211
+ wb.Workbook = {
33212
+ Views: [{ RTL: true }]
33187
33213
  };
33188
- const workbook = xlsx_minExports.utils.book_new();
33189
- xlsx_minExports.utils.book_append_sheet(workbook, worksheet, "Report");
33190
- const fileName = `${props.exportFileName || "report"}.xlsx`;
33191
- xlsx_minExports.writeFile(workbook, fileName);
33214
+ xlsx_minExports.utils.book_append_sheet(wb, ws, "Report");
33215
+ const dateForFile = now.toLocaleDateString("fa-IR").replaceAll("/", "-");
33216
+ const fileName = `${title}_${dateForFile}.xlsx`;
33217
+ xlsx_minExports.writeFile(wb, fileName);
33192
33218
  };
33193
33219
  const handleExport = async () => {
33194
33220
  var _a, _b, _c;