main.js 65 KB

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