main.js 55 KB

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