main.js 63 KB

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