huaisianhuang 3 éve
szülő
commit
a762a72a35
3 módosított fájl, 131 hozzáadás és 38 törlés
  1. 8 21
      api/static/index2.html
  2. 108 17
      api/static/script_msg.js
  3. 15 0
      api/static/style.css

+ 8 - 21
api/static/index2.html

@@ -142,7 +142,7 @@
                 <h5 class="card-title">Jocelyn</h5>
               </div>
             </div>
-            <div class="card item" data-avatar="Angela" data-img="Jocelyn">
+            <div class="card item" data-avatar="Angela" data-img="Angela">
               <div class="imgfr"><img src="static/img/Angela.webp" class="card-img-top" alt="..."></div>
               <div class="card-body">
                 <h5 class="card-title">Angela</h5>
@@ -152,29 +152,16 @@
         </fieldset>
         <fieldset>
           <h3 class="fs-subtitle">台詞</h3>
-          <input type="text" name='t1' class='txtsrc txtsrc1' value="" placeholder="1"/> <br/>
-          <input type="text" name='t2' class='txtsrc txtsrc2' value="" placeholder="2" /><br/>
-          <input type="text" name='t3' class='txtsrc txtsrc3' value="" placeholder="3" /><br/>
-          <input type="text" name='t4' class='txtsrc txtsrc4' value="" placeholder="4" /><br/>
-          <input type="text" name='t5' class='txtsrc txtsrc5' value="" placeholder="5" /><br/>
-          <input type="text" name='t6' class='txtsrc txtsrc6' value="" placeholder="6" /><br/>
-          <input type="text" name='t7' class='txtsrc txtsrc7' value="" placeholder="7" /><br/>
-          <input type="text" name='t8' class='txtsrc txtsrc8' value="" placeholder="8" /><br/>
-          <input type="text" name='t9' class='txtsrc txtsrc9' value="" placeholder="9" /><br/>
-          <input type="text" name='t10' class='txtsrc txtsrc10' value="" placeholder="10" /><br/>
+          <div class="subtitle-inputs">
+          
+          </div>
+            <span class="add">+</span>
         </fieldset>
         <fieldset id='imgSrc'>
           <h3 class="fs-subtitle" style="display: inline-block;">影像連結<img class="ms-1" src="static/img/question.png" alt="" data-bs-toggle="tooltip" data-bs-placement="right" title="僅接受png, jpg, mp4格式"></h3><br/>
-          <input type="text" name='m1' class='imgsrc imgsrc1' value="" placeholder="1" /><input id="img1" type="file" class="img_uploader img_up"><label for="img1" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m2' class='imgsrc imgsrc2' value="" placeholder="2" /><input id="img2" type="file" class="img_uploader img_up"><label for="img2" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m3' class='imgsrc imgsrc3' value="" placeholder="3" /><input id="img3" type="file" class="img_uploader img_up"><label for="img3" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m4' class='imgsrc imgsrc4' value="" placeholder="4" /><input id="img4" type="file" class="img_uploader img_up"><label for="img4" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m5' class='imgsrc imgsrc5' value="" placeholder="5" /><input id="img5" type="file" class="img_uploader img_up"><label for="img5" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m6' class='imgsrc imgsrc6' value="" placeholder="6" /><input id="img6" type="file" class="img_uploader img_up"><label for="img6" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m7' class='imgsrc imgsrc7' value="" placeholder="7" /><input id="img7" type="file" class="img_uploader img_up"><label for="img7" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m8' class='imgsrc imgsrc8' value="" placeholder="8" /><input id="img8" type="file" class="img_uploader img_up"><label for="img8" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m9' class='imgsrc imgsrc9' value="" placeholder="9" /><input id="img9" type="file" class="img_uploader img_up"><label for="img9" class="upload-btn">上傳檔案</label><br/>
-          <input type="text" name='m10' class='imgsrc imgsrc10' value="" placeholder="10" /><input id="img10" type="file" class="img_uploader img_up"><label for="img10" class="upload-btn">上傳檔案</label><br/>
+          <div class="img-inputs">
+          </div>
+          <span class="addimg">+</span>
           <input id="checker" type="button" name="next" class="next action-button" value="送出" />
           <h3 style="display: none;" class="fs-subtitle">處理進度</h3>
           <div style="display: none;" id="myProgress">

+ 108 - 17
api/static/script_msg.js

@@ -30,11 +30,10 @@ function avatarChange() {
   $('.owl-carousel').trigger('to.owl.carousel', avatarSelector.selectedIndex);
   console.log(value);
   for(let i = 0;i < card.length; i++) {
+    card[i].classList.remove('active');
     if(card[i].dataset.avatar == value) {
       card[i].classList.add('active');
-    } else {
-      card[i].classList.remove('active');
-    }
+    } 
   }
 }
 
