main.js 54 KB

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