Browse Source

nft/users

huai-sian 3 years ago
parent
commit
b1018bc02e
8 changed files with 104 additions and 70 deletions
  1. 2 3
      adminUser-add.html
  2. 2 4
      adminUser-edit.html
  3. 2 2
      mint.html
  4. 5 5
      nft.html
  5. 38 39
      nft_add.html
  6. 49 13
      nft_edit.html
  7. 3 2
      transaction.html
  8. 3 2
      user.html

+ 2 - 3
adminUser-add.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">
@@ -913,7 +913,6 @@ var headers = {
         'Content-Type': 'application/json'
     }
 
-
 $("#nft_add_form").submit(function(e) {
   e.preventDefault();
   

+ 2 - 4
adminUser-edit.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">
@@ -935,8 +935,6 @@ axios({
 $("#nft_add_form").submit(function(e) {
   e.preventDefault();
 
-
-
   // 資料庫欄位型態是tinyint(1),所以另外用is_active_checkbox、is_active欄位來做轉換
   // if ($("#is_active_checkbox").is(':checked')) {
   //   $('#is_active').val(1);

+ 2 - 2
mint.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">

+ 5 - 5
nft.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">
@@ -662,15 +662,15 @@ $(document).ready(function($) {
           <th scope="row"><img src="' + res[i].Nft.imgurl + '" alt="' + res[i].Nft.title + '"></th> \
           <td class="fw-bold">' + res[i].Nft.title + '</td> \
           <td>' + res[i].count + '</td>' + `<td style="text-align: center;">
-            <a class="btn btn-primary" href="nft_add.html?id=${res[i].Nft.title}" role="button" style="font-size:0.8rem;">編輯</a>
+            <a class="btn btn-primary" href="nft_edit.html?id=${res[i].Nft.id}" role="button" style="font-size:0.8rem;">編輯</a>
             </td>`;
         
         temp += '</tr>';
       }
-
       $(".nftdata").html(temp);
     }, error: function(xhr, status, error) {
-      console.log(xhr.responseText); // test
+      console.log(JSON.parse(xhr.responseText)); // test
+      window.location.replace('./login.html');
     }
   });
 });

+ 38 - 39
nft_add.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">
@@ -562,15 +562,15 @@
 
               <form id="nft_add_form" method="post" enctype="multipart/form-data">
                 <div class="row mb-3">
-                  <label for="inputText" class="col-sm-2 col-form-label">名稱</label>
+                  <label for="title" class="col-sm-2 col-form-label">名稱</label>
                   <div class="col-sm-10">
-                    <input id="title" name="title" type="text" class="form-control">
+                    <input id="title" name="title" type="text" class="form-control" required>
                   </div>
                 </div>
                 <div class="row mb-3">
-                  <label for="inputNumber" class="col-sm-2 col-form-label">圖片</label>
+                  <label for="image" class="col-sm-2 col-form-label">圖片</label>
                   <div class="col-sm-10">
-                    <input id="image" name="image" class="form-control" type="file">
+                    <input id="image" name="image" class="form-control" type="file" required>
                   </div>
                 </div>   
                 <div class="row mb-3">
@@ -578,7 +578,25 @@
                   <div class="col-sm-10">
                     <input id="content" name="content" class="form-control" type="text">
                   </div>
-                </div>        
+                </div>
+                <div class="row mb-3">
+                  <label for="uid" class="col-sm-2 col-form-label">識別號</label>
+                  <div class="col-sm-10">
+                    <input id="uid" name="uid" class="form-control" type="number" placeholder="4 - 9位數字" required>
+                  </div>
+                </div>
+                <div class="row mb-3">
+                  <label for="toaddress" class="col-sm-2 col-form-label">目標地址</label>
+                  <div class="col-sm-10">
+                    <input type="text" class="form-control" id="toaddress" name="toaddress" required>
+                  </div>
+                </div>
+                <div class="row mb-3">
+                  <label for="amount" class="col-sm-2 col-form-label">數量</label>
+                  <div class="col-sm-10">
+                    <input type="number" class="form-control" id="amount" name="amount" required>
+                  </div>
+                </div>         
                 <div class="row mb-3">
                   <legend class="col-form-label col-sm-2 pt-0">顯示</legend>
                   <div class="col-sm-10">
@@ -932,21 +950,26 @@ function handleFileSelect(evt) {
 
 $("#nft_add_form").submit(function(e) {
   e.preventDefault();
-  var bodyFormData = new FormData($('#nft_add_form')[0]);
+  const form = document.querySelector('#nft_add_form');
+  var bodyFormData = new FormData(form);
  
   var title = $('#title').val();
-  var image = $('#image').val();
   var desc = $('#content').val();
+  var uid = $('#uid').val();
+  var amount = $('#amount').val();
+  var toaddress = $('#toaddress').val();
+  console.log(title, desc, uid, amount, toaddress, imageFile);
 
   bodyFormData.append('title', title);
-  bodyFormData.append('context', title);
-  bodyFormData.append('category', '');
+  bodyFormData.append('context', desc);
+  bodyFormData.append('catagory', '');
   bodyFormData.append('hash', '');
-  bodyFormData.append('userid', '');
+  bodyFormData.append('uid', uid);
+  bodyFormData.append('amount', amount);
+  bodyFormData.append('address', toaddress);
   bodyFormData.append('image', imageFile);
   bodyFormData.append('is_active', $("#is_active_checkbox").is(':checked'));
-
-
+  
   if (!title) {
     Swal.fire({
       title: '注意',
@@ -975,7 +998,7 @@ $("#nft_add_form").submit(function(e) {
   } else {
     $('#is_active').val(0);
   }
-
+  console.log(bodyFormData);
   // var formData = new FormData($("#nft_add_form")[0]);
   axios({
   method: 'post',
@@ -989,30 +1012,6 @@ $("#nft_add_form").submit(function(e) {
 }).catch(err => {
   console.log(err);
 })
- /*  $.ajax({
-      url: url,
-      headers: headers,
-      type: 'POST',
-      data: bodyFormData,
-      cache: false,
-      contentType: false,
-      processData: false,
-      success: function (res, status) {
-        console.log(res); // test
-        Swal.fire({
-            title: '新增NFT',
-            icon: 'success',
-            text: 'NFT新增成功',
-            confirmButtonColor: '#3085d6'
-        });
-        window.setTimeout(() => {
-            window.location.href = 'nft.html';
-        }, 2000);
-      }, error: function(xhr, status, error) {
-        console.log(xhr.responseText); // test
-      }      
-  });
-   */
   return false;
 });
 </script>

+ 49 - 13
nft_edit.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">
@@ -911,6 +911,9 @@ var access_token = get_access_token();
 var headers = {'Authorization': 'Bearer ' + access_token}
 
 let Data;
+let category;
+let imgurl;
+
 function getpathId(){
   let id = window.location.search.split('?').pop();
   return id.split('=')[1];
@@ -926,6 +929,8 @@ axios({
   },
 }).then(res => {
   Data = {...res.data}
+  category = Data.catagory;
+  imgurl = Data.imgurl;
   console.log(Data);
   $('#title').val(res.data.title);
   $('#desc').val(res.data.context);
@@ -938,8 +943,33 @@ axios({
   
 }).catch(err => {
   console.log(err);
+  window.location.replace('./login.html');
 })
 
+document.getElementById('image').addEventListener('change', handleFileSelect, false);
+let imageFile;
+function handleFileSelect(evt) {
+    let files = evt.target.files; // FileList object
+
+    // use the 1st file from the list
+    let f = files[0];
+    imageFile = f
+    
+    let reader = new FileReader();
+
+    // Closure to capture the file information.
+    reader.onload = (function(theFile) {
+        return function(e) {
+          
+        };
+      })(f);
+
+      // Read in the image file as a data URL.
+      reader.readAsText(f);
+      imgurl = imageFile;
+      console.log(imgurl)
+}
+
 
 $("#nft_add_form").submit(function(e) {
   e.preventDefault();
@@ -967,19 +997,26 @@ $("#nft_add_form").submit(function(e) {
   // } else {
   //   $('#is_active').val(0);
   // }
-  let { category, hash, userid, imgurl } = Data;
+  
 
   let data = {
-    category,
-    hash,
-    userid,
+    catagory: category,
     is_active: $("#is_active_checkbox").is(':checked'),
     title,
     imgurl,
     context
   }
 
+  var bodyFormData = new FormData();
+
+  bodyFormData.append('title', title);
+  bodyFormData.append('context', context);
+  bodyFormData.append('catagory', category);
+  bodyFormData.append('image', imgurl);
+  bodyFormData.append('is_active', $("#is_active_checkbox").is(':checked'));
+
   console.log(data)
+  console.log(bodyFormData);
 
 axios({
   method: 'put',
@@ -987,9 +1024,9 @@ axios({
   headers: {
         'accept': 'application/json',
         'Authorization': `Bearer ${access_token}`,
-        'Content-Type': 'application/json'
+        'Content-Type': 'multipart/form-data'
   },
-  data
+  data: bodyFormData
 }).then(res => {
   console.log(res.data)
       Swal.fire({
@@ -998,9 +1035,9 @@ axios({
         text: '新增成功',
         confirmButtonColor: '#3085d6'
       });
-      window.setTimeout(() => {
-        window.location.href = 'nft.html';
-      }, 2000);
+      // window.setTimeout(() => {
+      //   window.location.href = 'nft.html';
+      // }, 2000);
 }).catch(err => {
   console.log(err);
   Swal.fire({
@@ -1010,9 +1047,8 @@ axios({
         confirmButtonColor: '#3085d6'
     });
 }) 
-
   return false;
-});
+}); 
 
 $('#btn_nft_delete').click(function() {
   axios({

+ 3 - 2
transaction.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">
@@ -657,6 +657,7 @@ $(document).ready(function($) {
       $(".transaction_data").html(temp);
     }, error: function(xhr, status, error) {
       console.log(xhr.responseText); // test
+      window.location.replace('./login.html');
     }
   });
 });

+ 3 - 2
user.html

@@ -301,12 +301,12 @@
         </a>
       </li>
 
-      <li class="nav-item">
+      <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="mint.html">
           <i class="bi bi-grid"></i>
           <span>Mint管理</span>
         </a>
-      </li>
+      </li> -->
 
       <!-- <li class="nav-item">
         <a class="nav-link collapsed" href="index.html">
@@ -734,6 +734,7 @@ $(document).ready(function($) {
       } */
     }, error: function(xhr, status, error) {
       console.log(xhr.responseText); // test
+      window.location.replace('./login.html');
     }
   });