main.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. if (typeof(cur) == "undefined" && parent.config.cur) {
  2. cur = parent.config.cur
  3. }
  4. function msg(value) {
  5. if (!value.data) {
  6. value.data = value.msg;
  7. }
  8. var url = '';
  9. if (value.data != 'reload' && value.status == 2) {
  10. out(value.msg);
  11. return;
  12. } else if(value.data == 'reload') {
  13. jump('');
  14. } else {
  15. if($("#url").length) {
  16. url = $("#url").val();
  17. } else {
  18. out(value.msg);
  19. return;
  20. }
  21. if (url) {
  22. jump(url);
  23. } else {
  24. jump('');
  25. }
  26. }
  27. return;
  28. }
  29. function selectShow(e, id) {
  30. id = '#update_' + id
  31. if ($(id).length) {
  32. $(id).find('option').each(function()
  33. {
  34. var parent = $(this).attr('parent');
  35. if (parent != e.val()) {
  36. $(this).html('');
  37. $(this).attr('selected', false)
  38. $(this).hide();
  39. } else {
  40. $(this).html($(this).attr('name'));
  41. $(this).show();
  42. }
  43. })
  44. }
  45. }
  46. function setFarm(e, id) {
  47. //$(".top-hide").attr('class', '').show();
  48. //e.attr('class', 'top-hide'). hide()
  49. //$("#top-show").html(e.html());
  50. request('post', '/admin/setCookie', {'farm':id}, function(msg)
  51. {
  52. location.reload()
  53. });
  54. }
  55. function jump(url) {
  56. if (typeof(parent.config.parentTitle) == "undefined") {
  57. if (url) {
  58. parent.location.href = url
  59. } else {
  60. parent.location.reload()
  61. }
  62. } else {
  63. if (url) {
  64. location.href = url
  65. } else {
  66. location.reload()
  67. }
  68. }
  69. }
  70. function load(e) {
  71. var param = eval('(' + e.html() + ')');
  72. var load = e.attr('load-args');
  73. if (load) {
  74. var args = eval('(' + load + ')');
  75. }
  76. var html = '';
  77. switch (param.method) {
  78. case 'showPage':
  79. e.html(param.name);
  80. var i;
  81. var arg = '?'
  82. for (i in args) {
  83. arg += '&' + i + '=' + args[i]
  84. }
  85. e.click(function()
  86. {
  87. showPage(param.url + arg);
  88. });
  89. e.attr('class', 'layui-btn layui-btn-normal layui-btn-mini').show()
  90. break
  91. case 'showData':
  92. args.key = param.key
  93. request('post', param.url, args, function(msg)
  94. {
  95. e.html(msg)
  96. e.show()
  97. });
  98. break
  99. }
  100. }
  101. function out(msg) {
  102. layer.msg(msg, {icon: 5, anim: 6});
  103. }
  104. function getCookie(name) {
  105. var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
  106. return r ? r[1] : undefined;
  107. }
  108. function notice(msg) {
  109. layer.msg(msg,{icon:1,time:1000});
  110. }
  111. function show(title, url, w, h, full) {
  112. x_admin_show(title, url, w, h, full)
  113. }
  114. function del(obj, id, url) {
  115. layer.confirm('确认要删除吗?',function(index){
  116. data = {}
  117. data.id = id
  118. request('delete', url, data, function(msg)
  119. {
  120. $(obj).parents("tr").remove();
  121. notice('已删除');
  122. })
  123. });
  124. }
  125. function rec(obj, id, url) {
  126. layer.confirm('确认要恢复吗?',function(index){
  127. data = {}
  128. data.id = id
  129. data.state = 'True'
  130. request('delete', url, data, function(msg)
  131. {
  132. $(obj).parents("tr").remove();
  133. notice('已恢复');
  134. })
  135. });
  136. }
  137. function delAll() {
  138. layer.confirm('确认要删除吗?',function(index){
  139. //捉到所有被选中的,发异步进行删除
  140. notice('删除成功');
  141. });
  142. }
  143. function request(type, url, data, callback) {
  144. data._xsrf = getCookie("_xsrf");
  145. $.ajax({
  146. type:type,
  147. url:url,
  148. data:data,
  149. success:function(msg){
  150. callback(msg)
  151. }
  152. });
  153. }
  154. //跳转页面
  155. function showPage(url) {
  156. location.href = url
  157. }