main.js 48 KB

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