main.js 41 KB

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