main.js 54 KB

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