main.js 41 KB

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