main.js 47 KB

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