main.js 55 KB

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