main.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 oper(obj, id, url, status) {
  119. layer.confirm('确认要进行此项操作吗?',function(index){
  120. data = {}
  121. data.id = id
  122. data.status = status
  123. request('delete', url, data, function(msg)
  124. {
  125. location.reload();
  126. })
  127. });
  128. }
  129. function del(obj, id, url) {
  130. layer.confirm('确认要删除吗?',function(index){
  131. data = {}
  132. data.id = id
  133. request('delete', url, data, function(msg)
  134. {
  135. $(obj).parents("tr").remove();
  136. notice('已删除');
  137. })
  138. });
  139. }
  140. function rec(obj, id, url) {
  141. layer.confirm('确认要恢复吗?',function(index){
  142. data = {}
  143. data.id = id
  144. data.state = 'True'
  145. request('delete', url, data, function(msg)
  146. {
  147. $(obj).parents("tr").remove();
  148. notice('已恢复');
  149. })
  150. });
  151. }
  152. function delAll() {
  153. layer.confirm('确认要删除吗?',function(index){
  154. //捉到所有被选中的,发异步进行删除
  155. notice('删除成功');
  156. });
  157. }
  158. function request(type, url, data, callback) {
  159. data._xsrf = getCookie("_xsrf");
  160. $.ajax({
  161. type:type,
  162. url:url,
  163. data:data,
  164. success:function(msg){
  165. callback(msg)
  166. }
  167. });
  168. }
  169. //跳转页面
  170. function showPage(url) {
  171. location.href = url
  172. }
  173. function initEditor()
  174. {
  175. if ($('.layui-editor').length) {
  176. $ ('.layui-editor').each(function() {
  177. var parent = $(this).parent().parent();
  178. loadEditor($(this));
  179. })
  180. }
  181. }
  182. function loadEditor(e)
  183. {
  184. if (!e.length) {
  185. return;
  186. }
  187. var id = e.attr('id');
  188. var key = e.attr('key');
  189. var toolbar = [
  190. 'title'
  191. ,'bold'
  192. ,'italic'
  193. ,'underline'
  194. ,'strikethrough'
  195. ,'fontScale'
  196. ,'color'
  197. ,'ol'
  198. ,'ul'
  199. ,'blockquote'
  200. ,'code'
  201. ,'table'
  202. ,'link'
  203. ,'image'
  204. ,'hr'
  205. ,'indent'
  206. ,'outdent'
  207. ,'alignment'
  208. , '|'
  209. ,'html'
  210. ];
  211. if (typeof(editors[id]) == "object") {
  212. editors[id].destroy();
  213. editors[id] = undefined;
  214. }
  215. if (typeof(editors[id]) == "undefined") {
  216. var xsrf = getCookie("_xsrf");
  217. var uploadUrl = '/upload?_xsrf='+xsrf;
  218. editors[id] = new Simditor( {
  219. textarea: e,
  220. upload: {
  221. url: uploadUrl,
  222. params: {key:key},
  223. fileKey: 'file',
  224. connectionCount: 10,
  225. leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
  226. },
  227. toolbar : toolbar
  228. });
  229. }
  230. }