main.js 50 KB

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