main.js 53 KB

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