main.js 55 KB

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