main.js 48 KB

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