main.js 49 KB

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