|
|
@@ -346,6 +346,13 @@
|
|
|
<button type="button" id="uploadBtn" class="upload-btn">Select Image <br> 選擇圖片 </button>
|
|
|
<div id="preview" class="preview"></div> -->
|
|
|
</div>
|
|
|
+
|
|
|
+ <!-- 上傳名單 (Excel/CSV) -->
|
|
|
+ <div class="upload-section">
|
|
|
+ <label for="listInput">Upload List<br><small>上傳名單(Excel / CSV)</small></label>
|
|
|
+ <input type="file" id="listInput" class="file-input"
|
|
|
+ accept=".csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
|
|
|
+ </div>
|
|
|
</div>
|
|
|
|
|
|
<!-- <div class="options">
|
|
|
@@ -410,6 +417,8 @@
|
|
|
let file = null;
|
|
|
let fileName = "";
|
|
|
let previewUrl = null;
|
|
|
+ let listFile = null;
|
|
|
+ let listFileName = "";
|
|
|
let isLoading = false;
|
|
|
|
|
|
// // 觸發檔案選擇
|
|
|
@@ -417,7 +426,7 @@
|
|
|
// fileInput.click();
|
|
|
// });
|
|
|
|
|
|
- // 選擇檔案後處理
|
|
|
+ // 選擇圖片
|
|
|
fileInput.addEventListener("change", (e) => {
|
|
|
const f = e.target.files[0];
|
|
|
if (f) {
|
|
|
@@ -429,6 +438,53 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ const listInput = document.getElementById("listInput");
|
|
|
+
|
|
|
+ // 上傳名單
|
|
|
+ listInput.addEventListener("change", function () {
|
|
|
+ const f = this.files && this.files[0] ? this.files[0] : null;
|
|
|
+ if (!f) {
|
|
|
+ listFile = null;
|
|
|
+ listFileName = "";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 格式檢查(.csv/.xls/.xlsx)
|
|
|
+ const okTypes = [
|
|
|
+ "text/csv",
|
|
|
+ "application/vnd.ms-excel",
|
|
|
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
|
+ ];
|
|
|
+ const okExt = [".csv", ".xls", ".xlsx"];
|
|
|
+ const lowerName = f.name.toLowerCase();
|
|
|
+ const pass =
|
|
|
+ okTypes.includes(f.type) ||
|
|
|
+ okExt.some((ext) => lowerName.endsWith(ext));
|
|
|
+
|
|
|
+ if (!pass) {
|
|
|
+ listFile = null;
|
|
|
+ listFileName = "";
|
|
|
+ listInput.value = ""; // 清空
|
|
|
+
|
|
|
+ Swal.fire({
|
|
|
+ title: "請選擇 .csv / .xls / .xlsx 檔案",
|
|
|
+ icon: "warning",
|
|
|
+ confirmButtonColor: "#910784",
|
|
|
+ });
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ listFile = f;
|
|
|
+ listFileName = f.name;
|
|
|
+ console.log('listFile', listFile);
|
|
|
+ console.log('listFileName', listFileName);
|
|
|
+
|
|
|
+ // 顯示檔名與大小
|
|
|
+ const sizeKB = Math.round(f.size / 1024);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
// 送出表單
|
|
|
submitBtn.addEventListener("click", async () => {
|
|
|
console.log('送出表單');
|
|
|
@@ -506,11 +562,20 @@
|
|
|
icon: "success",
|
|
|
confirmButtonColor: "#e47140",
|
|
|
}).then(() => {
|
|
|
- // 清空欄位
|
|
|
+ // 清空圖片相關
|
|
|
file = null;
|
|
|
previewUrl = null;
|
|
|
fileName = "";
|
|
|
preview.innerHTML = "";
|
|
|
+ // input type=file,需要手動 reset
|
|
|
+ document.getElementById("fileInput").value = "";
|
|
|
+
|
|
|
+ // 清空名單相關
|
|
|
+ listFile = null;
|
|
|
+ listFileName = "";
|
|
|
+ document.getElementById("listInput").value = "";
|
|
|
+
|
|
|
+ // 清空其他欄位
|
|
|
email.value = "";
|
|
|
headline.value = "";
|
|
|
newsText.value = "";
|