Browse Source

會員帳號管理

mike 3 years ago
parent
commit
4086b05f66
1 changed files with 77 additions and 85 deletions
  1. 77 85
      tables-data.html

+ 77 - 85
tables-data.html

@@ -533,53 +533,54 @@
               <!-- <p>Add lightweight datatables to your project with using the <a href="https://github.com/fiduswriter/Simple-DataTables" target="_blank">Simple DataTables</a> library. Just add <code>.datatable</code> class name to any table you wish to conver to a datatable</p> -->
 
               <!-- Table with stripped rows -->
-              <table class="table small datatable">
-                <thead>
-                  <tr>
-                    <th scope="col">#</th>
-                    <th scope="col">userid</th>
-                    <th scope="col">account</th>
-                    <th scope="col">email</th>
-                  </tr>
-                </thead>
-                <tbody class="userdata">
-                  <!-- <tr>
-                    <th scope="row">1</th>
-                    <td>Brandon Jacob</td>
-                    <td>Designer</td>
-                    <td>28</td>
-                    <td>2016-05-25</td>
-                  </tr>
-                  <tr>
-                    <th scope="row">2</th>
-                    <td>Bridie Kessler</td>
-                    <td>Developer</td>
-                    <td>35</td>
-                    <td>2014-12-05</td>
-                  </tr>
-                  <tr>
-                    <th scope="row">3</th>
-                    <td>Ashleigh Langosh</td>
-                    <td>Finance</td>
-                    <td>45</td>
-                    <td>2011-08-12</td>
-                  </tr>
-                  <tr>
-                    <th scope="row">4</th>
-                    <td>Angus Grady</td>
-                    <td>HR</td>
-                    <td>34</td>
-                    <td>2012-06-11</td>
-                  </tr>
-                  <tr>
-                    <th scope="row">5</th>
-                    <td>Raheem Lehner</td>
-                    <td>Dynamic Division Officer</td>
-                    <td>47</td>
-                    <td>2011-04-19</td>
-                  </tr> -->
-                </tbody>
-              </table>
+              <!-- <table class="table small datatable"> -->
+              <div class="table-responsive">
+                <table class="table table-responsive small text-wrap">
+                  <thead>
+                    <tr>
+                      <th scope="col">#</th>
+                      <th scope="col">Line ID / 帳號</th>
+                    </tr>
+                  </thead>
+                  <tbody class="userdata">
+                    <!-- <tr>
+                      <th scope="row">1</th>
+                      <td>Brandon Jacob</td>
+                      <td>Designer</td>
+                      <td>28</td>
+                      <td>2016-05-25</td>
+                    </tr>
+                    <tr>
+                      <th scope="row">2</th>
+                      <td>Bridie Kessler</td>
+                      <td>Developer</td>
+                      <td>35</td>
+                      <td>2014-12-05</td>
+                    </tr>
+                    <tr>
+                      <th scope="row">3</th>
+                      <td>Ashleigh Langosh</td>
+                      <td>Finance</td>
+                      <td>45</td>
+                      <td>2011-08-12</td>
+                    </tr>
+                    <tr>
+                      <th scope="row">4</th>
+                      <td>Angus Grady</td>
+                      <td>HR</td>
+                      <td>34</td>
+                      <td>2012-06-11</td>
+                    </tr>
+                    <tr>
+                      <th scope="row">5</th>
+                      <td>Raheem Lehner</td>
+                      <td>Dynamic Division Officer</td>
+                      <td>47</td>
+                      <td>2011-04-19</td>
+                    </tr> -->
+                  </tbody>
+                </table>
+              </div>
               <!-- End Table with stripped rows -->
 
             </div>
@@ -622,45 +623,36 @@
 
 <script>
 $(document).ready(function($) {
-  var str = '{ \
-    "hashed_password": "", \
-    "useraddress": "0x7a08c2f5587c1f848f13caa03035216c30034f13", \
-    "is_active": false, \
-    "created_at": "0000-00-00 00:00:00", \
-    "email": "", \
-    "id": 11,\
-    "userid": "U171a225ef8a06a3491f1d94310b7b265", \
-    "account": "", \
-    "is_superuser": false, \
-    "updated_at": "0000-00-00 00:00:00" \
-  }, \
-  { \
-    "hashed_password": "", \
-    "useraddress": "0xd1acf1eb9c956d1e90b650dd56bed57a5df2fcae", \
-    "is_active": false, \
-    "created_at": "0000-00-00 00:00:00", \
-    "email": "", \
-    "id": 12, \
-    "userid": "U1bd102319717680d145d74fe74af38f4", \
-    "account": "", \
-    "is_superuser": false, \
-    "updated_at": "0000-00-00 00:00:00" \
-  }';
-
-  var data = $.parseJSON('[' + str + ']');
+  var url = 'https://api.ptt.cx:8750/api/v1/user/?skip=0&limit=100';
+  var access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NDA4NzM4NDAsInN1YiI6IjkyIn0.Tt4i45p6S7EVZee4UcLcFakLUUx1zzIWOQ4Md4I8_ww';
+  var headers = {'Authorization': 'Bearer ' + access_token}
+
+  $.ajax({
+    url: url,
+    headers: headers,
+    success: function(res, status, jqXHR) {
+      console.log(res); // test
  
-  var temp = "";
-
-  for (let i=0; i < data.length; i++) {
-    temp += '<tr> \
-      <th scope="row">' + data[i].id + '</th> \
-      <td>' + data[i].userid + '</td> \
-      <td>' + data[i].account + '</td> \
-      <td>' + data[i].email + '</td> \
-    </tr>';
-  }
-
-  $(".userdata").html(temp);
+      var temp = "";
+
+      for (let i=0; i < res.length; i++) {
+        temp += '<tr> \
+          <th scope="row">' + res[i].id + '</th>';
+        
+        if (res[i].userid) {
+          temp += '<td>' + res[i].userid + '</td>';
+        } else if (res[i].account) {
+          temp += '<td>' + res[i].account + ' (<a href="mailto:' + res[i].email + '">' + res[i].email + '</a>)</td>';
+        }
+        
+        temp += '</tr>';
+      }
+
+      $(".userdata").html(temp);
+    }, error: function(xhr, status, error) {
+      console.log(xhr.responseText); // test
+    }
+  });
 });
 </script>  
 </body>