lang_table.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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="js/jquery.min.js"></script>
  34. <script src="js/bootstrap.min.js"></script>
  35. <script src="js/jquery_cookie_min.js"></script>
  36. <script src="js/scripts.js"></script>
  37. <script src="js/jqhttpsdk.js"></script>
  38. <script src="js/jkcor.js"></script>
  39. <script type="text/javascript">
  40. $(function () {
  41. let post_data = {
  42. 'token': $.cookie('access_token'),
  43. 'page': 1,
  44. 'line': 10
  45. }
  46. $.postJSON(
  47. http_ip_prot + 'langWord/query', JSON.stringify(post_data),
  48. function (data) {
  49. if (data['code'] == 0) {
  50. // console.log(data['res'])
  51. console.log(data)
  52. addTable(data['res'])
  53. } else {
  54. alert(data['msg'])
  55. }
  56. }
  57. )
  58. })
  59. let la_list
  60. let checkboxInput = '<input type="checkbox" aria-label="Checkbox for following text input">'
  61. function addTable(data) {
  62. //头部多区域语言
  63. let head_data = data['la_list'];
  64. la_list = head_data
  65. // body部详细语言
  66. let body_data = data['lw_dict'];
  67. console.log(body_data)
  68. let head_html = '<tr><th>en</th>';
  69. //头部标签添加
  70. $.each(head_data, function (idx, obj) {
  71. // console.log(idx)
  72. head_html += ('<th>' + obj['lang'] + '</th>')
  73. })
  74. let body_html = ''
  75. $.each(body_data, function (idx, obj) {
  76. // console.log(idx)
  77. // console.log(obj)
  78. body_html += '<tr>';
  79. body_html += ('<td>' + idx + '</td>');
  80. console.log('--------')
  81. $.each(la_list,function (x, y) {
  82. if(obj[y['lang']]){
  83. body_html += ('<td>' + obj[y['lang']] + '</td>')
  84. }else{
  85. body_html += ('<td></td>')
  86. }
  87. })
  88. body_html += '<td><a href="#" on>del</a></td></tr>';
  89. });
  90. head_html += '<th><a href="#" onclick="addRow()">add</a></th></tr>';
  91. $('#langTableHead').html(head_html)
  92. $('#langTableBody').html(body_html)
  93. addDelFunc()
  94. }
  95. function addRow() {
  96. let newRow = '<tr><td><input class="form-control" type="text" langID="key" id="newRow_key"></td>'
  97. $.each(la_list, function (idx, obj) {
  98. // console.log(idx)
  99. // newRow += ('<td>' + obj['id'] + '</td>')
  100. newRow += ('<td>' +
  101. '<input class="form-control" type="text" langID="' + obj['id'] + '" id="newRow_lang_' + obj['id'] + '">' +
  102. '</td>')
  103. })
  104. let saveBtn = '<button type="button" class="btn btn-primary">save</button>'
  105. let delBtn = '<button type="button" class="btn btn-danger">del</button>'
  106. newRow += '<td>' + saveBtn + delBtn + '</td></tr>'
  107. $('#langTableBody').append(newRow)
  108. addDelFunc()
  109. addSaveFunc()
  110. }
  111. function addDelFunc() {
  112. $(".btn-danger").bind("click", function () {
  113. let trRow = $(this).parent().parent()
  114. trRow.remove()
  115. });
  116. }
  117. function addSaveFunc() {
  118. $(".btn-primary").bind("click", function () {
  119. let post_data = {
  120. 'token': $.cookie('access_token')
  121. }
  122. let post_list = []
  123. let trRow = $(this).parent().parent()
  124. trRow.find('input').each(function () {
  125. // console.log($(this).attr('id'))
  126. // console.log($(this).attr('langID'))
  127. let inputVal = $(this).val()
  128. let langID = $(this).attr('langID')
  129. if (langID === 'key') {
  130. post_data['word_key'] = inputVal
  131. } else {
  132. post_list.push({'la_id': langID, 'val': inputVal})
  133. }
  134. })
  135. post_data['word_arr'] = post_list
  136. console.log(post_data)
  137. $.postJSON(
  138. http_ip_prot + 'langWord/add', JSON.stringify(post_data),
  139. function (data) {
  140. if (data['code'] == 0) {
  141. // console.log(data['res'])
  142. window.location.reload();
  143. console.log(data)
  144. } else {
  145. alert(data['msg'])
  146. }
  147. }
  148. )
  149. })
  150. }
  151. </script>
  152. </body>
  153. </html>