main.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587
  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 == '点此编辑') {
  1395. html = '';
  1396. }
  1397. if(html.indexOf('input') == -1)
  1398. {
  1399. if(type && type == 'textarea')
  1400. {
  1401. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1402. }
  1403. else
  1404. {
  1405. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1406. }
  1407. var self = $(this);
  1408. self.find("#edit").focus();
  1409. self.find("#edit").blur(function()
  1410. {
  1411. var value = self.find("#edit").val();
  1412. if(!value)
  1413. {
  1414. alert('不能为空');
  1415. return;
  1416. }
  1417. if($(this).find(".edit-content").length)
  1418. {
  1419. $(this).find(".edit-content").html(value);
  1420. }
  1421. else
  1422. {
  1423. self.attr('data-content', value);
  1424. }
  1425. self.html(value);
  1426. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1427. {
  1428. notify('修改成功', self);
  1429. preview();
  1430. /*
  1431. if(type && type == 'textarea')
  1432. {
  1433. self.html(t);
  1434. }
  1435. */
  1436. })
  1437. })
  1438. }
  1439. });
  1440. })
  1441. }
  1442. }
  1443. function preview()
  1444. {
  1445. if($("#preview").length)
  1446. {
  1447. var time = Date.parse(new Date());
  1448. var src = $('#preview').attr('src').split('#');
  1449. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1450. }
  1451. }
  1452. function del()
  1453. {
  1454. if($(".oper_delete").length)
  1455. {
  1456. $(".oper_delete").each(function()
  1457. {
  1458. var href = $(this).attr('href');
  1459. $(this).attr('href', '#');
  1460. $(this).unbind('click');
  1461. $(this).bind('click', function()
  1462. {
  1463. del_act(href);
  1464. });
  1465. })
  1466. }
  1467. }
  1468. /**
  1469. * 处理删除
  1470. */
  1471. function del_act(href)
  1472. {
  1473. var index = layer.confirm('确定进行此项操作吗?', function()
  1474. {
  1475. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1476. {
  1477. msg(t);
  1478. layer.close(index);
  1479. })
  1480. });
  1481. }
  1482. /**
  1483. * 处理特殊加载的按钮
  1484. */
  1485. function load(href)
  1486. {
  1487. var index = layer.confirm('确定进行此项操作吗?', function()
  1488. {
  1489. if(href.indexOf('&') == -1)
  1490. {
  1491. href += '?json=1&callback=?';
  1492. }
  1493. else
  1494. {
  1495. href += '&json=1&callback=?';
  1496. }
  1497. $.getJSON(href, {}, function(t)
  1498. {
  1499. msg(t);
  1500. layer.close(index);
  1501. //location.reload();
  1502. })
  1503. })
  1504. /*
  1505. showAlert('确定进行此项操作吗?', function()
  1506. {
  1507. $("#dever_modal_no").click();
  1508. $.getJSON(href + '&json=1', {}, function(t)
  1509. {
  1510. msg(t);
  1511. })
  1512. });
  1513. */
  1514. }
  1515. /**
  1516. * 处理特殊页面
  1517. */
  1518. function loadPage(href, title, submit)
  1519. {
  1520. if(href.indexOf('&') == -1)
  1521. {
  1522. href += '?json=1&callback=?';
  1523. }
  1524. else
  1525. {
  1526. href += '&json=1&callback=?';
  1527. }
  1528. $.getJSON(href, {}, function(t)
  1529. {
  1530. var func = false;
  1531. if (submit) {
  1532. }
  1533. showAlert(t.data, func, title);
  1534. })
  1535. }
  1536. /**
  1537. * 处理特殊加载的按钮
  1538. */
  1539. function jump(href, form)
  1540. {
  1541. if (form) {
  1542. var param = formData(form);
  1543. href += param[1];
  1544. }
  1545. location.href = href;
  1546. }
  1547. /**
  1548. * 处理change
  1549. */
  1550. function change()
  1551. {
  1552. if($(".change").length)
  1553. {
  1554. $(".change").each(function()
  1555. {
  1556. var key = $(this).attr('data-child');
  1557. /*
  1558. $('.' + key).each(function()
  1559. {
  1560. if($(this).find('select option:selected').val())
  1561. {
  1562. $(this).show();
  1563. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1564. }
  1565. });
  1566. */
  1567. $(this).change(function()
  1568. {
  1569. $('.' + key).hide();
  1570. var v = $('.' + key + '_' + $(this).val());
  1571. var s = v.find('select');
  1572. s.change(function()
  1573. {
  1574. $('.' + key + '_value').val($(this).val());
  1575. })
  1576. if(v.length)
  1577. {
  1578. $('.' + key + '_value').val(s.val());
  1579. v.show();
  1580. }
  1581. else
  1582. {
  1583. $('.' + key + '_value').val(-1);
  1584. }
  1585. });
  1586. if($(this).val() > 0)
  1587. {
  1588. $(this).change();
  1589. }
  1590. });
  1591. }
  1592. }
  1593. /**
  1594. * 处理图库系统
  1595. */
  1596. function image()
  1597. {
  1598. if($(".dever-note").length)
  1599. {
  1600. $(".dever-note").each(function()
  1601. {
  1602. var key = $(this).attr('key');
  1603. $(this).inlineattachment(
  1604. {
  1605. uploadUrl: config.upload + '.drag?key='+ key
  1606. });
  1607. });
  1608. }
  1609. if($(".image_upload").length)
  1610. {
  1611. $(".image_upload").each(function(i)
  1612. {
  1613. //如果是大文件
  1614. if ($(this).attr('l')) {
  1615. loadUploadL(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');
  1616. } else {
  1617. var parent = $(this).parent().parent();
  1618. //alert(parent.attr('id'));
  1619. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1620. {
  1621. return;
  1622. }
  1623. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1624. }
  1625. })
  1626. }
  1627. if($(".upload_show").length)
  1628. {
  1629. $(".upload_show").each(function(i)
  1630. {
  1631. var parent = $(this).parent().parent();
  1632. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1633. {
  1634. return;
  1635. }
  1636. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1637. })
  1638. }
  1639. if($(".upload_show_editor").length)
  1640. {
  1641. $(".upload_show_editor").each(function(i)
  1642. {
  1643. var parent = $(this).parent().parent();
  1644. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1645. {
  1646. return;
  1647. }
  1648. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 3);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1649. })
  1650. }
  1651. }
  1652. /**
  1653. * 修改密码
  1654. */
  1655. function pass(e)
  1656. {
  1657. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1658. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  1659. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  1660. html += '</div>';
  1661. var edit = function()
  1662. {
  1663. var old_password = $("#edit_old_password").val();
  1664. var new_password = $("#edit_new_password").val();
  1665. if(!old_password || !new_password)
  1666. {
  1667. alert('请输入密码');
  1668. return;
  1669. }
  1670. if(old_password == new_password)
  1671. {
  1672. alert('旧密码和新密码相同');
  1673. return;
  1674. }
  1675. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1676. {
  1677. alert(t);
  1678. })
  1679. };
  1680. showAlert(html, edit, '修改密码');
  1681. /*
  1682. $('#dever_modal_body').html(html);
  1683. $('#dever_modal_title').html('修改密码');
  1684. */
  1685. }
  1686. var MSG = [];
  1687. /**
  1688. * 打开弹窗
  1689. */
  1690. //function showMsg(title, e, id, func)
  1691. function showMsg(title, e, id, func, param)
  1692. {
  1693. if(id.indexOf('http://') == -1)
  1694. {
  1695. if($(id).length)
  1696. {
  1697. var html = $(id).html();
  1698. if($(id).html())
  1699. {
  1700. var html = $(id).html();
  1701. MSG[id] = html;
  1702. $(id).html('');
  1703. }
  1704. else
  1705. {
  1706. var html = MSG[id];
  1707. }
  1708. }
  1709. else
  1710. {
  1711. var html = id;
  1712. }
  1713. showAlert(html, func, title);
  1714. /*
  1715. $('#dever_modal_body').html(html);
  1716. $('#dever_modal_title').html(title);
  1717. if (func) {
  1718. $("#dever_modal_yes").unbind('click').bind('click', func);
  1719. } else {
  1720. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1721. }
  1722. */
  1723. }
  1724. else
  1725. {
  1726. var url = id;
  1727. var send = {};
  1728. if (param) {
  1729. send = param;
  1730. }
  1731. if (e && e.attr('msg-send')) {
  1732. send.data = e.attr('msg-send');
  1733. }
  1734. if (url.indexOf('?') != -1) {
  1735. url = url + '&';
  1736. } else {
  1737. url = url + '?';
  1738. }
  1739. $.getJSON(url+'json=1&callback=?',send,function(t)
  1740. {
  1741. t = t.data;
  1742. showAlert(t, func, t);
  1743. /*
  1744. $('#dever_modal_body').html(t);
  1745. $('#dever_modal_title').html(title);
  1746. if(func)
  1747. {
  1748. $("#dever_modal_yes").unbind('click').bind('click', func);
  1749. }
  1750. */
  1751. });
  1752. }
  1753. }
  1754. function updateMsg(id)
  1755. {
  1756. $("#"+id).submit();
  1757. }
  1758. function showAlert(msg, func, title, index)
  1759. {
  1760. if (!title) {
  1761. title = '提醒您';
  1762. }
  1763. var type = 0;
  1764. if (msg.indexOf('<') != -1) {
  1765. type = 1;
  1766. }
  1767. var config = {
  1768. type: 0,
  1769. title: title,
  1770. shade: 0.1,
  1771. shadeClose : true,
  1772. content: msg
  1773. };
  1774. config.scrollbar = false;
  1775. if (type == 1) {
  1776. if (index) {
  1777. config.zIndex = index;
  1778. config.type = 1;
  1779. config.btn = ['确定'];
  1780. }
  1781. config.area = '800px';
  1782. //config.type = 1;
  1783. }
  1784. if (func) {
  1785. config.yes = function(index)
  1786. {
  1787. func(index);
  1788. };
  1789. } else {
  1790. config.yes = function(index)
  1791. {
  1792. layer.close(index);
  1793. };
  1794. }
  1795. var index = layer.open(config);
  1796. }
  1797. function fastEdit(e, url, title, col, index)
  1798. {
  1799. var func = function()
  1800. {
  1801. submit_action();
  1802. };
  1803. var send = {};
  1804. send.col = col;
  1805. $.get(url,send,function(t)
  1806. {
  1807. var html = '';
  1808. var valid = '';
  1809. if ($(t).find('form').length && $(t).find('#valid').length) {
  1810. var html = $(t).find('form').prop("outerHTML");
  1811. var valid = $(t).find('#valid').prop("outerHTML");
  1812. html = html + valid;
  1813. if (html.indexOf('left: 740px') != -1) {
  1814. html = html.replace('left: 740px', 'left:583px;')
  1815. }
  1816. } else {
  1817. html = t;
  1818. func = false;
  1819. }
  1820. if (index == 1) {
  1821. showAlert(html, func, title, 19850422);
  1822. } else {
  1823. showAlert(html, func, title);
  1824. }
  1825. $('.layui-layer-content').css('overflow-x', 'hidden');
  1826. $('#update_button').hide();
  1827. layui.use(['formSelects'], function(){
  1828. $("select").each(function()
  1829. {
  1830. if ($(this).attr('xm-select')) {
  1831. layui.formSelects.render($(this).attr('xm-select'));
  1832. }
  1833. })
  1834. });
  1835. init(560);
  1836. });
  1837. }
  1838. /*
  1839. var test =
  1840. {
  1841. refreshPage: false,
  1842. addAjaxFlag: true,
  1843. //添加收藏
  1844. add: function(cfg)
  1845. {
  1846. }
  1847. }
  1848. */
  1849. function showToggle(e)
  1850. {
  1851. var id = e.attr('toggle');
  1852. var child = e.attr('toggle_child');
  1853. var parent = e.parent();
  1854. parent.parent().find('li').removeClass('active');
  1855. parent.addClass('active');
  1856. $(child).fadeOut(100);
  1857. $(id).fadeIn(500);
  1858. initEditor($(id).find('.editor'));
  1859. }
  1860. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1861. {
  1862. var e = '#' + id;
  1863. var parent = value.split(',');
  1864. var cur = parent[0];
  1865. parent.remove(cur);
  1866. value = parent.join(',');
  1867. var html = '';
  1868. var old = level;
  1869. if (!total) {
  1870. level_id = 0;
  1871. } else {
  1872. if (level >= total) {
  1873. //$(e).show();
  1874. return;
  1875. }
  1876. level_id = $(e + '_' + level).val();
  1877. level = parseInt(level) + 1;
  1878. }
  1879. $.getJSON(url + '?json=1&callback=?', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1880. var check = '';
  1881. if (t.status == 1) {
  1882. var total = t.data.level_total;
  1883. var data = t.data.list;
  1884. if(!$(e + '_' + level).length) {
  1885. 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+'\');">';
  1886. }
  1887. for (a in data) {
  1888. if (data[a].value) {
  1889. check = '';
  1890. if (cur == data[a].value) {
  1891. check = ' selected';
  1892. }
  1893. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1894. }
  1895. }
  1896. if(!$(e + '_' + level).length) {
  1897. html += '</select><span>&nbsp;&nbsp;</span>';
  1898. $(e).append(html);
  1899. $(e + '_' + level).change();
  1900. } else {
  1901. $(e + '_' + level).html(html);
  1902. $(e + '_' + level).change();
  1903. }
  1904. } else {
  1905. $(e + '_' + old).nextAll('select').remove();
  1906. $(e + '_' + old).next('span').nextAll('span').remove();
  1907. }
  1908. /*
  1909. if ($('#' + name + '_level_value').length) {
  1910. var total = $(id).find('select').length;
  1911. $('#' + name + '_level_value').val(total);
  1912. }
  1913. if ($('#' + name + '_up_value').length) {
  1914. $('#' + name + '_up_value').val($(id + '_-2').val());
  1915. }
  1916. */
  1917. });
  1918. }
  1919. /*
  1920. function select_mul(level, id, url, name, value, valid, w, num)
  1921. {
  1922. if(level == 0)
  1923. {
  1924. $(id).find('select').remove();
  1925. $(id).find('span').remove();
  1926. return;
  1927. }
  1928. var parent = value.split(',');
  1929. var cur = parent[0];
  1930. parent.remove(cur);
  1931. value = parent.join(',');
  1932. var html = '';
  1933. var old = level;
  1934. if(level != -1)
  1935. {
  1936. if($(id + '_' + level).length)
  1937. {
  1938. level = $(id + '_' + level).val();
  1939. }
  1940. alert(level);
  1941. if(level == 0)
  1942. {
  1943. $(id + '_' + old).nextAll('select').remove();
  1944. $(id + '_' + old).next('span').nextAll('span').remove();
  1945. if($('#' + name + '_level_value').length)
  1946. {
  1947. var total = $(id).find('select').length;
  1948. $('#' + name + '_level_value').val(total);
  1949. }
  1950. if(old == -2 && $('#' + name + '_value_value').length)
  1951. {
  1952. $('#' + name + '_value_value').val(level);
  1953. }
  1954. return;
  1955. }
  1956. if(old == -2)
  1957. {
  1958. $(id + '_' + old).nextAll('select').remove();
  1959. $(id + '_' + old).next('span').nextAll('span').remove();
  1960. }
  1961. if($('#' + name + '_value_value').length)
  1962. {
  1963. $('#' + name + '_value_value').val(level);
  1964. }
  1965. }
  1966. var total = $(id).find('select').length;
  1967. if(num > 0 && total >= num)
  1968. {
  1969. return;
  1970. }
  1971. var get = url.replace('{level}', level);
  1972. if(level == -1)
  1973. {
  1974. level = -2;
  1975. }
  1976. if(!$(id + '_' + level).length)
  1977. {
  1978. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1979. {
  1980. var check = '';
  1981. if(t.status == 1)
  1982. {
  1983. 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+');">';
  1984. console.log(t.data);
  1985. for(a in t.data)
  1986. {
  1987. if(t.data[a].value)
  1988. {
  1989. check = '';
  1990. if(cur == t.data[a].value)
  1991. {
  1992. check = ' selected';
  1993. }
  1994. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1995. }
  1996. }
  1997. html += '</select><span>&nbsp;&nbsp;</span>';
  1998. $(id).append(html);
  1999. $(id + '_' + level).change();
  2000. }
  2001. else
  2002. {
  2003. $(id + '_' + old).nextAll('select').remove();
  2004. $(id + '_' + old).next('span').nextAll('span').remove();
  2005. }
  2006. if($('#' + name + '_level_value').length)
  2007. {
  2008. var total = $(id).find('select').length;
  2009. $('#' + name + '_level_value').val(total);
  2010. }
  2011. if($('#' + name + '_up_value').length)
  2012. {
  2013. $('#' + name + '_up_value').val($(id + '_-2').val());
  2014. }
  2015. });
  2016. }
  2017. }
  2018. */
  2019. //处理更新页面的一些功能,写到一起吧
  2020. var dever_update =
  2021. {
  2022. addIndex : 2,
  2023. index : [],
  2024. auto : false,
  2025. save_key : '',
  2026. init : function()
  2027. {
  2028. var self = this;
  2029. self.index = [];
  2030. // 增加整个更新的表单
  2031. if($(".dever_update_add").length)
  2032. {
  2033. $('.dever_update_add').unbind('click').bind('click', function()
  2034. {
  2035. self.add($(this));
  2036. })
  2037. }
  2038. /* 以后再增加 同时更新另外一个表
  2039. if($(".form-add-content").length)
  2040. {
  2041. var url = config.host + 'auth.password';
  2042. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  2043. $.get(url, function(t)
  2044. {
  2045. $(".form-add-content").html(t);
  2046. init();
  2047. })
  2048. }
  2049. */
  2050. //增加某一部分表单
  2051. if($(".dever_form_add").length)
  2052. {
  2053. $('.dever_form_add').each(function()
  2054. {
  2055. var key = $.attr('toggle_key');
  2056. if(typeof(self.index[key]) == "undefined")
  2057. {
  2058. self.index[key] = 0;
  2059. }
  2060. $(this).unbind('click').bind('click', function()
  2061. {
  2062. self.append($(this));
  2063. })
  2064. })
  2065. self.del();
  2066. }
  2067. // 开启自动保存
  2068. if($("#struct").length)
  2069. {
  2070. var save = $("#struct").attr('save');
  2071. if(save == 'yes')
  2072. {
  2073. //检测
  2074. self.save_key = location.href + 'test';
  2075. self.check();
  2076. }
  2077. }
  2078. if($('.dever-note').length)
  2079. {
  2080. $('.dever-note').each(function()
  2081. {
  2082. var mditor = new Mditor($(this),{
  2083. fixedHeight:true
  2084. });
  2085. mditor.openPreview();
  2086. })
  2087. }
  2088. },
  2089. save : function()
  2090. {
  2091. //var data = $("#data-1").html();
  2092. var data = [];
  2093. $(".update_value").each(function(i)
  2094. {
  2095. if($(this).attr("update_type") == 'checked')
  2096. {
  2097. data[i] = $(this).get(0).checked;
  2098. }
  2099. else if($(this).attr("update_type") == 'html')
  2100. {
  2101. data[i] = $(this).html();
  2102. }
  2103. else if($(this).attr("update_type") == 'src')
  2104. {
  2105. data[i] = $(this).attr('src');
  2106. }
  2107. else
  2108. {
  2109. data[i] = $(this).val();
  2110. }
  2111. });
  2112. store.set(this.save_key, data.join('|||'));
  2113. //console.info(data);
  2114. },
  2115. recover : function()
  2116. {
  2117. var index = layer.confirm('确定恢复上次保存的数据吗?', function()
  2118. {
  2119. var data = store.get(this.save_key).split('|||');
  2120. if(data)
  2121. {
  2122. var value = $(".update_value");
  2123. for(var k in data)
  2124. {
  2125. var e = value.eq(k);
  2126. if(e.attr('update_type') == 'checked')
  2127. {
  2128. if(data[k] == 'true')
  2129. {
  2130. e.get(0).checked = true;
  2131. }
  2132. else
  2133. {
  2134. e.get(0).checked = false;
  2135. }
  2136. }
  2137. else if(e.attr('update_type') == 'html')
  2138. {
  2139. e.html(data[k]);
  2140. }
  2141. else if(e.attr('update_type') == 'src')
  2142. {
  2143. e.attr('src', data[k]);
  2144. }
  2145. else
  2146. {
  2147. if(e.attr('id'))
  2148. {
  2149. var id = e.attr('id');
  2150. if(typeof(editors[id]) != "undefined")
  2151. {
  2152. editors[id].html(data[k]);
  2153. }
  2154. }
  2155. e.val(data[k]);
  2156. }
  2157. }
  2158. store.set(this.save_key, '');
  2159. this.check();
  2160. }
  2161. })
  2162. },
  2163. check : function()
  2164. {
  2165. var data = store.get(this.save_key);
  2166. var self = this;
  2167. if(data)
  2168. {
  2169. $(".dever_save").unbind('click').bind('click', function()
  2170. {
  2171. self.recover();
  2172. }).show();
  2173. }
  2174. else
  2175. {
  2176. $(".dever_save").hide();
  2177. self.auto = setInterval(function(){self.save()}, 3000);
  2178. }
  2179. },
  2180. del : function()
  2181. {
  2182. var self = this;
  2183. if($(".dever_form_delete").length)
  2184. {
  2185. $('.dever_form_delete').each(function()
  2186. {
  2187. $(this).unbind('click').bind('click', function()
  2188. {
  2189. var parent = $(this).parent();
  2190. var id = parent.attr('id');
  2191. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  2192. var key = $('#tab-' + id).attr('toggle_key');
  2193. if(index <= 1 && self.index[key] <= index)
  2194. {
  2195. }
  2196. else if(index <= 1 && self.index[key] > index)
  2197. {
  2198. index = index+1;
  2199. $("#tab-"+key+"-child-" + index).click();
  2200. }
  2201. else
  2202. {
  2203. index = index-1;
  2204. $("#tab-"+key+"-child-" + index).click();
  2205. };
  2206. $('#tab-' + id).parent().remove();
  2207. parent.remove();
  2208. self.index[key]--;
  2209. })
  2210. })
  2211. }
  2212. },
  2213. append : function(e)
  2214. {
  2215. var self = this;
  2216. var key = e.attr('toggle_key');
  2217. var child = '.dever_'+key+'_child';
  2218. if(typeof(self.index[key]) == "undefined")
  2219. {
  2220. self.index[key] = 0;
  2221. }
  2222. if (isNaN(self.index[key])) {
  2223. self.index[key] = 0;
  2224. }
  2225. if(self.index[key] <= 0)
  2226. {
  2227. self.index[key] = $(child).length;
  2228. }
  2229. if(self.index[key] > 30)
  2230. {
  2231. layer.showAlert('最多只能增加30条');
  2232. return;
  2233. }
  2234. var p = e.parent();
  2235. var id = key + '-child-' + self.index[key];
  2236. var name = '第' + (self.index[key]) + '条';
  2237. 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>');
  2238. var e = e.parent().parent();
  2239. var n = e.next();
  2240. var p = e.parent();
  2241. var content = n.html();
  2242. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  2243. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  2244. p.append(content);
  2245. if ($("#" + id).find('.ke-container').length >= 1) {
  2246. $("#" + id).find('.ke-container').eq(0).remove();
  2247. }
  2248. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  2249. self.del();
  2250. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  2251. self.index[key]++;
  2252. image();
  2253. loadShow();
  2254. autocomplete();
  2255. change();
  2256. },
  2257. add : function(e)
  2258. {
  2259. var self = this;
  2260. var p = e.parent();
  2261. var id = 'data-' + this.addIndex;
  2262. var name = '新增数据-' + (this.addIndex-1);
  2263. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  2264. var content = $("#content").find('.tab-pane').eq(0).html();
  2265. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  2266. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  2267. $("#content").append(content);
  2268. $('#update_' + this.addIndex + '__where_id').val('-1');
  2269. this.addIndex++;
  2270. }
  2271. }
  2272. $.fn.pasteEvents = function( delay ) {
  2273. if (delay == undefined) delay = 20;
  2274. return $(this).each(function() {
  2275. var $el = $(this);
  2276. $el.on("paste", function() {
  2277. $el.trigger("prepaste");
  2278. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  2279. });
  2280. });
  2281. };
  2282. $("textarea").on("postpaste", function()
  2283. {
  2284. if($(this).val().indexOf('<') != -1)
  2285. {
  2286. $(this).val(toMarkdown($(this).val()));
  2287. }
  2288. }).pasteEvents();