main.js 41 KB

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