main.js 57 KB

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