main.js 77 KB

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