main.js 3.2 KB

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