main.js 54 KB

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