main.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. if (typeof(cur) == "undefined" && parent.config.cur) {
  2. cur = parent.config.cur
  3. }
  4. var editors = [];
  5. function msg(value) {
  6. if (!value.data) {
  7. value.data = value.msg;
  8. }
  9. var url = '';
  10. if (value.data != 'reload' && value.status == 2) {
  11. out(value.msg);
  12. return;
  13. } else if(value.data == 'reload') {
  14. jump('');
  15. } else {
  16. if($("#url").length) {
  17. url = $("#url").val();
  18. } else {
  19. out(value.msg);
  20. return;
  21. }
  22. if (url) {
  23. jump(url);
  24. } else {
  25. jump('');
  26. }
  27. }
  28. return;
  29. }
  30. function selectShow(e, id, prefix) {
  31. if (!prefix) {
  32. prefix = 'update';
  33. }
  34. id = '#'+prefix+'_' + id
  35. if ($(id).length) {
  36. $(id).find('option').each(function()
  37. {
  38. var parent = $(this).attr('parent');
  39. if (parent != e.val()) {
  40. $(this).html('');
  41. $(this).attr('selected', false)
  42. $(this).hide();
  43. } else {
  44. $(this).html($(this).attr('name'));
  45. $(this).show();
  46. }
  47. })
  48. }
  49. }
  50. function setFarm(e, id) {
  51. //$(".top-hide").attr('class', '').show();
  52. //e.attr('class', 'top-hide'). hide()
  53. //$("#top-show").html(e.html());
  54. request('post', '/admin/setCookie', {'farm':id}, function(msg)
  55. {
  56. location.reload()
  57. });
  58. }
  59. function jump(url) {
  60. if (typeof(parent.config.parentTitle) == "undefined") {
  61. if (url) {
  62. parent.location.href = url
  63. } else {
  64. parent.location.reload()
  65. }
  66. } else {
  67. if (url) {
  68. location.href = url
  69. } else {
  70. location.reload()
  71. }
  72. }
  73. }
  74. function load(e) {
  75. var param = eval('(' + e.html() + ')');
  76. var load = e.attr('load-args');
  77. if (load) {
  78. var args = eval('(' + load + ')');
  79. }
  80. var html = '';
  81. switch (param.method) {
  82. case 'showPage':
  83. e.html(param.name);
  84. var i;
  85. var arg = '?'
  86. for (i in args) {
  87. arg += '&' + i + '=' + args[i]
  88. }
  89. e.click(function()
  90. {
  91. showPage(param.url + arg);
  92. });
  93. e.attr('class', 'layui-btn layui-btn-normal layui-btn-mini').show()
  94. break
  95. case 'showData':
  96. args.key = param.key
  97. request('post', param.url, args, function(msg)
  98. {
  99. e.html(msg)
  100. e.show()
  101. });
  102. break
  103. }
  104. }
  105. function out(msg) {
  106. layer.msg(msg, {icon: 5, anim: 6});
  107. }
  108. function getCookie(name) {
  109. var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
  110. return r ? r[1] : undefined;
  111. }
  112. function notice(msg) {
  113. layer.msg(msg,{icon:1,time:1000});
  114. }
  115. function show(title, url, w, h, full) {
  116. x_admin_show(title, url, w, h, full)
  117. }
  118. function del(obj, id, url) {
  119. layer.confirm('确认要删除吗?',function(index){
  120. data = {}
  121. data.id = id
  122. request('delete', url, data, function(msg)
  123. {
  124. $(obj).parents("tr").remove();
  125. notice('已删除');
  126. })
  127. });
  128. }
  129. function rec(obj, id, url) {
  130. layer.confirm('确认要恢复吗?',function(index){
  131. data = {}
  132. data.id = id
  133. data.state = 'True'
  134. request('delete', url, data, function(msg)
  135. {
  136. $(obj).parents("tr").remove();
  137. notice('已恢复');
  138. })
  139. });
  140. }
  141. function oper(name, url) {
  142. layer.confirm('确认要'+name+'吗?',function(index){
  143. data = {}
  144. request('post', url, data, function(msg)
  145. {
  146. notice('操作成功');
  147. })
  148. });
  149. }
  150. function delAll() {
  151. layer.confirm('确认要删除吗?',function(index){
  152. //捉到所有被选中的,发异步进行删除
  153. notice('删除成功');
  154. });
  155. }
  156. function request(type, url, data, callback) {
  157. data._xsrf = getCookie("_xsrf");
  158. $.ajax({
  159. type:type,
  160. url:url,
  161. data:data,
  162. success:function(msg){
  163. callback(msg)
  164. }
  165. });
  166. }
  167. //跳转页面
  168. function showPage(url) {
  169. location.href = url
  170. }
  171. function initEditor()
  172. {
  173. if ($('.layui-editor').length) {
  174. $ ('.layui-editor').each(function() {
  175. var parent = $(this).parent().parent();
  176. loadEditor($(this));
  177. })
  178. }
  179. }
  180. function loadEditor(e)
  181. {
  182. if (!e.length) {
  183. return;
  184. }
  185. var id = e.attr('id');
  186. var key = e.attr('key');
  187. var toolbar = [
  188. 'title'
  189. ,'bold'
  190. ,'italic'
  191. ,'underline'
  192. ,'strikethrough'
  193. ,'fontScale'
  194. ,'color'
  195. ,'ol'
  196. ,'ul'
  197. ,'blockquote'
  198. ,'code'
  199. ,'table'
  200. ,'link'
  201. ,'image'
  202. ,'hr'
  203. ,'indent'
  204. ,'outdent'
  205. ,'alignment'
  206. , '|'
  207. ,'html'
  208. ];
  209. if (typeof(editors[id]) == "object") {
  210. editors[id].destroy();
  211. editors[id] = undefined;
  212. }
  213. if (typeof(editors[id]) == "undefined") {
  214. var xsrf = getCookie("_xsrf");
  215. var uploadUrl = '/upload?_xsrf='+xsrf;
  216. editors[id] = new Simditor( {
  217. textarea: e,
  218. upload: {
  219. url: uploadUrl,
  220. params: {key:key},
  221. fileKey: 'file',
  222. connectionCount: 10,
  223. leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
  224. },
  225. toolbar : toolbar
  226. });
  227. }
  228. }