main.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260
  1. //这里的代码是最早写的,很乱,以后整合优化
  2. var editors = [];
  3. var editors_index = [];
  4. var tables = [];
  5. var select = '';
  6. var submitButton = '';
  7. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  8. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  9. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  10. } else {
  11. return this.replace(reallyDo, replaceWith);
  12. }
  13. }
  14. Array.prototype.remove = function(val) {
  15. var index = -1;
  16. for(var i = 0; i < this.length; i++)
  17. {
  18. if(this[i] == val)
  19. {
  20. index = i;
  21. }
  22. }
  23. if (index > -1) {
  24. this.splice(index, 1);
  25. }
  26. };
  27. $(document).ready(function()
  28. {
  29. //init();
  30. });
  31. function init()
  32. {
  33. editors = [];
  34. editors_index = [];
  35. select = '';
  36. edit();
  37. del();
  38. checkbox();
  39. image();
  40. change();
  41. autocomplete();
  42. template();
  43. submit();
  44. loadShow();
  45. initEditor();
  46. initPic();
  47. initDate();
  48. initLayui();
  49. initColor();
  50. //更新页面一些功能,上边的一些功能等找时间再优化吧
  51. dever_update.init();
  52. hljs.initHighlightingOnLoad();
  53. table();
  54. }
  55. function initLayui()
  56. {
  57. layui.use('layer', function() {
  58. var layer = layui.layer;
  59. layer.ready(function() {
  60. $(".dever-img").each(function()
  61. {
  62. layer.photos({
  63. photos: '#' + $(this).attr('id')
  64. });
  65. });
  66. });
  67. });
  68. }
  69. function initColor()
  70. {
  71. if ($('.dever-color').length) {
  72. $('.dever-color').each(function()
  73. {
  74. var self = $(this);
  75. var val = self.val();
  76. if (!val) {
  77. val = '#000000';
  78. }
  79. self.css('border-right', '40px solid '+val);
  80. self.colpick({
  81. layout:'hex',
  82. submit:0,
  83. colorScheme:'dark',
  84. color: val,
  85. onChange : function (hsb,hex,rgb,el,bySetColor) {
  86. $(el).css('border-color','#'+hex);
  87. if(!bySetColor) $(el).val('#' + hex);
  88. }
  89. }).keyup(function(){
  90. $(this).colpickSetColor(this.value);
  91. });
  92. })
  93. }
  94. }
  95. function formData(form)
  96. {
  97. var d = {};
  98. var t = $(form).serializeArray();
  99. var u = '';
  100. $.each(t, function() {
  101. if (this.name.indexOf('search_') != -1) {
  102. d[this.name] = this.value;
  103. u += '&' + this.name + '=' + this.value;
  104. }
  105. });
  106. return [d,u];
  107. }
  108. function initMenu()
  109. {
  110. if(typeof(config.layout) != "undefined")
  111. {
  112. $('.list-unstyled li').each(function(j)
  113. {
  114. $(this).unbind('click').bind('click', function()
  115. {
  116. if ($(this).index() == i) {
  117. //return;
  118. }
  119. $('.list-unstyled .active').each(function()
  120. {
  121. $(this).attr('class', '');
  122. $(this).find('a').attr('class', '');
  123. })
  124. $(this).attr('class', 'active');
  125. var a = $(this).find('a');
  126. a.attr('class', 'subdrop');
  127. //alert($(this).attr('class'));
  128. })
  129. });
  130. /*
  131. $('.project-list').each(function(i)
  132. {
  133. $(this).unbind('click').bind('click', function()
  134. {
  135. if ($(this).index() == i) {
  136. return;
  137. }
  138. $('.project-list').each(function()
  139. {
  140. $(this).find('i').parent().attr('class', '');
  141. $(this).find('ul').attr('class', 'list-unstyled upload-menu');
  142. })
  143. $(this).find('i').parent().attr('class', 'active');
  144. $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
  145. })
  146. });
  147. */
  148. }
  149. }
  150. function setOption(e, id)
  151. {
  152. var s = $("select[name="+id+"]");
  153. var v = s.val();
  154. if (!select) {
  155. select = s.clone();
  156. }
  157. s.find('option[parent]').remove();
  158. //查找出需要显示的option并复制
  159. var options = select.find("option[parent="+e.val()+"]").clone();
  160. //将需要显示的option添加到select中
  161. s.append(options);
  162. //因为option.remove()不会刷新控件,需要将新的option切换上去
  163. //这里排除了options.size() == 0的情况
  164. var state = 2;
  165. s.find('option').each(function()
  166. {
  167. var val = $(this).val();
  168. if (v == val) {
  169. state = 1;
  170. }
  171. });
  172. if (state == 1) {
  173. s.val(v);
  174. } else {
  175. s.val(0);
  176. }
  177. }
  178. function table()
  179. {
  180. if ($('.table-responsive').length) {
  181. $('.table-responsive[data-pattern]').each(function()
  182. {
  183. $(this).responsiveTable('update');
  184. });
  185. }
  186. }
  187. function pjax(param)
  188. {
  189. param.timeout = 8000;
  190. $.pjax(param);
  191. }
  192. function initDate()
  193. {
  194. $.datetimepicker.setLocale('ch');
  195. if($(".manage_time").length)
  196. {
  197. $(".manage_time").each(function()
  198. {
  199. $(this).datetimepicker(
  200. {
  201. //inline:true,
  202. timepicker:false,
  203. format:'Y-m-d',
  204. lang:'ch'
  205. });
  206. });
  207. }
  208. if($(".manage_date").length)
  209. {
  210. $(".manage_date").each(function()
  211. {
  212. $(this).datetimepicker(
  213. {
  214. //datepicker:false,
  215. format:'Y-m-d H:i:s',
  216. lang:'ch'
  217. });
  218. });
  219. }
  220. }
  221. function initPic()
  222. {
  223. $('a[rel]').fancybox();
  224. }
  225. function initEditor(e)
  226. {
  227. if (!e) {
  228. e = $('.editor');
  229. }
  230. if(e.length)
  231. {
  232. var param = false;
  233. var editor = [];
  234. e.each(function()
  235. {
  236. var parent = $(this).parent().parent();
  237. //alert(parent.attr('id'));
  238. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  239. {
  240. return;
  241. }
  242. if (!param) {
  243. param = loadEditorParam($(this));
  244. }
  245. editor.push($(this).attr('id'));
  246. });
  247. if (editor) {
  248. for (var i in editor) {
  249. var id = editor[i];
  250. if (typeof(id) == 'string' && !editors[id]) {
  251. param.index = editors_index.length;
  252. editors[id] = KindEditor.create('#' + id, param);
  253. editors_index.push(id);
  254. }
  255. }
  256. }
  257. }
  258. }
  259. function loadEditorParam(e)
  260. {
  261. if(!e.length)
  262. {
  263. return;
  264. }
  265. var key = e.attr('key');
  266. var media = e.attr('media');
  267. if (!media) {
  268. media = key;
  269. }
  270. var view = config.upload.replace('save', 'view');
  271. var param = {
  272. height : "500px",
  273. allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
  274. allowImageRemote : true, //上传图片框网络图片的功能,false为隐藏,默认为true
  275. allowFileManager : true, //浏览图片空间
  276. allowMediaUpload : true,
  277. filterMode : true, //HTML特殊代码过滤
  278. themeType : 'default',
  279. filePostName : 'file',
  280. dialogOffset : 0, //对话框距离页面顶部的位置,默认为0居中,
  281. uploadJson : config.upload + '.kindeditor?key=' + key,
  282. fileManagerJson : view + '.kindeditorFile?key=' + media,
  283. items : [
  284. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  285. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  286. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  287. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  288. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  289. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'media' ,'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  290. 'anchor', 'link', 'unlink'
  291. ]
  292. /*
  293. items : [
  294. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  295. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  296. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  297. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  298. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  299. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  300. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  301. 'anchor', 'link', 'unlink', '|', 'about'
  302. ]
  303. */
  304. }
  305. return param;
  306. }
  307. //更新页面的提交按钮
  308. function submit()
  309. {
  310. if($(".save-data").length)
  311. {
  312. if (submitButton) {
  313. $(".save-data").each(function()
  314. {
  315. $(this).html(submitButton);
  316. })
  317. }
  318. $(".save-data").unbind('click').bind('click', function()
  319. {
  320. if (editors) {
  321. for (var i in editors) {
  322. if (i.indexOf('update_') != -1) {
  323. editors[i].sync();
  324. }
  325. }
  326. }
  327. //return;
  328. submitButton = $(this).html();
  329. $(this).html('loading...');
  330. $(this).unbind('click');
  331. submit_action();
  332. })
  333. }
  334. }
  335. //直接提交更新页的数据
  336. function submit_action()
  337. {
  338. $(".form1").submit();
  339. }
  340. //设置某一个input的值
  341. function set_update(id, value)
  342. {
  343. if($(id).length)
  344. {
  345. $(id).val(value);
  346. }
  347. }
  348. /**
  349. * 批量复制数据
  350. */
  351. function copy_data(e)
  352. {
  353. var html = '<div>';
  354. html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
  355. html += '</div>';
  356. $('#dever_modal_body').html(html);
  357. $('#dever_modal_title').html('复制数据');
  358. $("#dever_modal_yes").unbind('click').bind('click', function()
  359. {
  360. set_update('#copy_num', $("#temp_copy_num").val());
  361. set_update('#update_where_id', 0);
  362. submit_action();
  363. });
  364. }
  365. //头部菜单
  366. function topMenu(e)
  367. {
  368. var p = e.parent().parent().parent().find('span');
  369. p.html(e.html());
  370. //更新当前的精细权限
  371. var url = config.host + 'top.update_action?json=1';
  372. var id = e.attr('data-id');
  373. $.post(url, {id:id}, function(t)
  374. {
  375. var href = location.href;
  376. if(location.href.indexOf('where_id') != -1)
  377. {
  378. var temp = location.href.split('where_id');
  379. href = temp[0] + 'where_id=' + t;
  380. }
  381. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  382. {
  383. pjax({url: href, container: config.layout})
  384. }
  385. else
  386. {
  387. location.href = href;
  388. }
  389. })
  390. }
  391. //更新页面的批量载入选择
  392. function loadShow()
  393. {
  394. if($(".show_input").length)
  395. {
  396. $(".show_input input").each(function()
  397. {
  398. if($(this).attr('checked'))
  399. {
  400. inputShow($(this), $(this).attr('show_id'), 'input');
  401. }
  402. })
  403. $(".show_input select").each(function()
  404. {
  405. if($(this).find('option:selected').text())
  406. {
  407. inputShow($(this), $(this).attr('show_id'));
  408. }
  409. })
  410. }
  411. }
  412. function inputShow(e,n,t)
  413. {
  414. $(".show_" + n).hide();
  415. var array = ['input', 'textarea'];
  416. for(var a in array)
  417. {
  418. if ($(".show_" + n).find(array[a]).length) {
  419. var c = $(".show_" + n).find(array[a]).attr('class');
  420. if (c.indexOf('validate[required]') > -1) {
  421. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  422. }
  423. }
  424. }
  425. if (t == 'input') {
  426. var item = e.parent().find('input');
  427. item.each(function()
  428. {
  429. if($(this).get(0).checked == true)
  430. {
  431. inputShowOne($(this),n);
  432. }
  433. });
  434. } else {
  435. var item = e.parent().find('select');
  436. item.each(function()
  437. {
  438. if($(this).find('option:selected').text())
  439. {
  440. inputShowOne($(this),n);
  441. }
  442. });
  443. }
  444. }
  445. function inputShowOne(e,n)
  446. {
  447. var value = e.val();
  448. var ele = '.show_' + n + '_ajax';
  449. if ($(ele).length) {
  450. $(ele).each(function()
  451. {
  452. var self = $(this);
  453. var url = self.attr('dever-ajax');
  454. $.getJSON(url + value + '&callback=?', function(t) {
  455. self.find('.margin-top').html(t.data);
  456. inputShowOneValiDate(self);
  457. checkbox();
  458. })
  459. })
  460. } else {
  461. ele = '.show_' + n + '_' + value;
  462. inputShowOneValiDate($(ele));
  463. }
  464. }
  465. function inputShowOneValiDate(e)
  466. {
  467. e.show();
  468. var array = ['input', 'textarea'];
  469. for(var a in array)
  470. {
  471. if(e.length && e.attr('class').indexOf('show_no') == -1)
  472. {
  473. e.find(array[a]).each(function()
  474. {
  475. var parent = $(this).parent();
  476. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  477. {
  478. $(this).addClass('validate[required]');
  479. }
  480. })
  481. }
  482. }
  483. }
  484. //批量更新
  485. function list_mul(e)
  486. {
  487. var type = parseInt($("#mul_type").val());
  488. if(type != 1 && type != 2)
  489. {
  490. alert('您还没有选择数据更新方式');
  491. return;
  492. }
  493. layer.confirm('确定进行此项操作吗?', function()
  494. {
  495. $('#method').val('mul');
  496. $('#function').val('msg');
  497. $('#form1').attr('target', 'f1').submit();
  498. })
  499. }
  500. //搜索
  501. function list_search(e)
  502. {
  503. $('#method').val('search');
  504. $('#function').val('');
  505. $('#form1').attr('target', '').submit();
  506. }
  507. //更新数据
  508. function update(e, id, project, table, notice)
  509. {
  510. var call = function()
  511. {
  512. var col = e.attr('name').replace('up_col_', '');
  513. var value = e.val();
  514. var old = e.attr('data-old');
  515. var url = config.host + 'database.update_action?json=1';
  516. $.post(url, {where_id:id,col:col,value:value,project:project,table:table}, function(t)
  517. {
  518. var t = eval('('+t+')');
  519. if (t.status == 1) {
  520. e.attr('data-old', value);
  521. notify('操作已成功!您的操作已修改当前选项!');
  522. preview();
  523. } else {
  524. msg(t);
  525. e.val(old);
  526. }
  527. })
  528. }
  529. if(notice)
  530. {
  531. layer.confirm(notice, function()
  532. {
  533. call();
  534. });
  535. }
  536. else
  537. {
  538. call();
  539. }
  540. }
  541. function notify(msg)
  542. {
  543. var notice = new PNotify({
  544. title: '提示信息',
  545. text: msg,
  546. buttons: {
  547. closer: false,
  548. sticker: false
  549. }
  550. });
  551. notice.get().click(function() {
  552. notice.remove();
  553. });
  554. }
  555. //模板选择
  556. function template()
  557. {
  558. if(config.template)
  559. {
  560. $('body').attr('class', 'theme-' + config.template);
  561. }
  562. if($(".selector").length)
  563. {
  564. $(".selector").each(function()
  565. {
  566. if($(this).data('check') == 'checked')
  567. {
  568. selector($(this));
  569. }
  570. })
  571. }
  572. }
  573. //选择器
  574. function selector(e)
  575. {
  576. var value = e.data('value');
  577. var name = e.data('name');
  578. $('#'+name+'_value').val(value);
  579. $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
  580. e.children().css({'border':'1px solid black'});
  581. if(name == 'update_template')
  582. {
  583. $('body').attr('class', 'theme-' + value);
  584. }
  585. }
  586. //根据e的值,来载入其他数据
  587. function loading(e, data)
  588. {
  589. var value = e.val();
  590. if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
  591. {
  592. var id = e.attr('id').replace('_temp', '');
  593. if($('#' + id).length)
  594. {
  595. var value = $('#' + id).val();
  596. }
  597. }
  598. if(data.element)
  599. {
  600. if(data.url)
  601. {
  602. data.value = value;
  603. $.getJSON(data.url, data, function(t)
  604. {
  605. $('#update_'+data.element+'_value').val(t.data);
  606. });
  607. }
  608. else
  609. {
  610. $('#update_'+data.element+'_value').val(value);
  611. }
  612. }
  613. else if(data.url)
  614. {
  615. data.value = value;
  616. data.where_id = $('#update_where_id').val();
  617. data.table = $('#table').val();
  618. data.project = $('#project').val();
  619. $.getJSON(data.url, data, function(s)
  620. {
  621. t = s.data;
  622. if(t.indexOf('onblur') != -1)
  623. {
  624. eval(t);
  625. }
  626. else
  627. {
  628. var parent = e.parent().parent();
  629. if(t.indexOf('status') == -1)
  630. {
  631. if(data.type == 1)
  632. {
  633. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  634. {
  635. $(this).remove();
  636. });
  637. }
  638. else
  639. {
  640. $('.checking_-1,.checking_3,.checking_4').each(function()
  641. {
  642. $(this).remove();
  643. });
  644. }
  645. parent.after(t);
  646. checkbox();
  647. }
  648. }
  649. });
  650. }
  651. }
  652. //根据e的值,来载入其他数据,先检测是否选中
  653. function checking(name, e, data)
  654. {
  655. var value = [];
  656. $('.' + name).each(function()
  657. {
  658. if($(this).get(0).checked == true)
  659. {
  660. value.push($(this).val());
  661. }
  662. });
  663. if(data.url)
  664. {
  665. data.value = value.join(',');
  666. data.where_id = $('#update_where_id').val();
  667. data.table = $('#table').val();
  668. data.project = $('#project').val();
  669. if(data.check)
  670. {
  671. data.check_value = false;
  672. $(data.check).each(function()
  673. {
  674. if($(this).get(0).checked == true)
  675. {
  676. data.check_value = $(this).val();
  677. }
  678. });
  679. }
  680. $.getJSON(data.url, data, function(s)
  681. {
  682. t = s.data;
  683. var parent = e.parent().parent().parent();
  684. if(t.indexOf('status') == -1)
  685. {
  686. if(data.type == 1)
  687. {
  688. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  689. {
  690. $(this).remove();
  691. });
  692. }
  693. else
  694. {
  695. $('.checking_-1,.checking_3,.checking_4').each(function()
  696. {
  697. $(this).remove();
  698. });
  699. }
  700. parent.after(t);
  701. checkbox();
  702. }
  703. });
  704. }
  705. }
  706. function autocomplete()
  707. {
  708. if ($("input").length) {
  709. $("input").each(function()
  710. {
  711. $(this).attr('autocomplete', 'new-password');
  712. });
  713. }
  714. if($("input[complete]").length)
  715. {
  716. $("input[complete]").each(function()
  717. {
  718. var cache = {};
  719. var self = $(this);
  720. self.autocomplete(
  721. {
  722. minLength: 2,
  723. source: function( request, response )
  724. {
  725. var term = request.term.split( /,\s*/ );
  726. request.term = term.pop();
  727. if ( request.term in cache ) {
  728. response( cache[ request.term ] );
  729. return;
  730. }
  731. var cate = self.attr('complete_cate');
  732. if (cate) {
  733. request[cate] = $('update_' + cate + '_value').val();
  734. }
  735. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  736. data = data.data
  737. cache[ term ] = data;
  738. var state = true;
  739. for(var i in data)
  740. {
  741. if(data[i].id <=0)
  742. {
  743. state = false;
  744. }
  745. }
  746. if(state)
  747. {
  748. response( data );
  749. }
  750. });
  751. },
  752. focus: function() {
  753. // prevent value inserted on focus
  754. return false;
  755. },
  756. select: function( event, ui )
  757. {
  758. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  759. var value = self.attr('complete_callback');
  760. var id = self.attr('id').replace('_temp', '');
  761. var name = self.attr('name').replace('_temp', '');
  762. //var e = $("#" + id);
  763. var e = self;
  764. var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
  765. if (!$("#" + id + '_show').length) {
  766. e.parent().append(html);
  767. }
  768. if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
  769. {
  770. var link = '';
  771. var attr = '';
  772. var pic = '';
  773. if (ui.item['pic']) {
  774. pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
  775. }
  776. if (ui.item['link']) {
  777. link = ui.item['link'];
  778. attr = ' target="_blank"';
  779. }
  780. var html = '<tr><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+ui.item[value]+'"/>&nbsp;&nbsp;'+pic+'<a href="'+link+'" '+attr+' title="'+ui.item.value+'">'+ui.item.value+'</td><td width="10%"><a href="javascript:;" onclick="autocomplete_del($(this), \''+id+'\', \''+ui.item[value]+'\', \''+name+'\')">[删除]</a></td></tr>';
  781. $("#" + id + '_show').append(html);
  782. if (!autocomplete_value[id]) {
  783. autocomplete_value[id] = [];
  784. }
  785. autocomplete_value[id].push(ui.item[value]);
  786. }
  787. ui.item.value = '';
  788. }
  789. });
  790. })
  791. }
  792. }
  793. function autocomplete_del(e, id, value)
  794. {
  795. e.parent().parent().remove();
  796. autocomplete_value[id].remove(value);
  797. var len = autocomplete_value.length;
  798. if (len < 1 && !($('#del_' + name).length)) {
  799. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  800. }
  801. }
  802. function searchbox(id, e)
  803. {
  804. var self = e.parent().find("input");
  805. var v = self.val();
  806. var key = self.attr('id').replace('_temp', '');
  807. var request = {};
  808. request.term = v;
  809. var cate = self.attr('searchbox_cate');
  810. if (cate) {
  811. var c = cate.split(',');
  812. for (var i in c) {
  813. if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
  814. request[c[i]] = $('#'+c[i]).val();
  815. }
  816. }
  817. }
  818. var index = layer.msg('加载中...');
  819. $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
  820. layer.close(index);
  821. var data = data.data;
  822. if (!data) {
  823. showAlert('没有搜索到数据');
  824. return;
  825. }
  826. var html = '<div class="layui-tab layui-tab-brief"" overflow><ul class="layui-tab-title" style="height: 60px; overflow: auto;">{cate}</ul><div class="layui-tab-content" style="padding-top: 0px;">{content}</div><div style="margin-left:10px"><input type="checkbox" onclick="searchbox_checkall($(this), \'searchbox_'+id+'\')"/>&nbsp;全选<button type="button" onclick="searchbox_yes(\''+self.attr('id')+'\', \'.searchbox_'+id+'\', true)" class="btn btn-primary layui-btn layuiadmin-btn-list" style="margin-left:10px;margin-top: -2px;"><i class="fa fa-save"></i> 确定</button></div></div>';
  827. if (data) {
  828. var j = 0;
  829. var c = '';
  830. var s = '';
  831. var cateHtml = '';
  832. var content = '';
  833. for (var i in data) {
  834. if (j == 0) {
  835. c = 'class="layui-this"';
  836. s = 'layui-show';
  837. } else {
  838. c = '';
  839. s = '';
  840. }
  841. cateHtml += '<li '+c+'>'+data[i].name+'</li>';
  842. j++;
  843. var item = '<div class="layui-tab-item '+s+'"><div style="margin-top: 10px;overflow: auto;max-height: 500px;"><table class="table table-small-font table-bordered">{head}';
  844. var p = false;
  845. for (var k in data[i].child) {
  846. if (data[i].child[k].name) {
  847. var pic = '';
  848. if (data[i].child[k].pic) {
  849. pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
  850. p = true;
  851. }
  852. var check = '';
  853. if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
  854. check = 'checked';
  855. }
  856. item += '<tr><td width="10%"><input '+check+' type="checkbox" onclick="searchbox_checkone($(this), \''+self.attr('id')+'\', \''+key+'\', '+data[i].child[k].id+', \''+key+'\')" class="searchbox_'+id+' searchbox_'+id+'_'+data[i].id+'" data-class="searchbox_'+id+'_'+data[i].id+'" data-pic="'+data[i].child[k].pic+'" data-name="'+data[i].child[k].name+'" data-value="'+data[i].child[k].id+'" data-link="'+data[i].child[k].link+'" value="'+data[i].child[k].id+'"/></td>'+pic+'<td><a href="" >'+data[i].child[k].name+'</td></tr>';
  857. }
  858. }
  859. item += '</table></div></div>';
  860. var head = '<tr><td width="10%"><input type="checkbox" class="searchbox_'+id+'" onclick="searchbox_checkall($(this), \'searchbox_'+id+'_'+data[i].id+'\')"/></td><td>标题</td></tr>';
  861. if (p) {
  862. head = head.replace('</td><td>', '</td><td>图片</td><td>');
  863. }
  864. item = item.replace('{head}', head);
  865. content += item;
  866. }
  867. if (cateHtml) {
  868. html = html.replace('{cate}', cateHtml);
  869. }
  870. if (content) {
  871. html = html.replace('{content}', content);
  872. }
  873. }
  874. var config = {
  875. type: 1,
  876. shade: 0.3,
  877. title : false,
  878. shadeClose : true,
  879. area : ['800px', '600px'],
  880. content: html
  881. };
  882. layer.open(config);
  883. layui.use('element', function(){
  884. var element = layui.element;
  885. });
  886. });
  887. }
  888. function searchbox_checkall(e, id)
  889. {
  890. $('.' + id).each(function()
  891. {
  892. $(this).get(0).checked = e.get(0).checked;
  893. //$(this).click();
  894. })
  895. }
  896. function searchbox_checkone(e, id, key, value)
  897. {
  898. if (!e.get(0).checked) {
  899. $('#searchbox_check_' + key + '_' + value).remove();
  900. searchbox_value.remove(value);
  901. var len = searchbox_value.length;
  902. var name = key.replace('_value', '');
  903. if (len < 1 && !($('#del_' + name).length)) {
  904. $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  905. }
  906. } else {
  907. var c = '.' + e.attr('data-class');
  908. searchbox_yes(id, c, false);
  909. }
  910. }
  911. function searchbox_yes(e, c, state)
  912. {
  913. var self = $("#" +e);
  914. $(c).each(function()
  915. {
  916. if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
  917. var value = self.attr('searchbox_callback');
  918. var id = self.attr('id').replace('_temp', '');
  919. var name = self.attr('name').replace('_temp', '');
  920. var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
  921. if (!$("#" + id + '_show').length) {
  922. self.parent().append(html);
  923. }
  924. if (!$("#" + id + '_show').find('#searchbox_check_'+id+'_'+$(this).attr('data-value')).length)
  925. {
  926. var link = '';
  927. var attr = '';
  928. var pic = '';
  929. if ($(this).attr('data-pic') && $(this).attr('data-pic') != 'undefined') {
  930. pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
  931. }
  932. if ($(this).attr('data-link')) {
  933. link = $(this).attr('data-link');
  934. attr = ' target="_blank"';
  935. }
  936. var html = '<tr id="searchbox_check_'+id+'_'+$(this).attr('data-value')+'"><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+$(this).attr('data-value')+'"/>&nbsp;&nbsp;'+pic+'<a href="'+link+'" '+attr+' title="'+$(this).attr('data-name')+'">'+$(this).attr('data-name')+'</td><td width="10%"><a href="javascript:;" onclick="searchbox_del($(this), \''+id+'\', \''+$(this).attr('data-value')+'\', \''+name+'\')">[删除]</a></td></tr>';
  937. $("#" + id + '_show').append(html);
  938. if (!searchbox_value[id]) {
  939. searchbox_value[id] = [];
  940. }
  941. searchbox_value[id].push($(this).attr('data-value'));
  942. }
  943. }
  944. })
  945. if (state == true) {
  946. layer.closeAll();
  947. }
  948. }
  949. function searchbox_del(e, id, value, name)
  950. {
  951. e.parent().parent().remove();
  952. searchbox_value.remove(value);
  953. var len = searchbox_value.length;
  954. if (len < 1 && !($('#del_' + name).length)) {
  955. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  956. }
  957. }
  958. //后台通用的提示
  959. function msg(value)
  960. {
  961. $("#dever_modal_no").click();
  962. if(!value.data)
  963. {
  964. value.data = value.msg;
  965. }
  966. if(value == 1)
  967. {
  968. location.reload();
  969. return;
  970. }
  971. submit();
  972. var url = '';
  973. if(value.data != 'reload' && value.status == 2)
  974. {
  975. showAlert(value.msg, false, '错误提示');
  976. //alert(value.data);
  977. //location.reload();
  978. return;
  979. }
  980. else if(value.data == 'reload')
  981. {
  982. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  983. {
  984. pjax({url: location.href, container: config.layout})
  985. }
  986. else
  987. {
  988. location.reload();
  989. }
  990. return;
  991. }
  992. else
  993. {
  994. if(value.data.indexOf('http://') != -1)
  995. {
  996. url = value.data;
  997. }
  998. else if($("#url").length)
  999. {
  1000. url = $("#url").val();
  1001. }
  1002. else
  1003. {
  1004. notify(value.data)
  1005. return;
  1006. }
  1007. if(url)
  1008. {
  1009. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1010. {
  1011. pjax({url: url, container: config.layout});
  1012. }
  1013. else
  1014. {
  1015. location.href = url;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1021. {
  1022. pjax({url: location.href, container: config.layout});
  1023. }
  1024. else
  1025. {
  1026. location.reload();
  1027. }
  1028. }
  1029. }
  1030. return;
  1031. }
  1032. /**
  1033. * 处理多选问题,处理全选按钮
  1034. */
  1035. function checkbox()
  1036. {
  1037. if($(".autoload").length)
  1038. {
  1039. $(".autoload").each(function()
  1040. {
  1041. if($(this).get(0).checked == true)
  1042. {
  1043. $(this).removeClass('autoload');
  1044. $(this).load();
  1045. }
  1046. });
  1047. }
  1048. if($(".autoload_text").length)
  1049. {
  1050. $(".autoload_text").each(function()
  1051. {
  1052. if($(this).val())
  1053. {
  1054. $(this).removeClass('autoload_text');
  1055. $(this).load();
  1056. }
  1057. });
  1058. }
  1059. var name = 'checkbox-checkall';
  1060. var checkbox = $("." + name);
  1061. if(checkbox.length)
  1062. {
  1063. checkbox.unbind('click').bind('click', function()
  1064. {
  1065. var self = $(this);
  1066. $("." + name + "-" + self.val()).each(function()
  1067. {
  1068. $(this).get(0).checked = self.get(0).checked;
  1069. var next = $(this).next();
  1070. if($(this).get(0).checked == true)
  1071. {
  1072. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1073. {
  1074. next.attr('disabled', false);
  1075. }
  1076. if($("#mul_type").length)
  1077. {
  1078. $("#mul_type").val(1);
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1084. {
  1085. next.attr('disabled', true);
  1086. }
  1087. if($("#mul_type").length)
  1088. {
  1089. $("#mul_type").val(0);
  1090. }
  1091. }
  1092. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1093. inputShow($(this), 'col');
  1094. }
  1095. })
  1096. });
  1097. checkbox.each(function()
  1098. {
  1099. var self = $(this);
  1100. var len = $("." + name + "-" + self.val()).length;
  1101. $("." + name + "-" + self.val()).each(function()
  1102. {
  1103. $(this).unbind('click').bind('click', function()
  1104. {
  1105. var next = $(this).next();
  1106. if($(this).get(0).checked == true)
  1107. {
  1108. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1109. self.get(0).checked = true;
  1110. }
  1111. if(self.attr('type') == 'radio')
  1112. {
  1113. //如果父选项是radio类型,做下限制
  1114. //alert(1);
  1115. }
  1116. if($("#mul_type").length)
  1117. {
  1118. $("#mul_type").val(1);
  1119. }
  1120. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1121. {
  1122. next.attr('disabled', false);
  1123. }
  1124. }
  1125. else
  1126. {
  1127. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1128. {
  1129. next.attr('disabled', true);
  1130. }
  1131. }
  1132. var num = 0;
  1133. $("." + name + "-" + self.val()).each(function()
  1134. {
  1135. if($(this).get(0).checked == true)
  1136. {
  1137. num = 1;
  1138. }
  1139. });
  1140. var id = $(this).attr('name');
  1141. var hidden = id;
  1142. id = id.replace('[]', '');
  1143. if(num == 0)
  1144. {
  1145. self.get(0).checked = false;
  1146. if($("#mul_type").length)
  1147. {
  1148. $("#mul_type").val(0);
  1149. }
  1150. if (!$('#' + id).length) {
  1151. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  1152. }
  1153. } else {
  1154. if ($('#' + id).length) {
  1155. $('#' + id).remove();
  1156. }
  1157. }
  1158. })
  1159. if($(this).get(0).checked == true)
  1160. {
  1161. self.get(0).checked = true;
  1162. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1163. inputShow($(this), 'col');
  1164. }
  1165. }
  1166. });
  1167. })
  1168. }
  1169. }
  1170. /**
  1171. * 处理双击编辑
  1172. */
  1173. function edit()
  1174. {
  1175. if($(".edit").length)
  1176. {
  1177. $(".edit").each(function()
  1178. {
  1179. $(this).bind('dblclick', function()
  1180. {
  1181. var col = $(this).attr('data-col');
  1182. var project = $(this).attr('data-project');
  1183. var table = $(this).attr('data-table');
  1184. var url = $(this).attr('data-url');
  1185. var id = $(this).attr('data-id');
  1186. var html = $(this).attr('data-content');
  1187. var type = $(this).attr('data-type');
  1188. if($(this).find(".edit-content").length)
  1189. {
  1190. html = $(this).find(".edit-content").html();
  1191. html = html.replace('<!--', '<');
  1192. html = html.replace('-->', '>');
  1193. }
  1194. if(html.indexOf('input') == -1)
  1195. {
  1196. if(type && type == 'textarea')
  1197. {
  1198. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1199. }
  1200. else
  1201. {
  1202. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1203. }
  1204. var self = $(this);
  1205. self.find("#edit").blur(function()
  1206. {
  1207. var value = self.find("#edit").val();
  1208. if(!value)
  1209. {
  1210. alert('不能为空');
  1211. return;
  1212. }
  1213. if($(this).find(".edit-content").length)
  1214. {
  1215. $(this).find(".edit-content").html(value);
  1216. }
  1217. else
  1218. {
  1219. self.attr('data-content', value);
  1220. }
  1221. self.html(value);
  1222. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1223. {
  1224. notify('修改成功');
  1225. preview();
  1226. /*
  1227. if(type && type == 'textarea')
  1228. {
  1229. self.html(t);
  1230. }
  1231. */
  1232. })
  1233. })
  1234. }
  1235. });
  1236. })
  1237. }
  1238. }
  1239. function preview()
  1240. {
  1241. if($("#preview").length)
  1242. {
  1243. var time = Date.parse(new Date());
  1244. var src = $('#preview').attr('src').split('#');
  1245. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1246. }
  1247. }
  1248. function del()
  1249. {
  1250. if($(".oper_delete").length)
  1251. {
  1252. $(".oper_delete").each(function()
  1253. {
  1254. var href = $(this).attr('href');
  1255. $(this).attr('href', '#');
  1256. $(this).unbind('click');
  1257. $(this).bind('click', function()
  1258. {
  1259. del_act(href);
  1260. });
  1261. })
  1262. }
  1263. }
  1264. /**
  1265. * 处理删除
  1266. */
  1267. function del_act(href)
  1268. {
  1269. layer.confirm('确定进行此项操作吗?', function()
  1270. {
  1271. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1272. {
  1273. msg(t);
  1274. })
  1275. });
  1276. }
  1277. /**
  1278. * 处理特殊加载的按钮
  1279. */
  1280. function load(href)
  1281. {
  1282. layer.confirm('确定进行此项操作吗?', function()
  1283. {
  1284. if(href.indexOf('&') == -1)
  1285. {
  1286. href += '?json=1&callback=?';
  1287. }
  1288. else
  1289. {
  1290. href += '&json=1&callback=?';
  1291. }
  1292. $.getJSON(href, {}, function(t)
  1293. {
  1294. msg(t);
  1295. //location.reload();
  1296. })
  1297. })
  1298. /*
  1299. showAlert('确定进行此项操作吗?', function()
  1300. {
  1301. $("#dever_modal_no").click();
  1302. $.getJSON(href + '&json=1', {}, function(t)
  1303. {
  1304. msg(t);
  1305. })
  1306. });
  1307. */
  1308. }
  1309. /**
  1310. * 处理特殊加载的按钮
  1311. */
  1312. function jump(href, form)
  1313. {
  1314. if (form) {
  1315. var param = formData(form);
  1316. href += param[1];
  1317. }
  1318. location.href = href;
  1319. }
  1320. /**
  1321. * 处理change
  1322. */
  1323. function change()
  1324. {
  1325. if($(".change").length)
  1326. {
  1327. $(".change").each(function()
  1328. {
  1329. var key = $(this).attr('data-child');
  1330. /*
  1331. $('.' + key).each(function()
  1332. {
  1333. if($(this).find('select option:selected').val())
  1334. {
  1335. $(this).show();
  1336. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1337. }
  1338. });
  1339. */
  1340. $(this).change(function()
  1341. {
  1342. $('.' + key).hide();
  1343. var v = $('.' + key + '_' + $(this).val());
  1344. var s = v.find('select');
  1345. s.change(function()
  1346. {
  1347. $('.' + key + '_value').val($(this).val());
  1348. })
  1349. if(v.length)
  1350. {
  1351. $('.' + key + '_value').val(s.val());
  1352. v.show();
  1353. }
  1354. else
  1355. {
  1356. $('.' + key + '_value').val(-1);
  1357. }
  1358. });
  1359. if($(this).val() > 0)
  1360. {
  1361. $(this).change();
  1362. }
  1363. });
  1364. }
  1365. }
  1366. /**
  1367. * 处理图库系统
  1368. */
  1369. function image()
  1370. {
  1371. if($(".dever-note").length)
  1372. {
  1373. $(".dever-note").each(function()
  1374. {
  1375. var key = $(this).attr('key');
  1376. $(this).inlineattachment(
  1377. {
  1378. uploadUrl: config.upload + '.drag?key='+ key
  1379. });
  1380. });
  1381. }
  1382. if($(".image_upload").length)
  1383. {
  1384. $(".image_upload").each(function(i)
  1385. {
  1386. var parent = $(this).parent().parent();
  1387. //alert(parent.attr('id'));
  1388. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1389. {
  1390. return;
  1391. }
  1392. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1393. })
  1394. }
  1395. }
  1396. /**
  1397. * 修改密码
  1398. */
  1399. function pass(e)
  1400. {
  1401. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1402. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  1403. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  1404. html += '</div>';
  1405. var edit = function()
  1406. {
  1407. var old_password = $("#edit_old_password").val();
  1408. var new_password = $("#edit_new_password").val();
  1409. if(!old_password || !new_password)
  1410. {
  1411. alert('请输入密码');
  1412. return;
  1413. }
  1414. if(old_password == new_password)
  1415. {
  1416. alert('旧密码和新密码相同');
  1417. return;
  1418. }
  1419. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1420. {
  1421. alert(t);
  1422. })
  1423. };
  1424. showAlert(html, edit, '修改密码');
  1425. /*
  1426. $('#dever_modal_body').html(html);
  1427. $('#dever_modal_title').html('修改密码');
  1428. */
  1429. }
  1430. var MSG = [];
  1431. /**
  1432. * 打开弹窗
  1433. */
  1434. //function showMsg(title, e, id, func)
  1435. function showMsg(title, e, id, func, param)
  1436. {
  1437. if(id.indexOf('http://') == -1)
  1438. {
  1439. if($(id).length)
  1440. {
  1441. var html = $(id).html();
  1442. if($(id).html())
  1443. {
  1444. var html = $(id).html();
  1445. MSG[id] = html;
  1446. $(id).html('');
  1447. }
  1448. else
  1449. {
  1450. var html = MSG[id];
  1451. }
  1452. }
  1453. else
  1454. {
  1455. var html = id;
  1456. }
  1457. showAlert(html, func, title);
  1458. /*
  1459. $('#dever_modal_body').html(html);
  1460. $('#dever_modal_title').html(title);
  1461. if (func) {
  1462. $("#dever_modal_yes").unbind('click').bind('click', func);
  1463. } else {
  1464. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1465. }
  1466. */
  1467. }
  1468. else
  1469. {
  1470. var url = id;
  1471. var send = {};
  1472. if (param) {
  1473. send = param;
  1474. }
  1475. if (e && e.attr('msg-send')) {
  1476. send.data = e.attr('msg-send');
  1477. }
  1478. if (url.indexOf('?') != -1) {
  1479. url = url + '&';
  1480. } else {
  1481. url = url + '?';
  1482. }
  1483. $.getJSON(url+'json=1',send,function(t)
  1484. {
  1485. t = t.data;
  1486. showAlert(t, func, t);
  1487. /*
  1488. $('#dever_modal_body').html(t);
  1489. $('#dever_modal_title').html(title);
  1490. if(func)
  1491. {
  1492. $("#dever_modal_yes").unbind('click').bind('click', func);
  1493. }
  1494. */
  1495. });
  1496. }
  1497. }
  1498. function updateMsg(id)
  1499. {
  1500. $("#"+id).submit();
  1501. }
  1502. function showAlert(msg, func, title)
  1503. {
  1504. if (!title) {
  1505. title = $("#dever-name").html() + '提醒您';
  1506. }
  1507. var type = 0;
  1508. if (msg.indexOf('<') != -1) {
  1509. type = 1;
  1510. }
  1511. var config = {
  1512. type: 0,
  1513. title: title,
  1514. shade: 0,
  1515. shadeClose : true,
  1516. content: msg
  1517. };
  1518. if (type == 1) {
  1519. config.area = '500px';
  1520. }
  1521. if (func) {
  1522. config.yes = function()
  1523. {
  1524. func();
  1525. };
  1526. }
  1527. layer.open(config);
  1528. }
  1529. function fastEdit(e, url, title, col)
  1530. {
  1531. var func = function()
  1532. {
  1533. submit_action();
  1534. };
  1535. var send = {};
  1536. send.col = col;
  1537. $.get(url,send,function(t)
  1538. {
  1539. var html = $(t).find('form').prop("outerHTML");
  1540. var valid = $(t).find('#valid').prop("outerHTML");
  1541. html = html + valid;
  1542. showAlert(html, func, title);
  1543. $('#update_button').hide();
  1544. init();
  1545. });
  1546. }
  1547. /*
  1548. var test =
  1549. {
  1550. refreshPage: false,
  1551. addAjaxFlag: true,
  1552. //添加收藏
  1553. add: function(cfg)
  1554. {
  1555. }
  1556. }
  1557. */
  1558. function showToggle(e)
  1559. {
  1560. var id = e.attr('toggle');
  1561. var child = e.attr('toggle_child');
  1562. var parent = e.parent();
  1563. parent.parent().find('li').removeClass('active');
  1564. parent.addClass('active');
  1565. $(child).fadeOut(100);
  1566. $(id).fadeIn(500);
  1567. initEditor($(id).find('.editor'));
  1568. }
  1569. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1570. {
  1571. var e = '#' + id;
  1572. var parent = value.split(',');
  1573. var cur = parent[0];
  1574. parent.remove(cur);
  1575. value = parent.join(',');
  1576. var html = '';
  1577. var old = level;
  1578. if (!total) {
  1579. level_id = 0;
  1580. } else {
  1581. if (level >= total) {
  1582. //$(e).show();
  1583. return;
  1584. }
  1585. level_id = $(e + '_' + level).val();
  1586. level = parseInt(level) + 1;
  1587. }
  1588. $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1589. var check = '';
  1590. if (t.status == 1) {
  1591. var total = t.data.level_total;
  1592. var data = t.data.list;
  1593. if(!$(e + '_' + level).length) {
  1594. html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\');">';
  1595. }
  1596. for (a in data) {
  1597. if (data[a].value) {
  1598. check = '';
  1599. if (cur == data[a].value) {
  1600. check = ' selected';
  1601. }
  1602. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1603. }
  1604. }
  1605. if(!$(e + '_' + level).length) {
  1606. html += '</select><span>&nbsp;&nbsp;</span>';
  1607. $(e).append(html);
  1608. $(e + '_' + level).change();
  1609. } else {
  1610. $(e + '_' + level).html(html);
  1611. $(e + '_' + level).change();
  1612. }
  1613. } else {
  1614. $(e + '_' + old).nextAll('select').remove();
  1615. $(e + '_' + old).next('span').nextAll('span').remove();
  1616. }
  1617. /*
  1618. if ($('#' + name + '_level_value').length) {
  1619. var total = $(id).find('select').length;
  1620. $('#' + name + '_level_value').val(total);
  1621. }
  1622. if ($('#' + name + '_up_value').length) {
  1623. $('#' + name + '_up_value').val($(id + '_-2').val());
  1624. }
  1625. */
  1626. });
  1627. }
  1628. /*
  1629. function select_mul(level, id, url, name, value, valid, w, num)
  1630. {
  1631. if(level == 0)
  1632. {
  1633. $(id).find('select').remove();
  1634. $(id).find('span').remove();
  1635. return;
  1636. }
  1637. var parent = value.split(',');
  1638. var cur = parent[0];
  1639. parent.remove(cur);
  1640. value = parent.join(',');
  1641. var html = '';
  1642. var old = level;
  1643. if(level != -1)
  1644. {
  1645. if($(id + '_' + level).length)
  1646. {
  1647. level = $(id + '_' + level).val();
  1648. }
  1649. alert(level);
  1650. if(level == 0)
  1651. {
  1652. $(id + '_' + old).nextAll('select').remove();
  1653. $(id + '_' + old).next('span').nextAll('span').remove();
  1654. if($('#' + name + '_level_value').length)
  1655. {
  1656. var total = $(id).find('select').length;
  1657. $('#' + name + '_level_value').val(total);
  1658. }
  1659. if(old == -2 && $('#' + name + '_value_value').length)
  1660. {
  1661. $('#' + name + '_value_value').val(level);
  1662. }
  1663. return;
  1664. }
  1665. if(old == -2)
  1666. {
  1667. $(id + '_' + old).nextAll('select').remove();
  1668. $(id + '_' + old).next('span').nextAll('span').remove();
  1669. }
  1670. if($('#' + name + '_value_value').length)
  1671. {
  1672. $('#' + name + '_value_value').val(level);
  1673. }
  1674. }
  1675. var total = $(id).find('select').length;
  1676. if(num > 0 && total >= num)
  1677. {
  1678. return;
  1679. }
  1680. var get = url.replace('{level}', level);
  1681. if(level == -1)
  1682. {
  1683. level = -2;
  1684. }
  1685. if(!$(id + '_' + level).length)
  1686. {
  1687. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1688. {
  1689. var check = '';
  1690. if(t.status == 1)
  1691. {
  1692. html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+' dever-mul-'+name+'_'+level+'" name="'+name+'[]" onchange="select_mul(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+num+');">';
  1693. console.log(t.data);
  1694. for(a in t.data)
  1695. {
  1696. if(t.data[a].value)
  1697. {
  1698. check = '';
  1699. if(cur == t.data[a].value)
  1700. {
  1701. check = ' selected';
  1702. }
  1703. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1704. }
  1705. }
  1706. html += '</select><span>&nbsp;&nbsp;</span>';
  1707. $(id).append(html);
  1708. $(id + '_' + level).change();
  1709. }
  1710. else
  1711. {
  1712. $(id + '_' + old).nextAll('select').remove();
  1713. $(id + '_' + old).next('span').nextAll('span').remove();
  1714. }
  1715. if($('#' + name + '_level_value').length)
  1716. {
  1717. var total = $(id).find('select').length;
  1718. $('#' + name + '_level_value').val(total);
  1719. }
  1720. if($('#' + name + '_up_value').length)
  1721. {
  1722. $('#' + name + '_up_value').val($(id + '_-2').val());
  1723. }
  1724. });
  1725. }
  1726. }
  1727. */
  1728. //处理更新页面的一些功能,写到一起吧
  1729. var dever_update =
  1730. {
  1731. addIndex : 2,
  1732. index : [],
  1733. auto : false,
  1734. save_key : '',
  1735. init : function()
  1736. {
  1737. var self = this;
  1738. self.index = [];
  1739. // 增加整个更新的表单
  1740. if($(".dever_update_add").length)
  1741. {
  1742. $('.dever_update_add').unbind('click').bind('click', function()
  1743. {
  1744. self.add($(this));
  1745. })
  1746. }
  1747. /* 以后再增加 同时更新另外一个表
  1748. if($(".form-add-content").length)
  1749. {
  1750. var url = config.host + 'auth.password';
  1751. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1752. $.get(url, function(t)
  1753. {
  1754. $(".form-add-content").html(t);
  1755. init();
  1756. })
  1757. }
  1758. */
  1759. //增加某一部分表单
  1760. if($(".dever_form_add").length)
  1761. {
  1762. $('.dever_form_add').each(function()
  1763. {
  1764. var key = $.attr('toggle_key');
  1765. if(typeof(self.index[key]) == "undefined")
  1766. {
  1767. self.index[key] = 0;
  1768. }
  1769. $(this).unbind('click').bind('click', function()
  1770. {
  1771. self.append($(this));
  1772. })
  1773. })
  1774. self.del();
  1775. }
  1776. // 开启自动保存
  1777. if($("#struct").length)
  1778. {
  1779. var save = $("#struct").attr('save');
  1780. if(save == 'yes')
  1781. {
  1782. //检测
  1783. self.save_key = location.href + 'test';
  1784. self.check();
  1785. }
  1786. }
  1787. if($('.dever-note').length)
  1788. {
  1789. $('.dever-note').each(function()
  1790. {
  1791. var mditor = new Mditor($(this),{
  1792. fixedHeight:true
  1793. });
  1794. mditor.openPreview();
  1795. })
  1796. }
  1797. },
  1798. save : function()
  1799. {
  1800. //var data = $("#data-1").html();
  1801. var data = [];
  1802. $(".update_value").each(function(i)
  1803. {
  1804. if($(this).attr("update_type") == 'checked')
  1805. {
  1806. data[i] = $(this).get(0).checked;
  1807. }
  1808. else if($(this).attr("update_type") == 'html')
  1809. {
  1810. data[i] = $(this).html();
  1811. }
  1812. else if($(this).attr("update_type") == 'src')
  1813. {
  1814. data[i] = $(this).attr('src');
  1815. }
  1816. else
  1817. {
  1818. data[i] = $(this).val();
  1819. }
  1820. });
  1821. store.set(this.save_key, data.join('|||'));
  1822. //console.info(data);
  1823. },
  1824. recover : function()
  1825. {
  1826. layer.confirm('确定恢复上次保存的数据吗?', function()
  1827. {
  1828. var data = store.get(this.save_key).split('|||');
  1829. if(data)
  1830. {
  1831. var value = $(".update_value");
  1832. for(var k in data)
  1833. {
  1834. var e = value.eq(k);
  1835. if(e.attr('update_type') == 'checked')
  1836. {
  1837. if(data[k] == 'true')
  1838. {
  1839. e.get(0).checked = true;
  1840. }
  1841. else
  1842. {
  1843. e.get(0).checked = false;
  1844. }
  1845. }
  1846. else if(e.attr('update_type') == 'html')
  1847. {
  1848. e.html(data[k]);
  1849. }
  1850. else if(e.attr('update_type') == 'src')
  1851. {
  1852. e.attr('src', data[k]);
  1853. }
  1854. else
  1855. {
  1856. if(e.attr('id'))
  1857. {
  1858. var id = e.attr('id');
  1859. if(typeof(editors[id]) != "undefined")
  1860. {
  1861. editors[id].html(data[k]);
  1862. }
  1863. }
  1864. e.val(data[k]);
  1865. }
  1866. }
  1867. store.set(this.save_key, '');
  1868. this.check();
  1869. }
  1870. })
  1871. },
  1872. check : function()
  1873. {
  1874. var data = store.get(this.save_key);
  1875. var self = this;
  1876. if(data)
  1877. {
  1878. $(".dever_save").unbind('click').bind('click', function()
  1879. {
  1880. self.recover();
  1881. }).show();
  1882. }
  1883. else
  1884. {
  1885. $(".dever_save").hide();
  1886. self.auto = setInterval(function(){self.save()}, 3000);
  1887. }
  1888. },
  1889. del : function()
  1890. {
  1891. var self = this;
  1892. if($(".dever_form_delete").length)
  1893. {
  1894. $('.dever_form_delete').each(function()
  1895. {
  1896. $(this).unbind('click').bind('click', function()
  1897. {
  1898. var parent = $(this).parent();
  1899. var id = parent.attr('id');
  1900. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1901. var key = $('#tab-' + id).attr('toggle_key');
  1902. if(index <= 1 && self.index[key] <= index)
  1903. {
  1904. }
  1905. else if(index <= 1 && self.index[key] > index)
  1906. {
  1907. index = index+1;
  1908. $("#tab-"+key+"-child-" + index).click();
  1909. }
  1910. else
  1911. {
  1912. index = index-1;
  1913. $("#tab-"+key+"-child-" + index).click();
  1914. };
  1915. $('#tab-' + id).parent().remove();
  1916. parent.remove();
  1917. self.index[key]--;
  1918. })
  1919. })
  1920. }
  1921. },
  1922. append : function(e)
  1923. {
  1924. var self = this;
  1925. var key = e.attr('toggle_key');
  1926. var child = '.dever_'+key+'_child';
  1927. if(typeof(self.index[key]) == "undefined")
  1928. {
  1929. self.index[key] = 0;
  1930. }
  1931. if(self.index[key] <= 0)
  1932. {
  1933. self.index[key] = $(child).length;
  1934. }
  1935. if(self.index[key] > 30)
  1936. {
  1937. layer.showAlert('最多只能增加30条');
  1938. return;
  1939. }
  1940. var p = e.parent();
  1941. var id = key + '-child-' + self.index[key];
  1942. var name = '第' + (self.index[key]) + '条';
  1943. p.before('<li><a href="javascript:;" id="tab-'+id+'" toggle_key="'+key+'" toggle_id="'+self.index[key]+'" toggle_child="'+child+'" toggle="#'+id+'" onclick="showToggle($(this))">'+name+'</a></li>');
  1944. var e = e.parent().parent();
  1945. var n = e.next();
  1946. var p = e.parent();
  1947. var content = n.html();
  1948. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1949. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1950. p.append(content);
  1951. if ($("#" + id).find('.ke-container').length >= 1) {
  1952. $("#" + id).find('.ke-container').eq(0).remove();
  1953. }
  1954. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1955. self.del();
  1956. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1957. self.index[key]++;
  1958. image();
  1959. loadShow();
  1960. autocomplete();
  1961. change();
  1962. },
  1963. add : function(e)
  1964. {
  1965. var self = this;
  1966. var p = e.parent();
  1967. var id = 'data-' + this.addIndex;
  1968. var name = '新增数据-' + (this.addIndex-1);
  1969. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1970. var content = $("#content").find('.tab-pane').eq(0).html();
  1971. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1972. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1973. $("#content").append(content);
  1974. $('#update_' + this.addIndex + '__where_id').val('-1');
  1975. this.addIndex++;
  1976. }
  1977. }
  1978. $.fn.pasteEvents = function( delay ) {
  1979. if (delay == undefined) delay = 20;
  1980. return $(this).each(function() {
  1981. var $el = $(this);
  1982. $el.on("paste", function() {
  1983. $el.trigger("prepaste");
  1984. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1985. });
  1986. });
  1987. };
  1988. $("textarea").on("postpaste", function()
  1989. {
  1990. if($(this).val().indexOf('<') != -1)
  1991. {
  1992. $(this).val(toMarkdown($(this).val()));
  1993. }
  1994. }).pasteEvents();