main.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  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.prev("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 = split(',');
  805. for (var i in c) {
  806. request[c[i]] = $('update_' + c[i] + '_value').val();
  807. }
  808. }
  809. $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
  810. var data = data.data;
  811. if (!data) {
  812. showAlert('没有搜索到数据');
  813. return;
  814. }
  815. 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>';
  816. if (data) {
  817. var j = 0;
  818. var c = '';
  819. var s = '';
  820. var cateHtml = '';
  821. var content = '';
  822. for (var i in data) {
  823. if (j == 0) {
  824. c = 'class="layui-this"';
  825. s = 'layui-show';
  826. } else {
  827. c = '';
  828. s = '';
  829. }
  830. cateHtml += '<li '+c+'>'+data[i].name+'</li>';
  831. j++;
  832. 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}';
  833. var p = false;
  834. for (var k in data[i].child) {
  835. if (data[i].child[k].name) {
  836. var pic = '';
  837. if (data[i].child[k].pic) {
  838. pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
  839. p = true;
  840. }
  841. var check = '';
  842. if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
  843. check = 'checked';
  844. }
  845. 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>';
  846. }
  847. }
  848. item += '</table></div></div>';
  849. 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>';
  850. if (p) {
  851. head = head.replace('</td><td>', '</td><td>图片</td><td>');
  852. }
  853. item = item.replace('{head}', head);
  854. content += item;
  855. }
  856. if (cateHtml) {
  857. html = html.replace('{cate}', cateHtml);
  858. }
  859. if (content) {
  860. html = html.replace('{content}', content);
  861. }
  862. }
  863. var config = {
  864. type: 1,
  865. shade: 0.3,
  866. title : false,
  867. shadeClose : true,
  868. area : ['500px', 'auto'],
  869. content: html
  870. };
  871. layer.open(config);
  872. });
  873. }
  874. function searchbox_checkall(e, id)
  875. {
  876. $('.' + id).each(function()
  877. {
  878. $(this).get(0).checked = e.get(0).checked;
  879. //$(this).click();
  880. })
  881. }
  882. function searchbox_checkone(e, id, key, value)
  883. {
  884. if (!e.get(0).checked) {
  885. $('#searchbox_check_' + key + '_' + value).remove();
  886. searchbox_value.remove(value);
  887. var len = searchbox_value.length;
  888. var name = key.replace('_value', '');
  889. if (len < 1 && !($('#del_' + name).length)) {
  890. $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  891. }
  892. } else {
  893. var c = '.' + e.attr('data-class');
  894. searchbox_yes(id, c, false);
  895. }
  896. }
  897. function searchbox_yes(e, c, state)
  898. {
  899. var self = $("#" +e);
  900. $(c).each(function()
  901. {
  902. if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
  903. var value = self.attr('searchbox_callback');
  904. var id = self.attr('id').replace('_temp', '');
  905. var name = self.attr('name').replace('_temp', '');
  906. 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>';
  907. if (!$("#" + id + '_show').length) {
  908. e.parent().append(html);
  909. }
  910. if ($("#" + id + '_show').html().indexOf($(this).attr('data-name')) == -1)
  911. {
  912. var link = '';
  913. var attr = '';
  914. var pic = '';
  915. if ($(this).attr('data-pic')) {
  916. pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
  917. }
  918. if ($(this).attr('data-link')) {
  919. link = $(this).attr('data-link');
  920. attr = ' target="_blank"';
  921. }
  922. 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>';
  923. $("#" + id + '_show').append(html);
  924. if (!searchbox_value[id]) {
  925. searchbox_value[id] = [];
  926. }
  927. searchbox_value[id].push($(this).attr('data-value'));
  928. }
  929. }
  930. })
  931. if (state == true) {
  932. layer.closeAll();
  933. }
  934. }
  935. function searchbox_del(e, id, value, name)
  936. {
  937. e.parent().parent().remove();
  938. searchbox_value.remove(value);
  939. var len = searchbox_value.length;
  940. if (len < 1 && !($('#del_' + name).length)) {
  941. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  942. }
  943. }
  944. //后台通用的提示
  945. function msg(value)
  946. {
  947. $("#dever_modal_no").click();
  948. if(!value.data)
  949. {
  950. value.data = value.msg;
  951. }
  952. if(value == 1)
  953. {
  954. location.reload();
  955. return;
  956. }
  957. submit();
  958. var url = '';
  959. if(value.data != 'reload' && value.status == 2)
  960. {
  961. showAlert(value.msg, false, '错误提示');
  962. //alert(value.data);
  963. //location.reload();
  964. return;
  965. }
  966. else if(value.data == 'reload')
  967. {
  968. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  969. {
  970. pjax({url: location.href, container: config.layout})
  971. }
  972. else
  973. {
  974. location.reload();
  975. }
  976. return;
  977. }
  978. else
  979. {
  980. if(value.data.indexOf('http://') != -1)
  981. {
  982. url = value.data;
  983. }
  984. else if($("#url").length)
  985. {
  986. url = $("#url").val();
  987. }
  988. else
  989. {
  990. notify(value.data)
  991. return;
  992. }
  993. if(url)
  994. {
  995. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  996. {
  997. pjax({url: url, container: config.layout});
  998. }
  999. else
  1000. {
  1001. location.href = url;
  1002. }
  1003. }
  1004. else
  1005. {
  1006. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1007. {
  1008. pjax({url: location.href, container: config.layout});
  1009. }
  1010. else
  1011. {
  1012. location.reload();
  1013. }
  1014. }
  1015. }
  1016. return;
  1017. }
  1018. /**
  1019. * 处理多选问题,处理全选按钮
  1020. */
  1021. function checkbox()
  1022. {
  1023. if($(".autoload").length)
  1024. {
  1025. $(".autoload").each(function()
  1026. {
  1027. if($(this).get(0).checked == true)
  1028. {
  1029. $(this).removeClass('autoload');
  1030. $(this).load();
  1031. }
  1032. });
  1033. }
  1034. if($(".autoload_text").length)
  1035. {
  1036. $(".autoload_text").each(function()
  1037. {
  1038. if($(this).val())
  1039. {
  1040. $(this).removeClass('autoload_text');
  1041. $(this).load();
  1042. }
  1043. });
  1044. }
  1045. var name = 'checkbox-checkall';
  1046. var checkbox = $("." + name);
  1047. if(checkbox.length)
  1048. {
  1049. checkbox.unbind('click').bind('click', function()
  1050. {
  1051. var self = $(this);
  1052. $("." + name + "-" + self.val()).each(function()
  1053. {
  1054. $(this).get(0).checked = self.get(0).checked;
  1055. var next = $(this).next();
  1056. if($(this).get(0).checked == true)
  1057. {
  1058. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1059. {
  1060. next.attr('disabled', false);
  1061. }
  1062. if($("#mul_type").length)
  1063. {
  1064. $("#mul_type").val(1);
  1065. }
  1066. }
  1067. else
  1068. {
  1069. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1070. {
  1071. next.attr('disabled', true);
  1072. }
  1073. if($("#mul_type").length)
  1074. {
  1075. $("#mul_type").val(0);
  1076. }
  1077. }
  1078. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1079. inputShow($(this), 'col');
  1080. }
  1081. })
  1082. });
  1083. checkbox.each(function()
  1084. {
  1085. var self = $(this);
  1086. var len = $("." + name + "-" + self.val()).length;
  1087. $("." + name + "-" + self.val()).each(function()
  1088. {
  1089. $(this).unbind('click').bind('click', function()
  1090. {
  1091. var next = $(this).next();
  1092. if($(this).get(0).checked == true)
  1093. {
  1094. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1095. self.get(0).checked = true;
  1096. }
  1097. if(self.attr('type') == 'radio')
  1098. {
  1099. //如果父选项是radio类型,做下限制
  1100. //alert(1);
  1101. }
  1102. if($("#mul_type").length)
  1103. {
  1104. $("#mul_type").val(1);
  1105. }
  1106. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1107. {
  1108. next.attr('disabled', false);
  1109. }
  1110. }
  1111. else
  1112. {
  1113. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1114. {
  1115. next.attr('disabled', true);
  1116. }
  1117. }
  1118. var num = 0;
  1119. $("." + name + "-" + self.val()).each(function()
  1120. {
  1121. if($(this).get(0).checked == true)
  1122. {
  1123. num = 1;
  1124. }
  1125. });
  1126. var id = $(this).attr('name');
  1127. var hidden = id;
  1128. id = id.replace('[]', '');
  1129. if(num == 0)
  1130. {
  1131. self.get(0).checked = false;
  1132. if($("#mul_type").length)
  1133. {
  1134. $("#mul_type").val(0);
  1135. }
  1136. if (!$('#' + id).length) {
  1137. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  1138. }
  1139. } else {
  1140. if ($('#' + id).length) {
  1141. $('#' + id).remove();
  1142. }
  1143. }
  1144. })
  1145. if($(this).get(0).checked == true)
  1146. {
  1147. self.get(0).checked = true;
  1148. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1149. inputShow($(this), 'col');
  1150. }
  1151. }
  1152. });
  1153. })
  1154. }
  1155. }
  1156. /**
  1157. * 处理双击编辑
  1158. */
  1159. function edit()
  1160. {
  1161. if($(".edit").length)
  1162. {
  1163. $(".edit").each(function()
  1164. {
  1165. $(this).bind('dblclick', function()
  1166. {
  1167. var col = $(this).attr('data-col');
  1168. var project = $(this).attr('data-project');
  1169. var table = $(this).attr('data-table');
  1170. var url = $(this).attr('data-url');
  1171. var id = $(this).attr('data-id');
  1172. var html = $(this).attr('data-content');
  1173. var type = $(this).attr('data-type');
  1174. if($(this).find(".edit-content").length)
  1175. {
  1176. html = $(this).find(".edit-content").html();
  1177. html = html.replace('<!--', '<');
  1178. html = html.replace('-->', '>');
  1179. }
  1180. if(html.indexOf('input') == -1)
  1181. {
  1182. if(type && type == 'textarea')
  1183. {
  1184. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1185. }
  1186. else
  1187. {
  1188. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1189. }
  1190. var self = $(this);
  1191. self.find("#edit").blur(function()
  1192. {
  1193. var value = self.find("#edit").val();
  1194. if(!value)
  1195. {
  1196. alert('不能为空');
  1197. return;
  1198. }
  1199. if($(this).find(".edit-content").length)
  1200. {
  1201. $(this).find(".edit-content").html(value);
  1202. }
  1203. else
  1204. {
  1205. self.attr('data-content', value);
  1206. }
  1207. self.html(value);
  1208. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1209. {
  1210. notify('修改成功');
  1211. preview();
  1212. /*
  1213. if(type && type == 'textarea')
  1214. {
  1215. self.html(t);
  1216. }
  1217. */
  1218. })
  1219. })
  1220. }
  1221. });
  1222. })
  1223. }
  1224. }
  1225. function preview()
  1226. {
  1227. if($("#preview").length)
  1228. {
  1229. var time = Date.parse(new Date());
  1230. var src = $('#preview').attr('src').split('#');
  1231. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1232. }
  1233. }
  1234. function del()
  1235. {
  1236. if($(".oper_delete").length)
  1237. {
  1238. $(".oper_delete").each(function()
  1239. {
  1240. var href = $(this).attr('href');
  1241. $(this).attr('href', '#');
  1242. $(this).unbind('click');
  1243. $(this).bind('click', function()
  1244. {
  1245. del_act(href);
  1246. });
  1247. })
  1248. }
  1249. }
  1250. /**
  1251. * 处理删除
  1252. */
  1253. function del_act(href)
  1254. {
  1255. layer.confirm('确定进行此项操作吗?', function()
  1256. {
  1257. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1258. {
  1259. msg(t);
  1260. })
  1261. });
  1262. }
  1263. /**
  1264. * 处理特殊加载的按钮
  1265. */
  1266. function load(href)
  1267. {
  1268. layer.confirm('确定进行此项操作吗?', function()
  1269. {
  1270. if(href.indexOf('&') == -1)
  1271. {
  1272. href += '?json=1&callback=?';
  1273. }
  1274. else
  1275. {
  1276. href += '&json=1&callback=?';
  1277. }
  1278. $.getJSON(href, {}, function(t)
  1279. {
  1280. msg(t);
  1281. //location.reload();
  1282. })
  1283. })
  1284. /*
  1285. showAlert('确定进行此项操作吗?', function()
  1286. {
  1287. $("#dever_modal_no").click();
  1288. $.getJSON(href + '&json=1', {}, function(t)
  1289. {
  1290. msg(t);
  1291. })
  1292. });
  1293. */
  1294. }
  1295. /**
  1296. * 处理特殊加载的按钮
  1297. */
  1298. function jump(href, form)
  1299. {
  1300. if (form) {
  1301. var param = formData(form);
  1302. href += param[1];
  1303. }
  1304. location.href = href;
  1305. }
  1306. /**
  1307. * 处理change
  1308. */
  1309. function change()
  1310. {
  1311. if($(".change").length)
  1312. {
  1313. $(".change").each(function()
  1314. {
  1315. var key = $(this).attr('data-child');
  1316. /*
  1317. $('.' + key).each(function()
  1318. {
  1319. if($(this).find('select option:selected').val())
  1320. {
  1321. $(this).show();
  1322. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1323. }
  1324. });
  1325. */
  1326. $(this).change(function()
  1327. {
  1328. $('.' + key).hide();
  1329. var v = $('.' + key + '_' + $(this).val());
  1330. var s = v.find('select');
  1331. s.change(function()
  1332. {
  1333. $('.' + key + '_value').val($(this).val());
  1334. })
  1335. if(v.length)
  1336. {
  1337. $('.' + key + '_value').val(s.val());
  1338. v.show();
  1339. }
  1340. else
  1341. {
  1342. $('.' + key + '_value').val(-1);
  1343. }
  1344. });
  1345. if($(this).val() > 0)
  1346. {
  1347. $(this).change();
  1348. }
  1349. });
  1350. }
  1351. }
  1352. /**
  1353. * 处理图库系统
  1354. */
  1355. function image()
  1356. {
  1357. if($(".dever-note").length)
  1358. {
  1359. $(".dever-note").each(function()
  1360. {
  1361. var key = $(this).attr('key');
  1362. $(this).inlineattachment(
  1363. {
  1364. uploadUrl: config.upload + '.drag?key='+ key
  1365. });
  1366. });
  1367. }
  1368. if($(".image_upload").length)
  1369. {
  1370. $(".image_upload").each(function(i)
  1371. {
  1372. var parent = $(this).parent().parent();
  1373. //alert(parent.attr('id'));
  1374. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1375. {
  1376. return;
  1377. }
  1378. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1379. })
  1380. }
  1381. }
  1382. /**
  1383. * 修改密码
  1384. */
  1385. function pass(e)
  1386. {
  1387. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1388. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  1389. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  1390. html += '</div>';
  1391. var edit = function()
  1392. {
  1393. var old_password = $("#edit_old_password").val();
  1394. var new_password = $("#edit_new_password").val();
  1395. if(!old_password || !new_password)
  1396. {
  1397. alert('请输入密码');
  1398. return;
  1399. }
  1400. if(old_password == new_password)
  1401. {
  1402. alert('旧密码和新密码相同');
  1403. return;
  1404. }
  1405. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1406. {
  1407. alert(t);
  1408. })
  1409. };
  1410. showAlert(html, edit, '修改密码');
  1411. /*
  1412. $('#dever_modal_body').html(html);
  1413. $('#dever_modal_title').html('修改密码');
  1414. */
  1415. }
  1416. var MSG = [];
  1417. /**
  1418. * 打开弹窗
  1419. */
  1420. //function showMsg(title, e, id, func)
  1421. function showMsg(title, e, id, func, param)
  1422. {
  1423. if(id.indexOf('http://') == -1)
  1424. {
  1425. if($(id).length)
  1426. {
  1427. var html = $(id).html();
  1428. if($(id).html())
  1429. {
  1430. var html = $(id).html();
  1431. MSG[id] = html;
  1432. $(id).html('');
  1433. }
  1434. else
  1435. {
  1436. var html = MSG[id];
  1437. }
  1438. }
  1439. else
  1440. {
  1441. var html = id;
  1442. }
  1443. showAlert(html, func, title);
  1444. /*
  1445. $('#dever_modal_body').html(html);
  1446. $('#dever_modal_title').html(title);
  1447. if (func) {
  1448. $("#dever_modal_yes").unbind('click').bind('click', func);
  1449. } else {
  1450. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1451. }
  1452. */
  1453. }
  1454. else
  1455. {
  1456. var url = id;
  1457. var send = {};
  1458. if (param) {
  1459. send = param;
  1460. }
  1461. if (e && e.attr('msg-send')) {
  1462. send.data = e.attr('msg-send');
  1463. }
  1464. if (url.indexOf('?') != -1) {
  1465. url = url + '&';
  1466. } else {
  1467. url = url + '?';
  1468. }
  1469. $.getJSON(url+'json=1',send,function(t)
  1470. {
  1471. t = t.data;
  1472. showAlert(t, func, t);
  1473. /*
  1474. $('#dever_modal_body').html(t);
  1475. $('#dever_modal_title').html(title);
  1476. if(func)
  1477. {
  1478. $("#dever_modal_yes").unbind('click').bind('click', func);
  1479. }
  1480. */
  1481. });
  1482. }
  1483. }
  1484. function updateMsg(id)
  1485. {
  1486. $("#"+id).submit();
  1487. }
  1488. function showAlert(msg, func, title)
  1489. {
  1490. if (!title) {
  1491. title = $("#dever-name").html() + '提醒您';
  1492. }
  1493. var type = 0;
  1494. if (msg.indexOf('<') != -1) {
  1495. type = 1;
  1496. }
  1497. var config = {
  1498. type: 0,
  1499. title: title,
  1500. shade: 0,
  1501. shadeClose : true,
  1502. content: msg
  1503. };
  1504. if (type == 1) {
  1505. config.area = '500px';
  1506. }
  1507. if (func) {
  1508. config.yes = function()
  1509. {
  1510. func();
  1511. };
  1512. }
  1513. layer.open(config);
  1514. }
  1515. function fastEdit(e, url, title, col)
  1516. {
  1517. var func = function()
  1518. {
  1519. submit_action();
  1520. };
  1521. var send = {};
  1522. send.col = col;
  1523. $.get(url,send,function(t)
  1524. {
  1525. var html = $(t).find('form').prop("outerHTML");
  1526. var valid = $(t).find('#valid').prop("outerHTML");
  1527. html = html + valid;
  1528. showAlert(html, func, title);
  1529. $('#update_button').hide();
  1530. init();
  1531. });
  1532. }
  1533. /*
  1534. var test =
  1535. {
  1536. refreshPage: false,
  1537. addAjaxFlag: true,
  1538. //添加收藏
  1539. add: function(cfg)
  1540. {
  1541. }
  1542. }
  1543. */
  1544. function showToggle(e)
  1545. {
  1546. var id = e.attr('toggle');
  1547. var child = e.attr('toggle_child');
  1548. var parent = e.parent();
  1549. parent.parent().find('li').removeClass('active');
  1550. parent.addClass('active');
  1551. $(child).fadeOut(100);
  1552. $(id).fadeIn(500);
  1553. initEditor($(id).find('.editor'));
  1554. }
  1555. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1556. {
  1557. var e = '#' + id;
  1558. var parent = value.split(',');
  1559. var cur = parent[0];
  1560. parent.remove(cur);
  1561. value = parent.join(',');
  1562. var html = '';
  1563. var old = level;
  1564. if (!total) {
  1565. level_id = 0;
  1566. } else {
  1567. if (level >= total) {
  1568. //$(e).show();
  1569. return;
  1570. }
  1571. level_id = $(e + '_' + level).val();
  1572. level = parseInt(level) + 1;
  1573. }
  1574. $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1575. var check = '';
  1576. if (t.status == 1) {
  1577. var total = t.data.level_total;
  1578. var data = t.data.list;
  1579. if(!$(e + '_' + level).length) {
  1580. 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+'\');">';
  1581. }
  1582. for (a in data) {
  1583. if (data[a].value) {
  1584. check = '';
  1585. if (cur == data[a].value) {
  1586. check = ' selected';
  1587. }
  1588. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1589. }
  1590. }
  1591. if(!$(e + '_' + level).length) {
  1592. html += '</select><span>&nbsp;&nbsp;</span>';
  1593. $(e).append(html);
  1594. $(e + '_' + level).change();
  1595. } else {
  1596. $(e + '_' + level).html(html);
  1597. $(e + '_' + level).change();
  1598. }
  1599. } else {
  1600. $(e + '_' + old).nextAll('select').remove();
  1601. $(e + '_' + old).next('span').nextAll('span').remove();
  1602. }
  1603. /*
  1604. if ($('#' + name + '_level_value').length) {
  1605. var total = $(id).find('select').length;
  1606. $('#' + name + '_level_value').val(total);
  1607. }
  1608. if ($('#' + name + '_up_value').length) {
  1609. $('#' + name + '_up_value').val($(id + '_-2').val());
  1610. }
  1611. */
  1612. });
  1613. }
  1614. /*
  1615. function select_mul(level, id, url, name, value, valid, w, num)
  1616. {
  1617. if(level == 0)
  1618. {
  1619. $(id).find('select').remove();
  1620. $(id).find('span').remove();
  1621. return;
  1622. }
  1623. var parent = value.split(',');
  1624. var cur = parent[0];
  1625. parent.remove(cur);
  1626. value = parent.join(',');
  1627. var html = '';
  1628. var old = level;
  1629. if(level != -1)
  1630. {
  1631. if($(id + '_' + level).length)
  1632. {
  1633. level = $(id + '_' + level).val();
  1634. }
  1635. alert(level);
  1636. if(level == 0)
  1637. {
  1638. $(id + '_' + old).nextAll('select').remove();
  1639. $(id + '_' + old).next('span').nextAll('span').remove();
  1640. if($('#' + name + '_level_value').length)
  1641. {
  1642. var total = $(id).find('select').length;
  1643. $('#' + name + '_level_value').val(total);
  1644. }
  1645. if(old == -2 && $('#' + name + '_value_value').length)
  1646. {
  1647. $('#' + name + '_value_value').val(level);
  1648. }
  1649. return;
  1650. }
  1651. if(old == -2)
  1652. {
  1653. $(id + '_' + old).nextAll('select').remove();
  1654. $(id + '_' + old).next('span').nextAll('span').remove();
  1655. }
  1656. if($('#' + name + '_value_value').length)
  1657. {
  1658. $('#' + name + '_value_value').val(level);
  1659. }
  1660. }
  1661. var total = $(id).find('select').length;
  1662. if(num > 0 && total >= num)
  1663. {
  1664. return;
  1665. }
  1666. var get = url.replace('{level}', level);
  1667. if(level == -1)
  1668. {
  1669. level = -2;
  1670. }
  1671. if(!$(id + '_' + level).length)
  1672. {
  1673. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1674. {
  1675. var check = '';
  1676. if(t.status == 1)
  1677. {
  1678. 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+');">';
  1679. console.log(t.data);
  1680. for(a in t.data)
  1681. {
  1682. if(t.data[a].value)
  1683. {
  1684. check = '';
  1685. if(cur == t.data[a].value)
  1686. {
  1687. check = ' selected';
  1688. }
  1689. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1690. }
  1691. }
  1692. html += '</select><span>&nbsp;&nbsp;</span>';
  1693. $(id).append(html);
  1694. $(id + '_' + level).change();
  1695. }
  1696. else
  1697. {
  1698. $(id + '_' + old).nextAll('select').remove();
  1699. $(id + '_' + old).next('span').nextAll('span').remove();
  1700. }
  1701. if($('#' + name + '_level_value').length)
  1702. {
  1703. var total = $(id).find('select').length;
  1704. $('#' + name + '_level_value').val(total);
  1705. }
  1706. if($('#' + name + '_up_value').length)
  1707. {
  1708. $('#' + name + '_up_value').val($(id + '_-2').val());
  1709. }
  1710. });
  1711. }
  1712. }
  1713. */
  1714. //处理更新页面的一些功能,写到一起吧
  1715. var dever_update =
  1716. {
  1717. addIndex : 2,
  1718. index : [],
  1719. auto : false,
  1720. save_key : '',
  1721. init : function()
  1722. {
  1723. var self = this;
  1724. self.index = [];
  1725. // 增加整个更新的表单
  1726. if($(".dever_update_add").length)
  1727. {
  1728. $('.dever_update_add').unbind('click').bind('click', function()
  1729. {
  1730. self.add($(this));
  1731. })
  1732. }
  1733. /* 以后再增加 同时更新另外一个表
  1734. if($(".form-add-content").length)
  1735. {
  1736. var url = config.host + 'auth.password';
  1737. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1738. $.get(url, function(t)
  1739. {
  1740. $(".form-add-content").html(t);
  1741. init();
  1742. })
  1743. }
  1744. */
  1745. //增加某一部分表单
  1746. if($(".dever_form_add").length)
  1747. {
  1748. $('.dever_form_add').each(function()
  1749. {
  1750. var key = $.attr('toggle_key');
  1751. if(typeof(self.index[key]) == "undefined")
  1752. {
  1753. self.index[key] = 0;
  1754. }
  1755. $(this).unbind('click').bind('click', function()
  1756. {
  1757. self.append($(this));
  1758. })
  1759. })
  1760. self.del();
  1761. }
  1762. // 开启自动保存
  1763. if($("#struct").length)
  1764. {
  1765. var save = $("#struct").attr('save');
  1766. if(save == 'yes')
  1767. {
  1768. //检测
  1769. self.save_key = location.href + 'test';
  1770. self.check();
  1771. }
  1772. }
  1773. if($('.dever-note').length)
  1774. {
  1775. $('.dever-note').each(function()
  1776. {
  1777. var mditor = new Mditor($(this),{
  1778. fixedHeight:true
  1779. });
  1780. mditor.openPreview();
  1781. })
  1782. }
  1783. },
  1784. save : function()
  1785. {
  1786. //var data = $("#data-1").html();
  1787. var data = [];
  1788. $(".update_value").each(function(i)
  1789. {
  1790. if($(this).attr("update_type") == 'checked')
  1791. {
  1792. data[i] = $(this).get(0).checked;
  1793. }
  1794. else if($(this).attr("update_type") == 'html')
  1795. {
  1796. data[i] = $(this).html();
  1797. }
  1798. else if($(this).attr("update_type") == 'src')
  1799. {
  1800. data[i] = $(this).attr('src');
  1801. }
  1802. else
  1803. {
  1804. data[i] = $(this).val();
  1805. }
  1806. });
  1807. store.set(this.save_key, data.join('|||'));
  1808. //console.info(data);
  1809. },
  1810. recover : function()
  1811. {
  1812. layer.confirm('确定恢复上次保存的数据吗?', function()
  1813. {
  1814. var data = store.get(this.save_key).split('|||');
  1815. if(data)
  1816. {
  1817. var value = $(".update_value");
  1818. for(var k in data)
  1819. {
  1820. var e = value.eq(k);
  1821. if(e.attr('update_type') == 'checked')
  1822. {
  1823. if(data[k] == 'true')
  1824. {
  1825. e.get(0).checked = true;
  1826. }
  1827. else
  1828. {
  1829. e.get(0).checked = false;
  1830. }
  1831. }
  1832. else if(e.attr('update_type') == 'html')
  1833. {
  1834. e.html(data[k]);
  1835. }
  1836. else if(e.attr('update_type') == 'src')
  1837. {
  1838. e.attr('src', data[k]);
  1839. }
  1840. else
  1841. {
  1842. if(e.attr('id'))
  1843. {
  1844. var id = e.attr('id');
  1845. if(typeof(editors[id]) != "undefined")
  1846. {
  1847. editors[id].html(data[k]);
  1848. }
  1849. }
  1850. e.val(data[k]);
  1851. }
  1852. }
  1853. store.set(this.save_key, '');
  1854. this.check();
  1855. }
  1856. })
  1857. },
  1858. check : function()
  1859. {
  1860. var data = store.get(this.save_key);
  1861. var self = this;
  1862. if(data)
  1863. {
  1864. $(".dever_save").unbind('click').bind('click', function()
  1865. {
  1866. self.recover();
  1867. }).show();
  1868. }
  1869. else
  1870. {
  1871. $(".dever_save").hide();
  1872. self.auto = setInterval(function(){self.save()}, 3000);
  1873. }
  1874. },
  1875. del : function()
  1876. {
  1877. var self = this;
  1878. if($(".dever_form_delete").length)
  1879. {
  1880. $('.dever_form_delete').each(function()
  1881. {
  1882. $(this).unbind('click').bind('click', function()
  1883. {
  1884. var parent = $(this).parent();
  1885. var id = parent.attr('id');
  1886. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1887. var key = $('#tab-' + id).attr('toggle_key');
  1888. if(index <= 1 && self.index[key] <= index)
  1889. {
  1890. }
  1891. else if(index <= 1 && self.index[key] > index)
  1892. {
  1893. index = index+1;
  1894. $("#tab-"+key+"-child-" + index).click();
  1895. }
  1896. else
  1897. {
  1898. index = index-1;
  1899. $("#tab-"+key+"-child-" + index).click();
  1900. };
  1901. $('#tab-' + id).parent().remove();
  1902. parent.remove();
  1903. self.index[key]--;
  1904. })
  1905. })
  1906. }
  1907. },
  1908. append : function(e)
  1909. {
  1910. var self = this;
  1911. var key = e.attr('toggle_key');
  1912. var child = '.dever_'+key+'_child';
  1913. if(typeof(self.index[key]) == "undefined")
  1914. {
  1915. self.index[key] = 0;
  1916. }
  1917. if(self.index[key] <= 0)
  1918. {
  1919. self.index[key] = $(child).length;
  1920. }
  1921. if(self.index[key] > 30)
  1922. {
  1923. layer.showAlert('最多只能增加30条');
  1924. return;
  1925. }
  1926. var p = e.parent();
  1927. var id = key + '-child-' + self.index[key];
  1928. var name = '第' + (self.index[key]) + '条';
  1929. 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>');
  1930. var e = e.parent().parent();
  1931. var n = e.next();
  1932. var p = e.parent();
  1933. var content = n.html();
  1934. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1935. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1936. p.append(content);
  1937. if ($("#" + id).find('.ke-container').length >= 1) {
  1938. $("#" + id).find('.ke-container').eq(0).remove();
  1939. }
  1940. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1941. self.del();
  1942. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1943. self.index[key]++;
  1944. image();
  1945. loadShow();
  1946. autocomplete();
  1947. change();
  1948. },
  1949. add : function(e)
  1950. {
  1951. var self = this;
  1952. var p = e.parent();
  1953. var id = 'data-' + this.addIndex;
  1954. var name = '新增数据-' + (this.addIndex-1);
  1955. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1956. var content = $("#content").find('.tab-pane').eq(0).html();
  1957. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1958. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1959. $("#content").append(content);
  1960. $('#update_' + this.addIndex + '__where_id').val('-1');
  1961. this.addIndex++;
  1962. }
  1963. }
  1964. $.fn.pasteEvents = function( delay ) {
  1965. if (delay == undefined) delay = 20;
  1966. return $(this).each(function() {
  1967. var $el = $(this);
  1968. $el.on("paste", function() {
  1969. $el.trigger("prepaste");
  1970. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1971. });
  1972. });
  1973. };
  1974. $("textarea").on("postpaste", function()
  1975. {
  1976. if($(this).val().indexOf('<') != -1)
  1977. {
  1978. $(this).val(toMarkdown($(this).val()));
  1979. }
  1980. }).pasteEvents();