main.js 56 KB

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