main.js 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954
  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. if (c.indexOf('validates') > -1) {
  666. $(".show_" + n).find(array[a]).removeClass('validates').addClass('validate[required]');
  667. }
  668. }
  669. }
  670. if (t == 'input') {
  671. var item = e.parent().find('input');
  672. item.each(function()
  673. {
  674. if($(this).get(0).checked == true)
  675. {
  676. inputShowOne($(this),n);
  677. }
  678. });
  679. } else {
  680. var item = e.parent().find('select');
  681. item.each(function()
  682. {
  683. if($(this).find('option:selected').text())
  684. {
  685. inputShowOne($(this),n);
  686. }
  687. });
  688. }
  689. }
  690. function inputShowOne(e,n)
  691. {
  692. var value = e.val();
  693. var ele = '.show_' + n + '_ajax';
  694. if ($(ele).length) {
  695. $(ele).each(function()
  696. {
  697. var self = $(this);
  698. var url = self.attr('dever-ajax');
  699. $.getJSON(url + value + '&callback=?', function(t) {
  700. self.find('.margin-top').html(t.data);
  701. inputShowOneValiDate(self);
  702. checkbox();
  703. })
  704. })
  705. } else {
  706. ele = '.show_' + n + '_' + value;
  707. inputShowOneValiDate($(ele));
  708. }
  709. }
  710. function inputShowOneValiDate(e)
  711. {
  712. e.show();
  713. var array = ['input', 'textarea'];
  714. for(var a in array)
  715. {
  716. if(e.length && e.attr('class').indexOf('show_no') == -1)
  717. {
  718. e.find(array[a]).each(function()
  719. {
  720. var parent = $(this).parent();
  721. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  722. {
  723. $(this).addClass('validate[required]');
  724. }
  725. })
  726. }
  727. }
  728. }
  729. //批量更新
  730. function list_mul(e)
  731. {
  732. var type = parseInt($("#mul_type").val());
  733. if(type != 1 && type != 2)
  734. {
  735. alert('您还没有选择数据更新方式');
  736. return;
  737. }
  738. var index = layer.confirm('确定进行此项操作吗?', function()
  739. {
  740. $('#method').val('mul');
  741. $('#function').val('msg');
  742. layer.close(index);
  743. $('#form1').attr('target', 'f1').submit();
  744. })
  745. }
  746. //搜索
  747. function list_search(e)
  748. {
  749. $('#method').val('search');
  750. $('#function').val('');
  751. $('#form1').attr('target', '').submit();
  752. }
  753. //更新数据
  754. function update(e, id, project, table, notice)
  755. {
  756. var call = function()
  757. {
  758. var col = e.attr('name').replace('up_col_', '');
  759. var value = e.val();
  760. var old = e.attr('data-old');
  761. var url = config.host + 'database.update_action?json=1';
  762. $.post(url, {where_id:id,col:col,value:value,project:project,table:table}, function(t)
  763. {
  764. var t = eval('('+t+')');
  765. if (t.status == 1) {
  766. e.attr('data-old', value);
  767. notify('操作已成功!您的操作已修改当前选项!', e);
  768. preview();
  769. } else {
  770. msg(t);
  771. e.val(old);
  772. }
  773. })
  774. }
  775. if(notice)
  776. {
  777. var index = layer.confirm(notice, function()
  778. {
  779. layer.close(index);
  780. call();
  781. });
  782. }
  783. else
  784. {
  785. call();
  786. }
  787. }
  788. function notify(msg, e)
  789. {
  790. if (!e) {
  791. layer.msg(msg);
  792. return;
  793. }
  794. layer.tips(msg, e, {
  795. tips: [1, '#3595CC']
  796. });
  797. /*
  798. var notice = new PNotify({
  799. title: '提示信息',
  800. text: msg,
  801. buttons: {
  802. closer: false,
  803. sticker: false
  804. }
  805. });
  806. notice.get().click(function() {
  807. notice.remove();
  808. });
  809. */
  810. }
  811. //模板选择
  812. function template()
  813. {
  814. if(config.template)
  815. {
  816. $('body').attr('class', 'theme-' + config.template);
  817. }
  818. if($(".selector").length)
  819. {
  820. $(".selector").each(function()
  821. {
  822. if($(this).data('check') == 'checked')
  823. {
  824. selector($(this));
  825. }
  826. })
  827. }
  828. }
  829. //选择器
  830. function selector(e)
  831. {
  832. var value = e.data('value');
  833. var name = e.data('name');
  834. $('#'+name+'_value').val(value);
  835. $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
  836. e.children().css({'border':'1px solid black'});
  837. if(name == 'update_template')
  838. {
  839. $('body').attr('class', 'theme-' + value);
  840. }
  841. }
  842. //根据e的值,来载入其他数据
  843. function loading(e, data)
  844. {
  845. var value = e.val();
  846. if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
  847. {
  848. var id = e.attr('id').replace('_temp', '');
  849. if($('#' + id).length)
  850. {
  851. var value = $('#' + id).val();
  852. }
  853. }
  854. if(data.element)
  855. {
  856. if(data.url)
  857. {
  858. data.value = value;
  859. $.getJSON(data.url, data, function(t)
  860. {
  861. $('#update_'+data.element+'_value').val(t.data);
  862. });
  863. }
  864. else
  865. {
  866. $('#update_'+data.element+'_value').val(value);
  867. }
  868. }
  869. else if(data.url)
  870. {
  871. data.value = value;
  872. data.where_id = $('#update_where_id').val();
  873. data.table = $('#table').val();
  874. data.project = $('#project').val();
  875. $.getJSON(data.url + '&json=1', data, function(s)
  876. {
  877. t = s.data;
  878. if(t.indexOf('onblur') != -1)
  879. {
  880. eval(t);
  881. }
  882. else
  883. {
  884. var parent = e.parent().parent();
  885. if(t.indexOf('status') == -1)
  886. {
  887. if(data.type == 1)
  888. {
  889. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  890. {
  891. $(this).remove();
  892. });
  893. }
  894. else
  895. {
  896. $('.checking_-1,.checking_3,.checking_4').each(function()
  897. {
  898. $(this).remove();
  899. });
  900. }
  901. if (!parent.parent().find('.bind_show').length) {
  902. parent.after('<div class="bind_show">' + t + '</div>');
  903. } else if (parent.parent().find('.bind_show').html() != t) {
  904. parent.parent().find('.bind_show').html(t);
  905. }
  906. checkbox();
  907. }
  908. }
  909. });
  910. }
  911. }
  912. //根据e的值,来载入其他数据,先检测是否选中
  913. function checking(name, e, data)
  914. {
  915. var value = [];
  916. $('.' + name).each(function()
  917. {
  918. if($(this).get(0).checked == true)
  919. {
  920. value.push($(this).val());
  921. }
  922. });
  923. if(data.url)
  924. {
  925. data.value = value.join(',');
  926. data.where_id = $('#update_where_id').val();
  927. data.table = $('#table').val();
  928. data.project = $('#project').val();
  929. if(data.check)
  930. {
  931. data.check_value = false;
  932. $(data.check).each(function()
  933. {
  934. if($(this).get(0).checked == true)
  935. {
  936. data.check_value = $(this).val();
  937. }
  938. });
  939. }
  940. $.getJSON(data.url, data, function(s)
  941. {
  942. t = s.data;
  943. var parent = e.parent().parent().parent();
  944. if(t.indexOf('status') == -1)
  945. {
  946. if(data.type == 1)
  947. {
  948. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  949. {
  950. $(this).remove();
  951. });
  952. }
  953. else
  954. {
  955. $('.checking_-1,.checking_3,.checking_4').each(function()
  956. {
  957. $(this).remove();
  958. });
  959. }
  960. parent.after(t);
  961. checkbox();
  962. }
  963. });
  964. }
  965. }
  966. function autocomplete()
  967. {
  968. if ($("input").length) {
  969. $("input").each(function()
  970. {
  971. $(this).attr('autocomplete', 'off');
  972. });
  973. }
  974. if($("input[complete]").length)
  975. {
  976. $("input[complete]").each(function()
  977. {
  978. var cache = {};
  979. var self = $(this);
  980. self.autocomplete(
  981. {
  982. minLength: 2,
  983. source: function( request, response )
  984. {
  985. var term = request.term.split( /,\s*/ );
  986. request.term = term.pop();
  987. if ( request.term in cache ) {
  988. response( cache[ request.term ] );
  989. return;
  990. }
  991. var cate = self.attr('complete_cate');
  992. if (cate) {
  993. request[cate] = $('update_' + cate + '_value').val();
  994. }
  995. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  996. data = data.data
  997. cache[ term ] = data;
  998. var state = true;
  999. for(var i in data)
  1000. {
  1001. if(data[i].id <=0)
  1002. {
  1003. state = false;
  1004. }
  1005. }
  1006. if(state)
  1007. {
  1008. response( data );
  1009. }
  1010. });
  1011. },
  1012. focus: function() {
  1013. // prevent value inserted on focus
  1014. return false;
  1015. },
  1016. select: function( event, ui )
  1017. {
  1018. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  1019. var value = self.attr('complete_callback');
  1020. var id = self.attr('id').replace('_temp', '');
  1021. var name = self.attr('name').replace('_temp', '');
  1022. //var e = $("#" + id);
  1023. var e = self;
  1024. 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>';
  1025. if (!$("#" + id + '_show').length) {
  1026. e.parent().append(html);
  1027. }
  1028. if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
  1029. {
  1030. var link = '';
  1031. var attr = '';
  1032. var pic = '';
  1033. if (ui.item['pic']) {
  1034. pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
  1035. }
  1036. if (ui.item['link']) {
  1037. link = ui.item['link'];
  1038. attr = ' target="_blank"';
  1039. }
  1040. 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>';
  1041. $("#" + id + '_show').append(html);
  1042. if (!autocomplete_value[id]) {
  1043. autocomplete_value[id] = [];
  1044. }
  1045. autocomplete_value[id].push(ui.item[value]);
  1046. }
  1047. ui.item.value = '';
  1048. }
  1049. });
  1050. })
  1051. }
  1052. }
  1053. function autocomplete_del(e, id, value, name)
  1054. {
  1055. e.parent().parent().remove();
  1056. autocomplete_value[id].remove(value);
  1057. var len = autocomplete_value[id].length;
  1058. if (len < 1 && !($('#del_' + name).length)) {
  1059. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1060. }
  1061. }
  1062. function searchbox(id, e)
  1063. {
  1064. var self = e.parent().find("input");
  1065. var v = self.val();
  1066. var key = self.attr('id').replace('_temp', '');
  1067. var request = {};
  1068. request.term = v;
  1069. var cate = self.attr('searchbox_cate');
  1070. if (cate) {
  1071. var c = cate.split(',');
  1072. for (var i in c) {
  1073. if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
  1074. request[c[i]] = $('#'+c[i]).val();
  1075. }
  1076. }
  1077. }
  1078. var index = layer.msg('加载中...');
  1079. $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
  1080. layer.close(index);
  1081. var data = data.data;
  1082. if (!data) {
  1083. showAlert('没有搜索到数据');
  1084. return;
  1085. }
  1086. 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>';
  1087. if (data) {
  1088. var j = 0;
  1089. var c = '';
  1090. var s = '';
  1091. var cateHtml = '';
  1092. var content = '';
  1093. for (var i in data) {
  1094. if (j == 0) {
  1095. c = 'class="layui-this"';
  1096. s = 'layui-show';
  1097. } else {
  1098. c = '';
  1099. s = '';
  1100. }
  1101. cateHtml += '<li '+c+'>'+data[i].name+'</li>';
  1102. j++;
  1103. 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}';
  1104. var p = false;
  1105. for (var k in data[i].child) {
  1106. if (data[i].child[k].name) {
  1107. var pic = '';
  1108. if (data[i].child[k].pic) {
  1109. pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
  1110. p = true;
  1111. }
  1112. var check = '';
  1113. if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
  1114. check = 'checked';
  1115. }
  1116. 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>';
  1117. }
  1118. }
  1119. item += '</table></div></div>';
  1120. 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>';
  1121. if (p) {
  1122. head = head.replace('</td><td>', '</td><td>图片</td><td>');
  1123. }
  1124. item = item.replace('{head}', head);
  1125. content += item;
  1126. }
  1127. if (cateHtml) {
  1128. html = html.replace('{cate}', cateHtml);
  1129. }
  1130. if (content) {
  1131. html = html.replace('{content}', content);
  1132. }
  1133. }
  1134. var config = {
  1135. type: 1,
  1136. shade: 0.3,
  1137. title : false,
  1138. shadeClose : true,
  1139. area : ['800px', '600px'],
  1140. content: html
  1141. };
  1142. layer.open(config);
  1143. layui.use('element', function(){
  1144. var element = layui.element;
  1145. });
  1146. });
  1147. }
  1148. function searchbox_checkall(e, id)
  1149. {
  1150. $('.' + id).each(function()
  1151. {
  1152. $(this).get(0).checked = e.get(0).checked;
  1153. //$(this).click();
  1154. })
  1155. }
  1156. function searchbox_checkone(e, id, key, value)
  1157. {
  1158. if (!e.get(0).checked) {
  1159. $('#searchbox_check_' + key + '_' + value).remove();
  1160. searchbox_value.remove(value);
  1161. var len = searchbox_value.length;
  1162. var name = key.replace('_value', '');
  1163. if (len < 1 && !($('#del_' + name).length)) {
  1164. $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1165. }
  1166. } else {
  1167. var c = '.' + e.attr('data-class');
  1168. searchbox_yes(id, c, false);
  1169. }
  1170. }
  1171. function searchbox_yes(e, c, state)
  1172. {
  1173. var self = $("#" +e);
  1174. $(c).each(function()
  1175. {
  1176. if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
  1177. var value = self.attr('searchbox_callback');
  1178. var id = self.attr('id').replace('_temp', '');
  1179. var name = self.attr('name').replace('_temp', '');
  1180. 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>';
  1181. if (!$("#" + id + '_show').length) {
  1182. self.parent().append(html);
  1183. }
  1184. if (!$("#" + id + '_show').find('#searchbox_check_'+id+'_'+$(this).attr('data-value')).length)
  1185. {
  1186. var link = '';
  1187. var attr = '';
  1188. var pic = '';
  1189. if ($(this).attr('data-pic') && $(this).attr('data-pic') != 'undefined') {
  1190. pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
  1191. }
  1192. if ($(this).attr('data-link')) {
  1193. link = $(this).attr('data-link');
  1194. attr = ' target="_blank"';
  1195. }
  1196. 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>';
  1197. $("#" + id + '_show').append(html);
  1198. if (!searchbox_value[id]) {
  1199. searchbox_value[id] = [];
  1200. }
  1201. searchbox_value[id].push($(this).attr('data-value'));
  1202. }
  1203. }
  1204. })
  1205. if (state == true) {
  1206. layer.closeAll();
  1207. }
  1208. }
  1209. function searchbox_del(e, id, value, name)
  1210. {
  1211. e.parent().parent().remove();
  1212. searchbox_value.remove(value);
  1213. var len = searchbox_value.length;
  1214. if (len < 1 && !($('#del_' + name).length)) {
  1215. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1216. }
  1217. }
  1218. //后台通用的提示
  1219. function msg(value)
  1220. {
  1221. $("#dever_modal_no").click();
  1222. if(!value.data)
  1223. {
  1224. value.data = value.msg;
  1225. }
  1226. if(value == 1)
  1227. {
  1228. location.reload();
  1229. return;
  1230. }
  1231. submit();
  1232. var url = '';
  1233. if(value.data != 'reload' && value.status == 2)
  1234. {
  1235. showAlert(value.msg, false, '错误提示');
  1236. //alert(value.data);
  1237. //location.reload();
  1238. return;
  1239. }
  1240. else if(value.data == 'reload')
  1241. {
  1242. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1243. {
  1244. pjax({url: location.href, container: config.layout})
  1245. }
  1246. else
  1247. {
  1248. location.reload();
  1249. }
  1250. return;
  1251. }
  1252. else
  1253. {
  1254. if(value.data.indexOf('http') != -1)
  1255. {
  1256. url = value.data;
  1257. }
  1258. else if($("#url").length)
  1259. {
  1260. url = $("#url").val();
  1261. }
  1262. else
  1263. {
  1264. notify(value.data)
  1265. return;
  1266. }
  1267. if(url)
  1268. {
  1269. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1270. {
  1271. pjax({url: url, container: config.layout});
  1272. }
  1273. else
  1274. {
  1275. location.href = url;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1281. {
  1282. pjax({url: location.href, container: config.layout});
  1283. }
  1284. else
  1285. {
  1286. location.reload();
  1287. }
  1288. }
  1289. }
  1290. return;
  1291. }
  1292. /**
  1293. * 处理多选问题,处理全选按钮
  1294. */
  1295. function checkbox()
  1296. {
  1297. if($(".autoload").length)
  1298. {
  1299. $(".autoload").each(function()
  1300. {
  1301. if($(this).get(0).checked == true)
  1302. {
  1303. $(this).removeClass('autoload');
  1304. $(this).load();
  1305. }
  1306. });
  1307. }
  1308. if($(".autoload_text").length)
  1309. {
  1310. $(".autoload_text").each(function()
  1311. {
  1312. if($(this).val())
  1313. {
  1314. $(this).removeClass('autoload_text');
  1315. $(this).load();
  1316. }
  1317. });
  1318. }
  1319. var name = 'checkbox-checkall';
  1320. var checkbox = $("." + name);
  1321. if(checkbox.length)
  1322. {
  1323. checkbox.unbind('click').bind('click', function()
  1324. {
  1325. var self = $(this);
  1326. $("." + name + "-" + self.val()).each(function()
  1327. {
  1328. $(this).get(0).checked = self.get(0).checked;
  1329. var next = $(this).next();
  1330. if($(this).get(0).checked == true)
  1331. {
  1332. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1333. {
  1334. next.attr('disabled', false);
  1335. }
  1336. if($("#mul_type").length)
  1337. {
  1338. $("#mul_type").val(1);
  1339. }
  1340. }
  1341. else
  1342. {
  1343. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1344. {
  1345. next.attr('disabled', true);
  1346. }
  1347. if($("#mul_type").length)
  1348. {
  1349. $("#mul_type").val(0);
  1350. }
  1351. }
  1352. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1353. inputShow($(this), 'col');
  1354. }
  1355. })
  1356. });
  1357. checkbox.each(function()
  1358. {
  1359. var self = $(this);
  1360. var len = $("." + name + "-" + self.val()).length;
  1361. $("." + name + "-" + self.val()).each(function()
  1362. {
  1363. $(this).unbind('click').bind('click', function()
  1364. {
  1365. var next = $(this).next();
  1366. var state = $(this).attr('data-state');
  1367. if($(this).get(0).checked == true)
  1368. {
  1369. if (state == 2) {
  1370. self.get(0).checked = true;
  1371. } else {
  1372. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1373. self.get(0).checked = true;
  1374. }
  1375. }
  1376. if(self.attr('type') == 'radio')
  1377. {
  1378. //如果父选项是radio类型,做下限制
  1379. //alert(1);
  1380. }
  1381. if($("#mul_type").length)
  1382. {
  1383. $("#mul_type").val(1);
  1384. }
  1385. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1386. {
  1387. next.attr('disabled', false);
  1388. }
  1389. }
  1390. else
  1391. {
  1392. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1393. {
  1394. next.attr('disabled', true);
  1395. }
  1396. }
  1397. var num = 0;
  1398. $("." + name + "-" + self.val()).each(function()
  1399. {
  1400. if($(this).get(0).checked == true)
  1401. {
  1402. num = 1;
  1403. }
  1404. });
  1405. var id = $(this).attr('name');
  1406. var hidden = id;
  1407. id = id.replace('[]', '');
  1408. if(num == 0)
  1409. {
  1410. self.get(0).checked = false;
  1411. if($("#mul_type").length)
  1412. {
  1413. $("#mul_type").val(0);
  1414. }
  1415. if (state == 2) {
  1416. } else if (!$('#' + id).length) {
  1417. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  1418. }
  1419. } else {
  1420. if ($('#' + id).length) {
  1421. $('#' + id).remove();
  1422. }
  1423. }
  1424. })
  1425. if($(this).get(0).checked == true)
  1426. {
  1427. self.get(0).checked = true;
  1428. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1429. inputShow($(this), 'col');
  1430. }
  1431. }
  1432. });
  1433. })
  1434. }
  1435. }
  1436. /**
  1437. * 处理双击编辑
  1438. */
  1439. function edit()
  1440. {
  1441. if($(".edit").length)
  1442. {
  1443. $(".edit").each(function()
  1444. {
  1445. $(this).bind('dblclick', function()
  1446. {
  1447. var col = $(this).attr('data-col');
  1448. var project = $(this).attr('data-project');
  1449. var table = $(this).attr('data-table');
  1450. var url = $(this).attr('data-url');
  1451. var id = $(this).attr('data-id');
  1452. var html = $(this).attr('data-content');
  1453. var type = $(this).attr('data-type');
  1454. if($(this).find(".edit-content").length)
  1455. {
  1456. html = $(this).find(".edit-content").html();
  1457. html = html.replace('<!--', '<');
  1458. html = html.replace('-->', '>');
  1459. }
  1460. if (html == '点此编辑') {
  1461. html = '';
  1462. }
  1463. if(html.indexOf('input') == -1)
  1464. {
  1465. if(type && type == 'textarea')
  1466. {
  1467. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1468. }
  1469. else
  1470. {
  1471. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1472. }
  1473. var self = $(this);
  1474. self.find("#edit").focus();
  1475. self.find("#edit").blur(function()
  1476. {
  1477. var value = self.find("#edit").val();
  1478. if(!value)
  1479. {
  1480. alert('不能为空');
  1481. return;
  1482. }
  1483. if($(this).find(".edit-content").length)
  1484. {
  1485. $(this).find(".edit-content").html(value);
  1486. }
  1487. else
  1488. {
  1489. self.attr('data-content', value);
  1490. }
  1491. self.html(value);
  1492. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1493. {
  1494. notify('修改成功', self);
  1495. preview();
  1496. /*
  1497. if(type && type == 'textarea')
  1498. {
  1499. self.html(t);
  1500. }
  1501. */
  1502. })
  1503. })
  1504. }
  1505. });
  1506. })
  1507. }
  1508. }
  1509. function preview()
  1510. {
  1511. if($("#preview").length)
  1512. {
  1513. var time = Date.parse(new Date());
  1514. var src = $('#preview').attr('src').split('#');
  1515. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1516. }
  1517. }
  1518. function del()
  1519. {
  1520. if($(".oper_delete").length)
  1521. {
  1522. $(".oper_delete").each(function()
  1523. {
  1524. var href = $(this).attr('href');
  1525. $(this).attr('href', '#');
  1526. $(this).unbind('click');
  1527. $(this).bind('click', function()
  1528. {
  1529. del_act(href);
  1530. });
  1531. })
  1532. }
  1533. }
  1534. /**
  1535. * 处理删除
  1536. */
  1537. function del_act(href)
  1538. {
  1539. var index = layer.confirm('确定进行此项操作吗?', function()
  1540. {
  1541. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1542. {
  1543. msg(t);
  1544. layer.close(index);
  1545. })
  1546. });
  1547. }
  1548. /**
  1549. * 处理特殊加载的按钮
  1550. */
  1551. function load(href, content, title)
  1552. {
  1553. if (!content) {
  1554. content = '确定进行此项操作吗?';
  1555. }
  1556. if (!title) {
  1557. title = '温馨提示';
  1558. }
  1559. var send = {title:title}
  1560. var index = layer.confirm(content, send, function()
  1561. {
  1562. if(href.indexOf('&') == -1)
  1563. {
  1564. href += '?json=1&callback=?';
  1565. }
  1566. else
  1567. {
  1568. href += '&json=1&callback=?';
  1569. }
  1570. $.getJSON(href, {}, function(t)
  1571. {
  1572. msg(t);
  1573. layer.close(index);
  1574. //location.reload();
  1575. })
  1576. })
  1577. /*
  1578. showAlert('确定进行此项操作吗?', function()
  1579. {
  1580. $("#dever_modal_no").click();
  1581. $.getJSON(href + '&json=1', {}, function(t)
  1582. {
  1583. msg(t);
  1584. })
  1585. });
  1586. */
  1587. }
  1588. /**
  1589. * 处理特殊页面
  1590. */
  1591. function loadPage(href, title, submit)
  1592. {
  1593. if(href.indexOf('&') == -1)
  1594. {
  1595. href += '?json=1&callback=?';
  1596. }
  1597. else
  1598. {
  1599. href += '&json=1&callback=?';
  1600. }
  1601. $.getJSON(href, {}, function(t)
  1602. {
  1603. var func = false;
  1604. if (submit) {
  1605. }
  1606. showAlert(t.data, func, title);
  1607. })
  1608. }
  1609. /**
  1610. * 处理特殊加载的按钮
  1611. */
  1612. function jump(href, form)
  1613. {
  1614. if (form) {
  1615. var param = formData(form);
  1616. href += param[1];
  1617. }
  1618. location.href = href;
  1619. }
  1620. /**
  1621. * 处理change
  1622. */
  1623. function change()
  1624. {
  1625. if($(".change").length)
  1626. {
  1627. $(".change").each(function()
  1628. {
  1629. var key = $(this).attr('data-child');
  1630. /*
  1631. $('.' + key).each(function()
  1632. {
  1633. if($(this).find('select option:selected').val())
  1634. {
  1635. $(this).show();
  1636. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1637. }
  1638. });
  1639. */
  1640. $(this).change(function()
  1641. {
  1642. $('.' + key).hide();
  1643. var v = $('.' + key + '_' + $(this).val());
  1644. var s = v.find('select');
  1645. s.change(function()
  1646. {
  1647. $('.' + key + '_value').val($(this).val());
  1648. })
  1649. if(v.length)
  1650. {
  1651. $('.' + key + '_value').val(s.val());
  1652. v.show();
  1653. }
  1654. else
  1655. {
  1656. $('.' + key + '_value').val(-1);
  1657. }
  1658. });
  1659. if($(this).val() > 0)
  1660. {
  1661. $(this).change();
  1662. }
  1663. });
  1664. }
  1665. }
  1666. /**
  1667. * 处理图库系统
  1668. */
  1669. function image()
  1670. {
  1671. if($(".dever-note").length)
  1672. {
  1673. $(".dever-note").each(function()
  1674. {
  1675. var key = $(this).attr('key');
  1676. $(this).inlineattachment(
  1677. {
  1678. uploadUrl: config.upload + '.drag?key='+ key
  1679. });
  1680. });
  1681. }
  1682. if($(".image_upload").length)
  1683. {
  1684. $(".image_upload").each(function(i)
  1685. {
  1686. //如果是大文件
  1687. if ($(this).attr('l')) {
  1688. loadUploadL(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');
  1689. } else {
  1690. var parent = $(this).parent().parent();
  1691. //alert(parent.attr('id'));
  1692. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1693. {
  1694. return;
  1695. }
  1696. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1697. }
  1698. })
  1699. }
  1700. if($(".upload_show").length)
  1701. {
  1702. $(".upload_show").each(function(i)
  1703. {
  1704. var parent = $(this).parent().parent();
  1705. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1706. {
  1707. return;
  1708. }
  1709. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1710. })
  1711. }
  1712. if($(".upload_cover").length)
  1713. {
  1714. $(".upload_cover").each(function(i)
  1715. {
  1716. var parent = $(this).parent().parent();
  1717. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1718. {
  1719. return;
  1720. }
  1721. showUploadCover(i,$(this),$(this).attr('key'),config.upload + '.videoCover', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1722. })
  1723. }
  1724. if($(".upload_show_editor").length)
  1725. {
  1726. $(".upload_show_editor").each(function(i)
  1727. {
  1728. var parent = $(this).parent().parent();
  1729. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1730. {
  1731. return;
  1732. }
  1733. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 3);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1734. })
  1735. }
  1736. }
  1737. /**
  1738. * 修改密码
  1739. */
  1740. function pass(e)
  1741. {
  1742. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1743. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  1744. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  1745. html += '</div>';
  1746. var edit = function()
  1747. {
  1748. var old_password = $("#edit_old_password").val();
  1749. var new_password = $("#edit_new_password").val();
  1750. if(!old_password || !new_password)
  1751. {
  1752. alert('请输入密码');
  1753. return;
  1754. }
  1755. if(old_password == new_password)
  1756. {
  1757. alert('旧密码和新密码相同');
  1758. return;
  1759. }
  1760. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1761. {
  1762. alert(t);
  1763. })
  1764. };
  1765. showAlert(html, edit, '修改密码');
  1766. /*
  1767. $('#dever_modal_body').html(html);
  1768. $('#dever_modal_title').html('修改密码');
  1769. */
  1770. }
  1771. var MSG = [];
  1772. /**
  1773. * 打开弹窗
  1774. */
  1775. //function showMsg(title, e, id, func)
  1776. function showMsg(title, e, id, func, param)
  1777. {
  1778. if(id.indexOf('http://') == -1)
  1779. {
  1780. if($(id).length)
  1781. {
  1782. var html = $(id).html();
  1783. if($(id).html())
  1784. {
  1785. var html = $(id).html();
  1786. MSG[id] = html;
  1787. $(id).html('');
  1788. }
  1789. else
  1790. {
  1791. var html = MSG[id];
  1792. }
  1793. }
  1794. else
  1795. {
  1796. var html = id;
  1797. }
  1798. showAlert(html, func, title);
  1799. /*
  1800. $('#dever_modal_body').html(html);
  1801. $('#dever_modal_title').html(title);
  1802. if (func) {
  1803. $("#dever_modal_yes").unbind('click').bind('click', func);
  1804. } else {
  1805. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1806. }
  1807. */
  1808. }
  1809. else
  1810. {
  1811. var url = id;
  1812. var send = {};
  1813. if (param) {
  1814. send = param;
  1815. }
  1816. if (e && e.attr('msg-send')) {
  1817. send.data = e.attr('msg-send');
  1818. }
  1819. if (url.indexOf('?') != -1) {
  1820. url = url + '&';
  1821. } else {
  1822. url = url + '?';
  1823. }
  1824. $.getJSON(url+'json=1&callback=?',send,function(t)
  1825. {
  1826. t = t.data;
  1827. showAlert(t, func, t);
  1828. /*
  1829. $('#dever_modal_body').html(t);
  1830. $('#dever_modal_title').html(title);
  1831. if(func)
  1832. {
  1833. $("#dever_modal_yes").unbind('click').bind('click', func);
  1834. }
  1835. */
  1836. });
  1837. }
  1838. }
  1839. function updateMsg(id)
  1840. {
  1841. $("#"+id).submit();
  1842. }
  1843. function showAlert(msg, func, title, index, t)
  1844. {
  1845. if (!title) {
  1846. title = '温馨提示';
  1847. }
  1848. var type = 0;
  1849. if (msg.indexOf('<') != -1) {
  1850. type = 1;
  1851. }
  1852. if (t) {
  1853. type = t;
  1854. }
  1855. var config = {
  1856. type: 0,
  1857. title: title,
  1858. shade: 0.1,
  1859. shadeClose : true,
  1860. content: msg
  1861. };
  1862. if (index) {
  1863. config.zIndex = index;
  1864. }
  1865. config.scrollbar = false;
  1866. if (type == 1) {
  1867. config.type = 1;
  1868. config.btn = ['保存', '关闭'];
  1869. if (func) {
  1870. config.area = '800px';
  1871. config.btn = ['保存', '关闭'];
  1872. } else {
  1873. config.area = '500px';
  1874. config.btn = ['关闭'];
  1875. }
  1876. } else if (type == 2) {
  1877. config.type = 1;
  1878. config.btn = [];
  1879. config.area = '800px';
  1880. }
  1881. config.cancel = config.btn2 = function(index)
  1882. {
  1883. layer.close(index);
  1884. };
  1885. if (func) {
  1886. config.yes = function(index)
  1887. {
  1888. func(index);
  1889. };
  1890. } else {
  1891. config.yes = config.cancel;
  1892. }
  1893. config.success = function() {
  1894. $('.layui-layer-content').css('padding', '10px');
  1895. }
  1896. config.end = function() {
  1897. $('.layui-layer-content').css('overflow-x', 'auto');
  1898. $('#update_button').show();
  1899. }
  1900. var index = layer.open(config);
  1901. }
  1902. function fastEdit(e, url, title, col, index, type)
  1903. {
  1904. var func = function()
  1905. {
  1906. $(".fast").submit();
  1907. };
  1908. var send = {};
  1909. if (col) {
  1910. send.col = col;
  1911. }
  1912. $.get(url + '&fast=1',send,function(t)
  1913. {
  1914. var html = '';
  1915. var valid = '';
  1916. var action = '';
  1917. if ($(t).find('form').length) {
  1918. if ($(t).find('form').length > 1) {
  1919. var form = $(t).find('form').eq(1);
  1920. form.addClass('layui-card-body');
  1921. } else {
  1922. var form = $(t).find('form').eq(0);
  1923. }
  1924. action = form.attr('action');
  1925. form.addClass('fast');
  1926. form.find('#function').eq(0).val('showYes');
  1927. var html = form.prop("outerHTML");
  1928. if ($(t).find('#valid').length) {
  1929. var valid = $(t).find('#valid').prop("outerHTML");
  1930. html = html + valid;
  1931. }
  1932. if (html.indexOf('left: 740px') != -1) {
  1933. html = html.replace('left: 740px', 'left:583px;')
  1934. }
  1935. } else {
  1936. html = t;
  1937. func = false;
  1938. }
  1939. /*
  1940. if ($(html).find('.layui-card-body').length > 0) {
  1941. html = html.replace('class="layui-card-body"', 'class="layui-card-body" style="display:none"');
  1942. html = html.replaceAll('class="layui-btn layuiadmin-btn-list"', 'class="layui-btn layuiadmin-btn-list" style="display:none"');
  1943. }
  1944. */
  1945. if (!action) {
  1946. type = 2;
  1947. func = false;
  1948. }
  1949. if (index == 1) {
  1950. showAlert(html, func, title, 19850422, type);
  1951. } else {
  1952. showAlert(html, func, title, false, type);
  1953. }
  1954. $('.layui-layer-content').css('overflow-x', 'hidden');
  1955. $('#update_button').hide();
  1956. layui.use(['formSelects', 'form'], function(){
  1957. var form = layui.form;
  1958. form.render();
  1959. $("select").each(function()
  1960. {
  1961. if ($(this).attr('xm-select')) {
  1962. layui.formSelects.render($(this).attr('xm-select'));
  1963. }
  1964. })
  1965. });
  1966. init(560);
  1967. });
  1968. }
  1969. /*
  1970. var test =
  1971. {
  1972. refreshPage: false,
  1973. addAjaxFlag: true,
  1974. //添加收藏
  1975. add: function(cfg)
  1976. {
  1977. }
  1978. }
  1979. */
  1980. function showToggle(e)
  1981. {
  1982. var id = e.attr('toggle');
  1983. var child = e.attr('toggle_child');
  1984. var parent = e.parent();
  1985. parent.parent().find('li').removeClass('active');
  1986. parent.addClass('active');
  1987. $(child).fadeOut(100);
  1988. $(id).fadeIn(500);
  1989. initEditor($(id).find('.editor'));
  1990. }
  1991. var select_api = {};
  1992. var select_api_name = [];
  1993. var select_api_title = '';
  1994. var select_api_open = '';
  1995. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param, col, api, type, title, open)
  1996. {
  1997. var e = '#' + id;
  1998. var parent = value.split(',');
  1999. var cur = parent[0];
  2000. parent.remove(cur);
  2001. value = parent.join(',');
  2002. var html = '';
  2003. var old = level;
  2004. var level_name = '';
  2005. if (!total) {
  2006. level_id = 0;
  2007. } else {
  2008. if (level >= total) {
  2009. //$(e).show();
  2010. return;
  2011. }
  2012. level_id = $(e + '_' + level).val();
  2013. if (level_id.indexOf('|') != -1) {
  2014. var temp = level_id.split('|');
  2015. if (level == 1) {
  2016. select_api_name = [];
  2017. }
  2018. level_id = temp[0];
  2019. level_name = temp[1];
  2020. select_api_name[level-1] = level_name;
  2021. }
  2022. level = parseInt(level) + 1;
  2023. }
  2024. var api_name = '';
  2025. if (col && api) {
  2026. select_api_title = title;
  2027. select_api_open = open;
  2028. if (name.indexOf('_no') == -1) {
  2029. api_name = name;
  2030. } else {
  2031. var t = name.split('_no');
  2032. api_name = t[0];
  2033. }
  2034. name += '_no';
  2035. }
  2036. $.getJSON(url + '&json=1&callback=?', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  2037. var check = '';
  2038. if (t.status == 1) {
  2039. var total = t.data.level_total;
  2040. var data = t.data.list;
  2041. if(!$(e + '_' + level).length) {
  2042. 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+'\');">';
  2043. }
  2044. for (a in data) {
  2045. if (data[a].value) {
  2046. check = '';
  2047. if (cur == data[a].value) {
  2048. check = ' selected';
  2049. }
  2050. var v = data[a].value;
  2051. if (col && api) {
  2052. v = data[a].value + '|' + data[a].name;
  2053. }
  2054. html += '<option value="'+v+'" '+check+'>'+data[a].name+'</option>';
  2055. }
  2056. }
  2057. if(!$(e + '_' + level).length) {
  2058. html += '</select><span>&nbsp;&nbsp;</span>';
  2059. $(e).append(html);
  2060. $(e + '_' + level).change();
  2061. } else {
  2062. $(e + '_' + level).html(html);
  2063. $(e + '_' + level).change();
  2064. }
  2065. } else {
  2066. $(e + '_' + old).nextAll('select').remove();
  2067. $(e + '_' + old).next('span').nextAll('span').remove();
  2068. }
  2069. if (col && api && level_id > 0) {
  2070. var send = {};
  2071. send[col] = level_id;
  2072. $.getJSON(api + '&json=1&callback=?', send, function(r) {
  2073. var h = '<ul style="list-style:none;margin-top: 20px;display:;" class="">';
  2074. if (type == 'checkbox') {
  2075. 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>';
  2076. }
  2077. for (var i in r.data) {
  2078. if (r.data[i]['name']) {
  2079. var checked = false;
  2080. 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) {
  2081. checked = true;
  2082. }
  2083. 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>';
  2084. }
  2085. }
  2086. h += '</ul>';
  2087. $(e + '_content').html(h);
  2088. });
  2089. }
  2090. /*
  2091. if ($('#' + name + '_level_value').length) {
  2092. var total = $(id).find('select').length;
  2093. $('#' + name + '_level_value').val(total);
  2094. }
  2095. if ($('#' + name + '_up_value').length) {
  2096. $('#' + name + '_up_value').val($(id + '_-2').val());
  2097. }
  2098. */
  2099. });
  2100. if (col && api) {
  2101. select_linkage_check_show(e, api_name);
  2102. }
  2103. }
  2104. function select_linkage_check_all(e, cur, level_id, level_name, id, api_name)
  2105. {
  2106. var checked = e.prop('checked');
  2107. $('.' + cur).each(function() {
  2108. $(this).prop('checked', checked);
  2109. select_linkage_check($(this), level_id, level_name, id, api_name);
  2110. })
  2111. }
  2112. function select_linkage_check(e, level_id, level_name, id, api_name, cid)
  2113. {
  2114. var level_key = 'level_' + level_id;
  2115. if (!select_api[level_key]) {
  2116. select_api[level_key] = {};
  2117. select_api[level_key]['id'] = level_id;
  2118. select_api[level_key]['name'] = level_name;
  2119. select_api[level_key]['value'] = {};
  2120. }
  2121. var value = e.val();
  2122. var temp = value.split('|');
  2123. var key = 'id_' + temp[0];
  2124. if (e.prop('checked')) {
  2125. select_api[level_key]['value'][key] = {};
  2126. select_api[level_key]['value'][key]['id'] = temp[0];
  2127. select_api[level_key]['value'][key]['name'] = temp[1];
  2128. select_api[level_key]['value'][key]['state'] = 1;
  2129. } else {
  2130. if (select_api[level_key] && select_api[level_key]['value'] && select_api[level_key]['value'][key]) {
  2131. select_api[level_key]['value'][key]['state'] = 2;
  2132. }
  2133. if (cid) {
  2134. $(cid).prop('checked', false);
  2135. }
  2136. }
  2137. select_linkage_check_show(id, api_name);
  2138. }
  2139. function select_linkage_check_show(id, api_name)
  2140. {
  2141. if (select_api) {
  2142. var select_api_json = JSON.stringify(select_api);
  2143. var html = '<div style="margin-top: 20px;display:;border: 1px solid #5050b1;padding: 10px;">';
  2144. for (var i in select_api) {
  2145. if (select_api[i]['value']) {
  2146. html += '[' + select_api[i]['name'] + ']:<ul style="list-style:none;" class="">';
  2147. for (var j in select_api[i]['value']) {
  2148. var n = '&nbsp;&nbsp;' + select_api[i]['value'][j]['name'];
  2149. if (select_api_open) {
  2150. var o = select_api_open.replace('{id}', select_api[i]['value'][j]['id']);
  2151. n = '<a href="javascript:;" onclick="fastEdit($(this), \''+o+'\', \''+select_api_title+'\', \'\', 1,1)">'+n+'</a>';
  2152. }
  2153. if (select_api[i]['value'][j]['state'] == 2) {
  2154. n += '[已删除]';
  2155. var checked = false;
  2156. } else {
  2157. var checked = true;
  2158. }
  2159. 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>';
  2160. }
  2161. html += '</ul>';
  2162. }
  2163. }
  2164. html += '</div>';
  2165. html += '<textarea name="'+api_name+'" style="display:none">'+select_api_json+'</textarea>';
  2166. $(id + '_data').html(html);
  2167. }
  2168. }
  2169. /*
  2170. function select_mul(level, id, url, name, value, valid, w, num)
  2171. {
  2172. if(level == 0)
  2173. {
  2174. $(id).find('select').remove();
  2175. $(id).find('span').remove();
  2176. return;
  2177. }
  2178. var parent = value.split(',');
  2179. var cur = parent[0];
  2180. parent.remove(cur);
  2181. value = parent.join(',');
  2182. var html = '';
  2183. var old = level;
  2184. if(level != -1)
  2185. {
  2186. if($(id + '_' + level).length)
  2187. {
  2188. level = $(id + '_' + level).val();
  2189. }
  2190. alert(level);
  2191. if(level == 0)
  2192. {
  2193. $(id + '_' + old).nextAll('select').remove();
  2194. $(id + '_' + old).next('span').nextAll('span').remove();
  2195. if($('#' + name + '_level_value').length)
  2196. {
  2197. var total = $(id).find('select').length;
  2198. $('#' + name + '_level_value').val(total);
  2199. }
  2200. if(old == -2 && $('#' + name + '_value_value').length)
  2201. {
  2202. $('#' + name + '_value_value').val(level);
  2203. }
  2204. return;
  2205. }
  2206. if(old == -2)
  2207. {
  2208. $(id + '_' + old).nextAll('select').remove();
  2209. $(id + '_' + old).next('span').nextAll('span').remove();
  2210. }
  2211. if($('#' + name + '_value_value').length)
  2212. {
  2213. $('#' + name + '_value_value').val(level);
  2214. }
  2215. }
  2216. var total = $(id).find('select').length;
  2217. if(num > 0 && total >= num)
  2218. {
  2219. return;
  2220. }
  2221. var get = url.replace('{level}', level);
  2222. if(level == -1)
  2223. {
  2224. level = -2;
  2225. }
  2226. if(!$(id + '_' + level).length)
  2227. {
  2228. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  2229. {
  2230. var check = '';
  2231. if(t.status == 1)
  2232. {
  2233. 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+');">';
  2234. console.log(t.data);
  2235. for(a in t.data)
  2236. {
  2237. if(t.data[a].value)
  2238. {
  2239. check = '';
  2240. if(cur == t.data[a].value)
  2241. {
  2242. check = ' selected';
  2243. }
  2244. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  2245. }
  2246. }
  2247. html += '</select><span>&nbsp;&nbsp;</span>';
  2248. $(id).append(html);
  2249. $(id + '_' + level).change();
  2250. }
  2251. else
  2252. {
  2253. $(id + '_' + old).nextAll('select').remove();
  2254. $(id + '_' + old).next('span').nextAll('span').remove();
  2255. }
  2256. if($('#' + name + '_level_value').length)
  2257. {
  2258. var total = $(id).find('select').length;
  2259. $('#' + name + '_level_value').val(total);
  2260. }
  2261. if($('#' + name + '_up_value').length)
  2262. {
  2263. $('#' + name + '_up_value').val($(id + '_-2').val());
  2264. }
  2265. });
  2266. }
  2267. }
  2268. */
  2269. //处理更新页面的一些功能,写到一起吧
  2270. var dever_update =
  2271. {
  2272. addIndex : 2,
  2273. index : [],
  2274. auto : false,
  2275. save_key : '',
  2276. init : function()
  2277. {
  2278. var self = this;
  2279. self.index = [];
  2280. // 增加整个更新的表单
  2281. if($(".dever_update_add").length)
  2282. {
  2283. $('.dever_update_add').unbind('click').bind('click', function()
  2284. {
  2285. self.add($(this));
  2286. })
  2287. }
  2288. /* 以后再增加 同时更新另外一个表
  2289. if($(".form-add-content").length)
  2290. {
  2291. var url = config.host + 'auth.password';
  2292. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  2293. $.get(url, function(t)
  2294. {
  2295. $(".form-add-content").html(t);
  2296. init();
  2297. })
  2298. }
  2299. */
  2300. //增加某一部分表单
  2301. if($(".dever_form_add").length)
  2302. {
  2303. $('.dever_form_add').each(function()
  2304. {
  2305. var key = $.attr('toggle_key');
  2306. if(typeof(self.index[key]) == "undefined")
  2307. {
  2308. self.index[key] = 0;
  2309. }
  2310. $(this).unbind('click').bind('click', function()
  2311. {
  2312. self.append($(this));
  2313. })
  2314. })
  2315. self.del();
  2316. }
  2317. // 开启自动保存
  2318. if($("#struct").length)
  2319. {
  2320. var save = $("#struct").attr('save');
  2321. if(save == 'yes')
  2322. {
  2323. //检测
  2324. self.save_key = location.href + 'test';
  2325. self.check();
  2326. }
  2327. }
  2328. if($('.dever-note').length)
  2329. {
  2330. $('.dever-note').each(function()
  2331. {
  2332. var mditor = new Mditor($(this),{
  2333. fixedHeight:true
  2334. });
  2335. mditor.openPreview();
  2336. })
  2337. }
  2338. },
  2339. save : function()
  2340. {
  2341. //var data = $("#data-1").html();
  2342. var data = [];
  2343. $(".update_value").each(function(i)
  2344. {
  2345. if($(this).attr("update_type") == 'checked')
  2346. {
  2347. data[i] = $(this).get(0).checked;
  2348. }
  2349. else if($(this).attr("update_type") == 'html')
  2350. {
  2351. data[i] = $(this).html();
  2352. }
  2353. else if($(this).attr("update_type") == 'src')
  2354. {
  2355. data[i] = $(this).attr('src');
  2356. }
  2357. else
  2358. {
  2359. data[i] = $(this).val();
  2360. }
  2361. });
  2362. store.set(this.save_key, data.join('|||'));
  2363. //console.info(data);
  2364. },
  2365. recover : function()
  2366. {
  2367. var index = layer.confirm('确定恢复上次保存的数据吗?', function()
  2368. {
  2369. var data = store.get(this.save_key).split('|||');
  2370. if(data)
  2371. {
  2372. var value = $(".update_value");
  2373. for(var k in data)
  2374. {
  2375. var e = value.eq(k);
  2376. if(e.attr('update_type') == 'checked')
  2377. {
  2378. if(data[k] == 'true')
  2379. {
  2380. e.get(0).checked = true;
  2381. }
  2382. else
  2383. {
  2384. e.get(0).checked = false;
  2385. }
  2386. }
  2387. else if(e.attr('update_type') == 'html')
  2388. {
  2389. e.html(data[k]);
  2390. }
  2391. else if(e.attr('update_type') == 'src')
  2392. {
  2393. e.attr('src', data[k]);
  2394. }
  2395. else
  2396. {
  2397. if(e.attr('id'))
  2398. {
  2399. var id = e.attr('id');
  2400. if(typeof(editors[id]) != "undefined")
  2401. {
  2402. editors[id].html(data[k]);
  2403. }
  2404. }
  2405. e.val(data[k]);
  2406. }
  2407. }
  2408. store.set(this.save_key, '');
  2409. this.check();
  2410. }
  2411. })
  2412. },
  2413. check : function()
  2414. {
  2415. var data = store.get(this.save_key);
  2416. var self = this;
  2417. if(data)
  2418. {
  2419. $(".dever_save").unbind('click').bind('click', function()
  2420. {
  2421. self.recover();
  2422. }).show();
  2423. }
  2424. else
  2425. {
  2426. $(".dever_save").hide();
  2427. self.auto = setInterval(function(){self.save()}, 3000);
  2428. }
  2429. },
  2430. del : function()
  2431. {
  2432. var self = this;
  2433. if($(".dever_form_delete").length)
  2434. {
  2435. $('.dever_form_delete').each(function()
  2436. {
  2437. $(this).unbind('click').bind('click', function()
  2438. {
  2439. var parent = $(this).parent();
  2440. var id = parent.attr('id');
  2441. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  2442. var key = $('#tab-' + id).attr('toggle_key');
  2443. if(index <= 1 && self.index[key] <= index)
  2444. {
  2445. }
  2446. else if(index <= 1 && self.index[key] > index)
  2447. {
  2448. index = index+1;
  2449. $("#tab-"+key+"-child-" + index).click();
  2450. }
  2451. else
  2452. {
  2453. index = index-1;
  2454. $("#tab-"+key+"-child-" + index).click();
  2455. };
  2456. $('#tab-' + id).parent().remove();
  2457. parent.remove();
  2458. self.index[key]--;
  2459. })
  2460. })
  2461. }
  2462. },
  2463. append : function(e)
  2464. {
  2465. var self = this;
  2466. var key = e.attr('toggle_key');
  2467. var child = '.dever_'+key+'_child';
  2468. if(typeof(self.index[key]) == "undefined")
  2469. {
  2470. self.index[key] = 0;
  2471. }
  2472. if (isNaN(self.index[key])) {
  2473. self.index[key] = 0;
  2474. }
  2475. if(self.index[key] <= 0)
  2476. {
  2477. self.index[key] = $(child).length;
  2478. }
  2479. if(self.index[key] > 30)
  2480. {
  2481. layer.showAlert('最多只能增加30条');
  2482. return;
  2483. }
  2484. var p = e.parent();
  2485. var id = key + '-child-' + self.index[key];
  2486. var name = '第' + (self.index[key]) + '条';
  2487. 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>');
  2488. var e = e.parent().parent();
  2489. var n = e.next();
  2490. var p = e.parent();
  2491. var content = n.html();
  2492. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  2493. content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  2494. p.append(content);
  2495. if ($("#" + id).find('.ke-container').length >= 1) {
  2496. $("#" + id).find('.ke-container').eq(0).remove();
  2497. }
  2498. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  2499. self.del();
  2500. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  2501. self.index[key]++;
  2502. image();
  2503. loadShow();
  2504. autocomplete();
  2505. change();
  2506. layui.use(['formSelects'], function(){
  2507. $('#' + id + " select").each(function()
  2508. {
  2509. if ($(this).attr('xm-select')) {
  2510. layui.formSelects.render($(this).attr('xm-select'));
  2511. }
  2512. })
  2513. });
  2514. },
  2515. add : function(e)
  2516. {
  2517. var self = this;
  2518. var p = e.parent();
  2519. var id = 'data-' + this.addIndex;
  2520. var name = '新增数据-' + (this.addIndex-1);
  2521. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  2522. var content = $("#content").find('.tab-pane').eq(0).html();
  2523. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  2524. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  2525. $("#content").append(content);
  2526. $('#update_' + this.addIndex + '__where_id').val('-1');
  2527. this.addIndex++;
  2528. }
  2529. }
  2530. $.fn.pasteEvents = function( delay ) {
  2531. if (delay == undefined) delay = 20;
  2532. return $(this).each(function() {
  2533. var $el = $(this);
  2534. $el.on("paste", function() {
  2535. $el.trigger("prepaste");
  2536. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  2537. });
  2538. });
  2539. };
  2540. $("textarea").on("postpaste", function()
  2541. {
  2542. if($(this).val().indexOf('<') != -1)
  2543. {
  2544. $(this).val(toMarkdown($(this).val()));
  2545. }
  2546. }).pasteEvents();
  2547. function showYes(msg)
  2548. {
  2549. if (msg.status == 2) {
  2550. layer.alert(msg.msg);
  2551. } else {
  2552. showAlert('保存成功', function() {
  2553. if (select_api_open) {
  2554. $('.layui-layer-content').css('overflow-x', 'auto');
  2555. $('#update_button').show();
  2556. layer.closeAll();
  2557. } else {
  2558. if(msg.data.indexOf('http') != -1) {
  2559. location.href = msg.data;
  2560. } else {
  2561. location.reload()
  2562. }
  2563. }
  2564. });
  2565. }
  2566. }
  2567. function setDay(e, d)
  2568. {
  2569. $('#search_option_sday').val(d);
  2570. $('.sday_button').removeClass('sday_button_border');
  2571. e.addClass('sday_button_border');
  2572. var date = new Date();
  2573. var year = date.getFullYear();
  2574. var month = date.getMonth()+1;
  2575. var day = date.getDate();
  2576. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  2577. //获取30天前得日期
  2578. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  2579. var lastY = lastDate.getFullYear();
  2580. var lastM = lastDate.getMonth()+1;
  2581. var lastD = lastDate.getDate();
  2582. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  2583. $('.manage_sday').eq(0).val(LDate);
  2584. $('.manage_sday').eq(1).val(nowDate);
  2585. }
  2586. function setDate(e, d)
  2587. {
  2588. $('#search_option_sdate').val(d);
  2589. $('.sdate_button').removeClass('sdate_button_border');
  2590. e.addClass('sdate_button_border');
  2591. var date = new Date();
  2592. var year = date.getFullYear();
  2593. var month = date.getMonth()+1;
  2594. var day = date.getDate();
  2595. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  2596. //获取30天前得日期
  2597. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  2598. var lastY = lastDate.getFullYear();
  2599. var lastM = lastDate.getMonth()+1;
  2600. var lastD = lastDate.getDate();
  2601. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  2602. $('.manage_sdate').eq(0).val(LDate + ' 00:00:00');
  2603. $('.manage_sdate').eq(1).val(nowDate + ' 23:59:59');
  2604. }
  2605. function showVideo(video)
  2606. {
  2607. var html = '<meta name="referrer" content="no-referrer"><video width="400" height="300" controls autoplay="autoplay"><source src="'+video+'" type="video/mp4">您的浏览器不支持Video标签。</video>';
  2608. showAlert(html);
  2609. }