Skip to content

Commit

Permalink
Merge pull request #32 from chienniman/issue-26
Browse files Browse the repository at this point in the history
Issue-26
  • Loading branch information
chienniman authored Jun 27, 2024
2 parents a943a40 + 366a008 commit bc213fd
Show file tree
Hide file tree
Showing 16 changed files with 1,716 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
File renamed without changes
File renamed without changes.
17 changes: 17 additions & 0 deletions components/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$(document).ready(function () {
function createBaseElement() {
$("body").append(`
<div class="bg"></div>
<div class="bg bg2"></div>
<div class="bg bg3"></div>
<div class="content">
<h1>全聯報表生成器</h1>
</div>
<div id="uploadedFiles"></div>
<div class="top-row"></div>
<table id="resultTable" border="1"></table>
`);
}

createBaseElement();
});
60 changes: 60 additions & 0 deletions dist/components/actionButtons/dailySummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(() => {
// helpers/mergeStyleString.js
function mergeStyleString(fixedStyles, styles) {
const mergedStyles = { ...fixedStyles, ...styles };
return Object.keys(mergedStyles).map((key) => `${key}: ${mergedStyles[key]};`).join(" ");
}

// components/shared/buttons/button.js
function button({ id, text, styles }) {
const fixedStyles = {
"max-width": "80px",
cursor: "pointer"
};
return `<button id="${id}" class="button" style="${mergeStyleString(
fixedStyles,
styles
)}">${text}</button>`;
}

// utils/dataProcessing.js
function getData(key) {
var storedData = sessionStorage.getItem(key);
return storedData ? JSON.parse(storedData) : null;
}

// components/actionButtons/dailySummary.js
$(document).ready(function() {
$(".top-row").append(
button({
id: "dailySummary",
text: "\u7E3D\u7D50",
styles: { display: "none" }
})
);
$("#dailySummary").on("click", async function() {
function generateSummary() {
const visitedAreas = getData("visitedAreas");
const visitedAreasText = visitedAreas.join("\uFF0C");
const summaryData = getData("summaryData");
const areaSummaries = summaryData.filter((e) => visitedAreas.includes(e["C"])).map((e) => {
const F = Math.ceil(e["F"]);
const G = Math.ceil(e["G"]);
const E = (e["E"] * 100).toFixed(2) + "%";
const H = (e["H"] * 100).toFixed(2) + "%";
return `${e["C"]}\u7684\u696D\u7E3E\u76EE\u6A19\u662F ${F}\uFF0C\u696D\u7E3E\u9054\u6210\u662F ${G}\uFF0C\u696D\u7E3E\u5360\u6BD4\u662F ${E}\uFF0C\u9054\u6210\u767E\u5206\u6BD4\u662F ${H}`;
});
let base = `\u4ECA\u65E5\u62DC\u8A2A\u4E86${visitedAreasText},\u56DE\u9867\u4ECA\u65E5\u696D\u7E3E\u9054\u6210\uFF0C`;
if (areaSummaries.length > 0) {
base += areaSummaries.join(";");
}
Swal.fire({
title: "\u6BCF\u65E5\u7E3D\u7D50",
text: base,
icon: "success"
});
}
generateSummary();
});
});
})();
49 changes: 49 additions & 0 deletions dist/components/actionButtons/exportToExcel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(() => {
// helpers/mergeStyleString.js
function mergeStyleString(fixedStyles, styles) {
const mergedStyles = { ...fixedStyles, ...styles };
return Object.keys(mergedStyles).map((key) => `${key}: ${mergedStyles[key]};`).join(" ");
}

// components/shared/buttons/button.js
function button({ id, text, styles }) {
const fixedStyles = {
"max-width": "80px",
cursor: "pointer"
};
return `<button id="${id}" class="button" style="${mergeStyleString(
fixedStyles,
styles
)}">${text}</button>`;
}

// components/actionButtons/exportToExcel.js
$(document).ready(function() {
$(".top-row").append(
button({
id: "exportToExcel",
text: "\u5C0E\u51FA",
styles: { display: "none" }
})
);
$("#exportToExcel").on("click", async function() {
function isTableEmpty(table) {
return table.children().length === 0;
}
function downloadDate() {
const today = /* @__PURE__ */ new Date();
const month = today.getMonth() + 1;
const day = today.getDate();
return `${month}\u6708_${day}\u65E5`;
}
function exportToExcel() {
const htmlTable = $("#resultTable");
if (isTableEmpty(htmlTable)) {
Swal.fire({ title: "\u7121\u6CD5\u5C0E\u51FA\u7A7A\u8868\u683C!", icon: "error" });
}
new Table2Excel().export(htmlTable, `PX\u53F0\u4E2D\u65E5\u92B7\u5EAB\u5B58\u8868_${downloadDate()}`);
}
exportToExcel();
});
});
})();
Loading

0 comments on commit bc213fd

Please sign in to comment.