SyuanYu 1 month ago
parent
commit
72d49e68cf

+ 7 - 5
news_templates/static/js/main.js

@@ -22,11 +22,13 @@ function historyBack() {
 let topBtn = document.querySelector('.top-btn');
 
 window.onscroll = () => {
-    const px = 100;
-    if (document.documentElement.scrollTop > px) {
-        topBtn.classList.add("show");
-    } else {
-        topBtn.classList.remove("show");
+    if (topBtn) {
+        const px = 100;
+        if (document.documentElement.scrollTop > px) {
+            topBtn.classList.add("show");
+        } else {
+            topBtn.classList.remove("show");
+        }
     }
 };
 

+ 7 - 5
static/js/main.js

@@ -22,11 +22,13 @@ function historyBack() {
 let topBtn = document.querySelector('.top-btn');
 
 window.onscroll = () => {
-    const px = 100;
-    if (document.documentElement.scrollTop > px) {
-        topBtn.classList.add("show");
-    } else {
-        topBtn.classList.remove("show");
+    if (topBtn) {
+        const px = 100;
+        if (document.documentElement.scrollTop > px) {
+            topBtn.classList.add("show");
+        } else {
+            topBtn.classList.remove("show");
+        }
     }
 };
 

+ 67 - 2
themes/hugo-bootstrap-5/layouts/free-pr-service/_index.html

@@ -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 = "";