main.js 70 KB

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