main.js 52 KB

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