main.js 3.3 KB

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