log.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. var token = localStorage.getItem("token");
  2. if(token){
  3. token = token.substr(1,token.length-2);
  4. }
  5. var init = function () {
  6. http.get('/api/tx-manager/admin/modelList?access_token='+token, '加载数据...', function (res) {
  7. var list = $("#list");
  8. list.empty();
  9. for (var p in res) {
  10. var v = res[p];
  11. var name = v['name'];
  12. var tr = '<tr>' +
  13. '<td><a class="model-name" href="#">' + name + '</a></td>' +
  14. '<td><span>' + v['count'] + '</span></td>' +
  15. '</tr>';
  16. list.append(tr);
  17. }
  18. });
  19. };
  20. init();
  21. $(document).on("click", ".model-name", function () {
  22. var model = $(this).text();
  23. $('#model').attr("data-model", model);
  24. http.get('/api/tx-manager/admin/modelTimes?model=' + model+'&access_token='+token, '加载数据...', function (res) {
  25. var list = $("#logs");
  26. list.empty();
  27. for (var p in res) {
  28. var data = res[p];
  29. var name = data.split(":")[0];
  30. var tr = '<tr><td><a class="model-time" data-data="' + data + '" href="#">' + name + '</a></td></tr>';
  31. list.append(tr);
  32. }
  33. });
  34. return false;
  35. });
  36. $(document).on("click", ".model-time", function () {
  37. var file = $(this).attr("data-data");
  38. var path = $('#model').attr("data-model") + ":" + file;
  39. http.get('/api/tx-manager/admin/modelInfos?path=' + path+'&access_token='+token, '加载数据...', function (res) {
  40. var list = $("#compensate");
  41. list.empty();
  42. for (var p in res) {
  43. var param = res[p];
  44. var tr =
  45. '<tr>' +
  46. '<td><span>' + param.time + '</span></td>' +
  47. '<td><span>' + param.method + '</span></td>' +
  48. '<td><span>' + param.executeTime + '</span></td>' +
  49. '<td><button data-data="' + param.base64 + '" class="btn btn-info detail">详情</button>' +
  50. '&nbsp;&nbsp;' +
  51. '<button data-data="' + param.key + '" class="btn btn-success compensate">补偿</button>' +
  52. '&nbsp;&nbsp;' +
  53. '<button data-data="' + param.key + '" class="btn btn-danger delete">删除</button></td>' +
  54. '</tr>';
  55. list.append(tr);
  56. }
  57. });
  58. return false;
  59. });
  60. var confim = function(title,callback){
  61. var button = $('#show-alert').find("button[data-event=button]");
  62. button.unbind();
  63. $("#content").text(title);
  64. button.click(function(){
  65. if(callback!=null){
  66. callback();
  67. reloadPage();
  68. }
  69. return true;
  70. })
  71. $('#show-alert').modal();
  72. }
  73. $(document).on("click", ".delete", function () {
  74. var path = $(this).attr("data-data");
  75. var tag = $(this).parent().parent();
  76. confim("确认要删除吗?",function(){
  77. http.get('/api/tx-manager/admin/delCompensate?path=' + path+'&access_token='+token, '加载数据...', function (res) {
  78. if (res) {
  79. hint('删除成功.');
  80. tag.remove();
  81. } else {
  82. hint('删除失败.');
  83. }
  84. });
  85. });
  86. return false;
  87. });
  88. var reloadPage = function(){
  89. var compensate = $("#compensate");
  90. var lg = compensate.find("tr").length;
  91. if(lg==1){
  92. location.reload();
  93. }
  94. }
  95. $(document).on("click", ".compensate", function () {
  96. var path = $(this).attr("data-data");
  97. var tag = $(this).parent().parent();
  98. confim("确认要补偿吗?",function(){
  99. http.get('/api/tx-manager/admin/compensate?path=' + path+'&access_token='+token, '加载数据...', function (res) {
  100. if (res) {
  101. hint('补偿成功.');
  102. tag.remove();
  103. } else {
  104. hint('补偿失败.');
  105. }
  106. });
  107. });
  108. return false;
  109. });
  110. $(document).on("click", ".detail", function () {
  111. var base64 = $(this).attr("data-data");
  112. var unicode = BASE64.decoder(base64);
  113. var str = '';
  114. for (var i = 0, len = unicode.length; i < len; ++i) {
  115. str += String.fromCharCode(unicode[i]);
  116. }
  117. var obj = JSON.parse(str);
  118. $("#body").empty();
  119. $('#body').append('<tr>\n' +
  120. ' <th>\n' +
  121. ' 发起方模块\n' +
  122. ' </th>\n' +
  123. ' <td>\n' +
  124. ' <span id="data-model"></span>\n' +
  125. ' </td>\n' +
  126. '\n' +
  127. ' <th>\n' +
  128. ' 发起方地址\n' +
  129. ' </th>\n' +
  130. ' <td>\n' +
  131. ' <span id="data-address"></span>\n' +
  132. ' </td>\n' +
  133. ' </tr>\n' +
  134. ' <tr>\n' +
  135. ' <th>\n' +
  136. ' 发起方标示\n' +
  137. ' </th>\n' +
  138. ' <td colspan="3">\n' +
  139. ' <span id="data-uniqueKey"></span>\n' +
  140. ' </td>\n' +
  141. ' </tr>\n' +
  142. ' <tr>\n' +
  143. ' <th>\n' +
  144. ' 记录时间\n' +
  145. ' </th>\n' +
  146. ' <td>\n' +
  147. ' <span id="data-currentTime"></span>\n' +
  148. ' </td>\n' +
  149. '\n' +
  150. ' <th>\n' +
  151. ' 执行时间(毫秒)\n' +
  152. ' </th>\n' +
  153. ' <td >\n' +
  154. ' <span id="data-time"></span>\n' +
  155. ' </td>\n' +
  156. ' </tr>\n' +
  157. ' <tr>\n' +
  158. ' <th>\n' +
  159. ' 发起方执行方法\n' +
  160. ' </th>\n' +
  161. ' <td colspan="3">\n' +
  162. ' <span id="data-methodStr"></span>\n' +
  163. ' </td>\n' +
  164. ' </tr>\n' +
  165. ' <tr>\n' +
  166. ' <th>\n' +
  167. ' 事务组Id\n' +
  168. ' </th>\n' +
  169. ' <td>\n' +
  170. ' <span id="data-groupId"></span>\n' +
  171. ' </td>\n' +
  172. ' <th>\n' +
  173. ' 完成状态</br>(1:已结束 0:未结束)\n' +
  174. ' </th>\n' +
  175. ' <td >\n' +
  176. ' <span id="data-hasOver"></span>\n' +
  177. ' </td>\n' +
  178. ' </tr>');
  179. $("#data-address").text(obj["address"]);
  180. var currentTime = obj["currentTime"];
  181. var date = new Date(currentTime);
  182. $("#data-currentTime").text(date.format('yyyy-MM-dd h:m:s'));
  183. $("#data-model").text(obj["model"]);
  184. $("#data-model").text(obj["model"]);
  185. $("#data-time").text(obj["time"]);
  186. $("#data-methodStr").text(obj["methodStr"]);
  187. $("#data-uniqueKey").text(obj["uniqueKey"]);
  188. $("#data-hasOver").text(obj["txGroup"]["hasOver"]);
  189. $("#data-groupId").text(obj["txGroup"]["groupId"]);
  190. $("#data-startTime").text(obj["txGroup"]["startTime"]);
  191. $("#data-state").text(obj["txGroup"]["state"]);
  192. var list = obj["txGroup"]["list"];
  193. for (var index in list) {
  194. var p = list[index];
  195. var notify = p["notify"];
  196. var model = p["model"];
  197. var modelIpAddress = p["modelIpAddress"];
  198. var methodStr = p["methodStr"];
  199. var uniqueKey = p["uniqueKey"];
  200. var tr1 =
  201. '<tr>' +
  202. '<th>模块名称</th><td><span>' + model + '</span></td>' +
  203. '<th>模块地址</th><td><span>' + modelIpAddress + '</span></td>' +
  204. '</tr>';
  205. $("#body").append(tr1);
  206. var tr2 =
  207. '<tr>' +
  208. '<th>唯一标示</th><td><span>' + uniqueKey + '</span></td>' +
  209. '<th>是否提交</th><td><span>' + notify + '</span></td>' +
  210. '</tr>';
  211. $("#body").append(tr2);
  212. var tr3 =
  213. '<tr>' +
  214. '<th>执行方法</th><td colspan="3"><span>' + methodStr + '</span></td>' +
  215. '</tr>';
  216. $("#body").append(tr3);
  217. }
  218. $('#show-modal').modal();
  219. return false;
  220. });