lang_table.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>langTable</title>
  8. <meta name="description" content="Source code generated using layoutit.com">
  9. <meta name="author" content="LayoutIt!">
  10. <link href="css/bootstrap.min.css" rel="stylesheet">
  11. </head>
  12. <body>
  13. <div class="container-fluid">
  14. <div class="row">
  15. <div class="col-md-12">
  16. <div class="input-group">
  17. <div class="input-group-prepend">
  18. <div class="input-group-text">
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. <!--add-->
  24. <div class="col-md-12">
  25. <table class="table">
  26. <thead id="langTableHead"></thead>
  27. <tbody id="langTableBody"></tbody>
  28. </table>
  29. </div>
  30. </div>
  31. </div>
  32. <table id="aacccxx"></table>
  33. <script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>
  34. <script src="js/jquery.min.js"></script>
  35. <script src="js/bootstrap.min.js"></script>
  36. <script src="js/jquery_cookie_min.js"></script>
  37. <script src="js/scripts.js"></script>
  38. <script src="js/jqhttpsdk.js"></script>
  39. <script src="js/jkcor.js"></script>
  40. <script type="text/javascript">
  41. $(function () {
  42. let post_data = {
  43. 'token': $.cookie('access_token'),
  44. 'page': 1,
  45. 'line': 10
  46. }
  47. $.postJSON(
  48. http_ip_prot + 'langWord/query', JSON.stringify(post_data),
  49. function (data) {
  50. if (data['code'] == 0) {
  51. // console.log(data['res'])
  52. console.log(data)
  53. addTable(data['res'])
  54. } else {
  55. alert(data['msg'])
  56. }
  57. }
  58. )
  59. })
  60. let la_list
  61. let checkboxInput = '<input type="checkbox" aria-label="Checkbox for following text input">'
  62. function addTable(data) {
  63. //头部多区域语言
  64. let head_data = data['la_list'];
  65. la_list = head_data
  66. // body部详细语言
  67. let body_data = data['lw_dict'];
  68. console.log(body_data)
  69. let head_html = '<tr><th>en</th>';
  70. //头部标签添加
  71. $.each(head_data, function (idx, obj) {
  72. // console.log(idx)
  73. head_html += ('<th>' + obj['lang'] + '</th>')
  74. })
  75. let body_html = ''
  76. $.each(body_data, function (idx, obj) {
  77. // console.log(idx)
  78. // console.log(obj)
  79. body_html += '<tr>';
  80. body_html += ('<td>' + idx + '</td>');
  81. console.log('--------')
  82. $.each(la_list,function (x, y) {
  83. if(obj[y['lang']]){
  84. body_html += ('<td>' + obj[y['lang']] + '</td>')
  85. }else{
  86. body_html += ('<td></td>')
  87. }
  88. })
  89. body_html += '<td><a href="#" on>del</a></td></tr>';
  90. });
  91. head_html += '<th><a href="#" onclick="addRow()">add</a></th></tr>';
  92. $('#langTableHead').html(head_html)
  93. $('#langTableBody').html(body_html)
  94. addDelFunc()
  95. }
  96. function addRow() {
  97. let newRow = '<tr><td><input class="form-control" type="text" langID="key" id="newRow_key"></td>'
  98. $.each(la_list, function (idx, obj) {
  99. // console.log(idx)
  100. // newRow += ('<td>' + obj['id'] + '</td>')
  101. newRow += ('<td>' +
  102. '<input class="form-control" type="text" langID="' + obj['id'] + '" id="newRow_lang_' + obj['id'] + '">' +
  103. '</td>')
  104. })
  105. let saveBtn = '<button type="button" class="btn btn-primary">save</button>'
  106. let delBtn = '<button type="button" class="btn btn-danger">del</button>'
  107. newRow += '<td>' + saveBtn + delBtn + '</td></tr>'
  108. $('#langTableBody').append(newRow)
  109. addDelFunc()
  110. addSaveFunc()
  111. }
  112. function addDelFunc() {
  113. $(".btn-danger").bind("click", function () {
  114. let trRow = $(this).parent().parent()
  115. trRow.remove()
  116. });
  117. }
  118. function addSaveFunc() {
  119. $(".btn-primary").bind("click", function () {
  120. let post_data = {
  121. 'token': $.cookie('access_token')
  122. }
  123. let post_list = []
  124. let trRow = $(this).parent().parent()
  125. trRow.find('input').each(function () {
  126. // console.log($(this).attr('id'))
  127. // console.log($(this).attr('langID'))
  128. let inputVal = $(this).val()
  129. let langID = $(this).attr('langID')
  130. if (langID === 'key') {
  131. post_data['word_key'] = inputVal
  132. } else {
  133. post_list.push({'la_id': langID, 'val': inputVal})
  134. }
  135. })
  136. post_data['word_arr'] = post_list
  137. console.log(post_data)
  138. $.postJSON(
  139. http_ip_prot + 'langWord/add', JSON.stringify(post_data),
  140. function (data) {
  141. if (data['code'] == 0) {
  142. // console.log(data['res'])
  143. window.location.reload();
  144. console.log(data)
  145. } else {
  146. alert(data['msg'])
  147. }
  148. }
  149. )
  150. })
  151. }
  152. </script>
  153. </body>
  154. </html>