main.js 54 KB

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