main.js 52 KB

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