main.js 54 KB

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