main.js 55 KB

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