main.js 53 KB

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