main.js 55 KB

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