@@ -91,15 +90,16 @@ $(".next").click(function () {
   txtARR = [];
   imgARR = [];
   var step;
-  for (step = 1; step <= 10; step++) {
-    if ($(".txtsrc" + step).val() != "") {
-      txtARR.push($(".txtsrc" + step).val())
+  let contentIdx = document.querySelectorAll(".txtsrc").length;
+  for (let i = 1; i < (contentIdx + 1); i++) {
+    if ($(`.txtsrc${i}`).val() != "") {
+      txtARR.push($(`.txtsrc${i}`).val())
     }
   }
-  var step2;
-  for (step2 = 1; step2 <= 10; step2++) {
-    if ($(".imgsrc" + step2).val() != "") {
-      imgARR.push($(".imgsrc" + step2).val())
+  let imgIdx = document.querySelectorAll(".imgsrc").length;
+  for (let i = 1; i < (imgIdx + 1); i++) {
+    if ($(`.imgsrc${i}`).val() != "") {
+      imgARR.push($(`.imgsrc${i}`).val())
     }
   }
   dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar, "client_id": client_id }
@@ -222,18 +222,109 @@ function load_data() {
   $("#linker").show();
   $(".linker__box").show();
 
-  $(".title_new").val(loaded_data.find(item => item.id == tid).name)
-  var step;
-  for (step = 1; step <= 10; step++) {
-    $(".txtsrc" + step).val(loaded_data.find(item => item.id == tid).text_content[step - 1])
+  let historyItem = loaded_data.filter(item => item.id == tid)[0];
+    console.log(historyItem);
+  $(".title_new").val(loaded_data.find(item => item.id == tid).name);
+
+  let txtlength = historyItem.text_content.length;
+  let imglength = historyItem.image_urls.length;
+
+  subtitleInputs.innerHTML = '';
+  imgInputs.innerHTML = '';
+  for (let i = 0; i < txtlength ; i++) {
+    var txtinput = document.createElement("input");
+        txtinput.setAttribute('type', 'text');
+        txtinput.setAttribute('name', `t${i+1}`);
+        txtinput.value = historyItem.text_content[i];
+        txtinput.setAttribute('placeholder', `${i+1}`);
+        txtinput.classList.add('txtsrc',`txtsrc${i+1}`)
+        subtitleInputs.appendChild(txtinput);
   }
-  var step2;
-  for (step2 = 1; step2 <= 10; step2++) {
-    $(".imgsrc" + step2).val(loaded_data.find(item => item.id == tid).image_urls[step2 - 1])
+  for (let i = 0; i < imglength; i++) {
+    var imginput = document.createElement("input");
+        imginput.setAttribute('type', 'text');
+        imginput.setAttribute('name', `m${i+1}`);
+        imginput.classList.add('imgsrc', `imgsrc${i+1}`);
+        imginput.value = historyItem.image_urls[i];
+        imginput.setAttribute('placeholder', `${i+1}`);
+        imgInputs.appendChild(imginput);
+
+        var imgupload = document.createElement("input");
+        imgupload.setAttribute('id', `img${i+1}`);
+        imgupload.setAttribute('type', `file`);
+        imgupload.classList.add('img_uploader', 'img_up');
+        imgInputs.appendChild(imgupload);
+        var imguploadlabel = document.createElement("label");
+        imguploadlabel.setAttribute('for', `img${i+1}`);
+        imguploadlabel.classList.add('upload-btn');
+        imguploadlabel.textContent = '上傳檔案';
+        imgInputs.appendChild(imguploadlabel);
   }
 
 }
 
+
+var subtitleInputs = document.querySelector(".subtitle-inputs");
+var imgInputs = document.querySelector(".img-inputs");
+let length = 5;
+function initial() {
+    for(let i = 0;i < length; i++) {
+        rendertxtBlock(i+1);
+        renderimgBlock(i+1);
+    }
+    console.log(document.querySelectorAll(".txtsrc").length + 1);
+}
+
+initial();
+
+var addbtn = document.querySelector(".add");
+var addimgbtn = document.querySelector(".addimg");
+
+addbtn.addEventListener('click', addtxtBlock);
+addimgbtn.addEventListener('click', addimgBlock);
+
+function addtxtBlock() {
+    let newIdx = document.querySelectorAll(".txtsrc").length + 1;
+    rendertxtBlock(newIdx);
+}
+
+function addimgBlock() {
+    let newimgIdx = document.querySelectorAll(".imgsrc").length + 1;
+    renderimgBlock(newimgIdx);
+}
+
+function rendertxtBlock(i){
+    var txtinput = document.createElement("input");
+        txtinput.setAttribute('type', 'text');
+        txtinput.setAttribute('name', `t${i}`);
+        txtinput.value = "";
+        txtinput.setAttribute('placeholder', `${i}`);
+        txtinput.classList.add('txtsrc',`txtsrc${i}`)
+        subtitleInputs.appendChild(txtinput);
+}
+
+function renderimgBlock(i) {
+    var imginput = document.createElement("input");
+        imginput.setAttribute('type', 'text');
+        imginput.setAttribute('name', `m${i}`);
+        imginput.classList.add('imgsrc', `imgsrc${i}`);
+        imginput.value = "";
+        imginput.setAttribute('placeholder', `${i}`);
+        imgInputs.appendChild(imginput);
+
+        var imgupload = document.createElement("input");
+        imgupload.setAttribute('id', `img${i}`);
+        imgupload.setAttribute('type', `file`);
+        imgupload.classList.add('img_uploader', 'img_up');
+        imgInputs.appendChild(imgupload);
+        var imguploadlabel = document.createElement("label");
+        imguploadlabel.setAttribute('for', `img${i}`);
+        imguploadlabel.classList.add('upload-btn');
+        imguploadlabel.textContent = '上傳檔案';
+        imgInputs.appendChild(imguploadlabel);
+}
+
+
 $('.owl-carousel').owlCarousel({
   loop:true,
   margin:10,

+ 15 - 0
api/static/style.css

@@ -696,3 +696,18 @@ footer {
 	background-color: #3b86d6;
 }
 
+.add, .addimg {
+	cursor: pointer;
+	display: inline-block;
+	width: 2rem;
+	height: 2rem;
+	background-color: #67abf3;
+	font-size: 1.2rem;
+	color: white;
+	border-radius: 50%;
+	transition: all .3s;
+}
+.add:hover, .addimg:hover {
+	background-color: #398ee9;
+}
+