123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939 |
- //这里的代码是最早写的,很乱,以后整合优化
- var editors = [];
- var editors_index = [];
- var tables = [];
- var select = '';
- var submitButton = '';
- var editorWidth = 0;
- var admingroup = false;
- String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
- if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
- return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
- } else {
- return this.replace(reallyDo, replaceWith);
- }
- }
- Array.prototype.remove = function(val) {
- var index = -1;
- for(var i = 0; i < this.length; i++)
- {
- if(this[i] == val)
- {
- index = i;
- }
- }
- if (index > -1) {
- this.splice(index, 1);
- }
- };
- Array.prototype.replaceOne = function(old, val) {
- var index = -1;
- for(var i = 0; i < this.length; i++)
- {
- if(this[i] == old)
- {
- index = i;
- }
- }
- if (index > -1) {
- this.splice(index, 1, val);
- }
- };
- $(document).ready(function()
- {
- //init();
- });
- function init(ew)
- {
- if (ew) {
- editorWidth = ew;
- } else {
- editorWidth = 0;
- }
- editors = [];
- editors_index = [];
- initEditor();
- select = '';
- edit();
- del();
- checkbox();
- image();
- change();
- autocomplete();
- template();
- submit();
- loadShow();
- initPic();
- initDate();
- initLayui();
- initColor();
- initUpdate();
- initClipboard();
- initEmoji();
- initSearch();
- //更新页面一些功能,上边的一些功能等找时间再优化吧
- dever_update.init();
- hljs.initHighlightingOnLoad();
- table();
- }
- function initSearch()
- {
- $("#form1 input").bind('keypress', function (event) {
- if (event.keyCode == 13) {
- $("#search_button").click();
- }
- });
- }
- function initEmoji()
- {
- if ($('.dever-emoji').length) {
- $('.dever-emoji').each(function()
- {
- emoji($(this), $(this).html());
- })
- }
- }
- function emoji(e, content)
- {
- var handle = function()
- {
- e.html(twemoji.parse(content)).show(200);
- };
- if (typeof jEmoji != 'object') {
- $.getScript('//twemoji.maxcdn.com/2/twemoji.min.js?11.4', function() {
- /*
- $("head").append("<link>");
- var css = $("head").children(":last");
- css.attr({
- rel: "stylesheet",
- type: "text/css",
- href: config.script + '/lib/emoji/emoji.css'
- });
- */
- return handle();
- });
- } else {
- return handle();
- }
- }
- function checkClick(e)
- {
- var objEvt = $._data(e[0], "events");
- if (objEvt && !objEvt["click"]) {
- return false;
- }
- return true;
- }
- function initClipboard()
- {
- var clipboard = new ClipboardJS('.clipboard');
- clipboard.on('success', function(e) {
-
- notify('复制成功', e.trigger);
- e.clearSelection();
- });
- clipboard.on('error', function(e) {
- notify('复制失败', e.trigger);
- });
- }
- function initUpdate()
- {
- if ($('.update_show_editor').length) {
- $('.update_show_editor').each(function() {
- $(this).bind('click', function()
- {
- var url = $(this).attr('key');
- var value = $(this).attr('editor_id');
- var title = $(this).attr('value');
- var send = '';
- if ($(this).attr('data-value')) {
- send = $(this).attr('data-value');
- }
- $.post(url, {value:send}, function(t)
- {
- var func = function() {
- var url = $('#editor_applet_pic').val();
- var appid = $('#editor_applet_id').val();
- var path = $('#editor_applet_path').val();
- var link = $('#editor_applet_link').val();
- if (!appid) {
- //alert('请选择小程序');
- //return;
- }
- if (!path) {
- alert('请填写路径');
- return;
- }
- if (!url) {
- alert('请上传封面');
- return;
- }
-
-
- var w = 750/2;
- KindEditor.insertHtml('#' + value, '<img src="'+url+'" style="width:'+w+'px;" data-applet="'+url+'||'+appid+'||'+path+'||'+link+'"/>');
- layer.closeAll();
- };
- showAlert(t, func, title);
- image();
- })
- })
-
- });
- }
- }
- function initLayui()
- {
- layui.use('layer', function() {
- var layer = layui.layer;
- layer.ready(function() {
- $(".dever-img").each(function()
- {
- layer.photos({
- photos: '#' + $(this).attr('id'),
- shade : 0.5
- });
- });
- });
- });
- }
- function initColor()
- {
- if ($('.dever-color').length) {
- $('.dever-color').each(function()
- {
- var self = $(this);
- var val = self.val();
- if (!val) {
- val = '#000000';
- }
- self.css('border-right', '40px solid '+val);
- self.colpick({
- layout:'hex',
- submit:0,
- colorScheme:'dark',
- color: val,
- onChange : function (hsb,hex,rgb,el,bySetColor) {
- $(el).css('border-color','#'+hex);
- if(!bySetColor) $(el).val('#' + hex);
- }
- }).keyup(function(){
- $(this).colpickSetColor(this.value);
- });
- })
-
- }
- }
- function formData(form)
- {
- var d = {};
- var t = $(form).serializeArray();
- var u = '';
- $.each(t, function() {
- if (this.name.indexOf('search_') != -1) {
- d[this.name] = this.value;
- u += '&' + this.name + '=' + this.value;
- }
- });
- return [d,u];
- }
- function initMenu()
- {
- if(typeof(config.layout) != "undefined")
- {
- $('.list-unstyled li').each(function(j)
- {
- $(this).unbind('click').bind('click', function()
- {
- if ($(this).index() == i) {
- //return;
- }
- $('.list-unstyled .active').each(function()
- {
- $(this).attr('class', '');
- $(this).find('a').attr('class', '');
- })
- $(this).attr('class', 'active');
- var a = $(this).find('a');
- a.attr('class', 'subdrop');
- //alert($(this).attr('class'));
- })
- });
- /*
- $('.project-list').each(function(i)
- {
- $(this).unbind('click').bind('click', function()
- {
- if ($(this).index() == i) {
- return;
- }
- $('.project-list').each(function()
- {
- $(this).find('i').parent().attr('class', '');
- $(this).find('ul').attr('class', 'list-unstyled upload-menu');
- })
- $(this).find('i').parent().attr('class', 'active');
- $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
- })
- });
- */
- }
- }
- function setOption(e, id)
- {
- var s = $("select[name="+id+"]");
- var v = s.val();
- if (!select) {
- select = s.clone();
- }
-
- s.find('option[parent]').remove();
- //查找出需要显示的option并复制
- var options = select.find("option[parent="+e.val()+"]").clone();
- //将需要显示的option添加到select中
- s.append(options);
- //因为option.remove()不会刷新控件,需要将新的option切换上去
- //这里排除了options.size() == 0的情况
- var state = 2;
- s.find('option').each(function()
- {
- var val = $(this).val();
- if (v == val) {
- state = 1;
- }
- });
- if (state == 1) {
- s.val(v);
- } else {
- s.val(0);
- }
-
- }
- function table()
- {
- if ($('.table-responsive').length) {
- $('.table-responsive[data-pattern]').each(function()
- {
- $(this).responsiveTable('update');
- });
- }
- }
- function pjax(param)
- {
- param.timeout = 8000;
- $.pjax(param);
-
- }
- function initDate()
- {
- $.datetimepicker.setLocale('ch');
-
- if($(".manage_date").length)
- {
- $(".manage_date").each(function()
- {
- $(this).datetimepicker(
- {
- //datepicker:false,
- format:'Y-m-d H:i:s',
- lang:'ch'
- });
- });
- }
- if($(".manage_day").length)
- {
- $(".manage_day").each(function()
- {
- $(this).datetimepicker(
- {
- //inline:true,
- timepicker:false,
- format:'Y-m-d',
- lang:'ch'
- });
- });
- }
- if($(".manage_sday").length)
- {
- $(".manage_sday").each(function()
- {
- $(this).datetimepicker(
- {
- //inline:true,
- timepicker:false,
- format:'Y-m-d',
- lang:'ch'
- });
- });
- }
- if($(".manage_sdate").length)
- {
- $(".manage_sdate").each(function()
- {
- $(this).datetimepicker(
- {
- //datepicker:false,
- format:'Y-m-d H:i:s',
- lang:'ch'
- });
- });
- }
- layui.use('laydate', function() {
- var laydate = layui.laydate;
- if ($('.manage_year').length) {
- $('.manage_year').each(function(i) {
- $(this).attr('id', 'manage_year_' + i);
- laydate.render({
- elem: '#manage_year_' + i,
- type: 'year',
- });
- })
- }
- if ($('.manage_month').length) {
- $('.manage_month').each(function(i) {
- $(this).attr('id', 'manage_month_' + i);
- laydate.render({
- elem: '#manage_month_' + i,
- type: 'month',
- });
- })
- }
-
- });
- }
- function initPic()
- {
- $('a[rel]').fancybox();
- }
- function initEditor(e)
- {
- if (!e) {
- e = $('.editor');
- }
- if(e.length)
- {
- var param = false;
- var editor = [];
- e.each(function()
- {
- var parent = $(this).parent().parent();
- //alert(parent.attr('id'));
- if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
- {
- return;
- }
- if (!param) {
- param = loadEditorParam($(this));
- }
- editor.push($(this).attr('id'));
- });
- if (editor) {
- for (var i in editor) {
- var id = editor[i];
- if (typeof(id) == 'string' && !editors[id]) {
- param.index = editors_index.length;
- editors[id] = KindEditor.create('#' + id, param);
- editors_index.push(id);
- }
- }
- }
- }
- if ($('.editor_tool').length) {
- $('.editor_tool').each(function()
- {
- $(this).click(function()
- {
- var tool = $(this).attr('tool');
- var id = $(this).attr('editor_id');
- editors[id].clickToolbar(tool);
- })
- });
- }
- }
- function loadEditorParam(e)
- {
- if(!e.length)
- {
- return;
- }
- var key = e.attr('key');
- var media = e.attr('media');
- var token = e.attr('token');
- var host = e.attr('host');
- var domain = e.attr('domain');
- var path = e.attr('path');
- var upload_search = e.attr('upload_search');
- var upload_search_value = e.attr('upload_search_value');
- var yun = {};
- if (token && host) {
- yun.token = token;
- yun.host = host;
- yun.domain = domain;
- yun.path = path;
- }
- if (!key) {
- key = 1;
- }
- if (!media) {
- media = 3;
- }
- var view = config.upload.replace('save', 'view');
- var param = {
- height : "400px",
- allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
- allowImageRemote : true, //上传图片框网络图片的功能,false为隐藏,默认为true
- allowFileManager : true, //浏览图片空间
- allowMediaUpload : true,
- filterMode : false, //HTML特殊代码过滤
- themeType : 'default',
- filePostName : 'file',
- dialogOffset : 0, //对话框距离页面顶部的位置,默认为0居中,
- uploadJson : config.upload + '.kindeditor?key=' + key + '&search=' + upload_search_value,
- uploadResJson : config.uploadRes + '.kindeditor?key=' + key + '&search=' + upload_search_value,
- uploadMediaJson : config.upload + '.kindeditor?key=' + media + '&search=' + upload_search_value,
- uploadYunJson : yun,
- fileManagerJson : view + '.files?key=' + key + '&upload_search=' + upload_search,
- mediaManagerJson : view + '.files?key=' + media + '&upload_search=' + upload_search,
- htmlTags : {
- section : ['id', 'class', 'color', 'size', 'face', '.background-color'],
- font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
- span : [
- 'id', 'class', '.color', '.background-color', '.font-size','.letter-spacing', '.background',
- '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
- ],
- div : [
- 'id', 'class', 'data-applet', 'data-file', 'data-id', 'data-key','.dever-video', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
- '.background-color', '.font-size','.letter-spacing', '.font-weight', '.background',
- '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
- ],
- table: [
- 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
- '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
- '.font-size', '.font-weight', '.font-style', '.text-decoration', '.background',
- '.width', '.height', '.border-collapse'
- ],
- 'td,th': [
- 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
- '.text-align', '.color', '.background-color', '.font-size','.letter-spacing', '.font-weight',
- '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
- ],
- a : ['id', 'class', 'href', 'target', 'name'],
- embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
- img : ['id', 'class', 'data-applet', 'data-file', 'data-id', 'data-key', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
- 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
- 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size','.letter-spacing', '.background',
- '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
- ],
- pre : ['id', 'class'],
- hr : ['id', 'class', '.page-break-after'],
- 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
- iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
- },
- items : [
- 'preview', 'undo', 'redo', '|', 'cut', 'copy', 'paste',
- 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
- 'justifyfull', 'indent', 'outdent', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', 'source', '/',
- 'formatblock', 'fontsize', 'fontheight', '|', 'forecolor', 'hilitecolor', 'bold',
- 'italic', 'underline', 'lineheight', 'removeformat', 'insertorderedlist','|', 'image','table', 'hr', 'pagebreak','link', 'unlink'
- ]
- /*,'media'
- items : [
- 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
- 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
- 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
- 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
- 'formatblock', 'fontsize', 'fontheight', '|', 'forecolor', 'hilitecolor', 'bold',
- 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage','table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
- 'anchor', 'link', 'unlink'
- ]
- */
- //media
- /*
- items : [
- 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
- 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
- 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
- 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
- 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
- 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
- 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
- 'anchor', 'link', 'unlink', '|', 'about'
- ]
- */
- }
- if (editorWidth > 0) {
- param.width = editorWidth + 'px';
- param.minWidth = editorWidth + 'px';
- }
- return param;
- }
- //更新页面的提交按钮
- function submit()
- {
- if($(".save-data").length)
- {
- if (submitButton) {
- $(".save-data").each(function()
- {
- $(this).html(submitButton);
- })
- }
-
- $(".save-data").unbind('click').bind('click', function()
- {
- if (editors) {
- for (var i in editors) {
- if (i.indexOf('update_') != -1) {
- editors[i].sync();
- }
- }
- }
- //return;
- submitButton = $(this).html();
- $(this).html('loading...');
- $(this).unbind('click');
- submit_action();
- })
- }
- }
- //直接提交更新页的数据
- function submit_action()
- {
- $(".form1").submit();
- }
- //设置某一个input的值
- function set_update(id, value)
- {
- if($(id).length)
- {
- $(id).val(value);
- }
- }
- /**
- * 批量复制数据
- */
- function copy_data(e)
- {
- var html = '<div>';
- html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
- html += '</div>';
- $('#dever_modal_body').html(html);
-
- $('#dever_modal_title').html('复制数据');
-
- $("#dever_modal_yes").unbind('click').bind('click', function()
- {
- set_update('#copy_num', $("#temp_copy_num").val());
- set_update('#update_where_id', 0);
- submit_action();
- });
- }
- //头部菜单
- function topMenu(e)
- {
- var p = e.parent().parent().parent().find('span');
- p.html(e.html());
- //更新当前的精细权限
- var url = config.host + 'top.update_action?json=1';
- var id = e.attr('data-id');
- $.post(url, {id:id}, function(t)
- {
- var href = location.href;
- if(location.href.indexOf('where_id') != -1)
- {
- var temp = location.href.split('where_id');
- href = temp[0] + 'where_id=' + t;
- }
- if(typeof(config.layout) != "undefined" && $(config.layout).length)
- {
- pjax({url: href, container: config.layout})
- }
- else
- {
- location.href = href;
- }
- })
- }
- //头部菜单
- function topCMenu(e)
- {
- var p = e.parent().parent().parent().find('span');
- p.html(e.html());
- //更新当前的精细权限
- var url = config.host + 'company.set?json=1';
- var id = e.attr('data-id');
- $.post(url, {company_id:id}, function(t)
- {
- location.reload();
- })
- }
- //链接跳转
- function go(key, value)
- {
- var href = location.href;
- if(location.href.indexOf(key) != -1)
- {
- var temp = location.href.split(key + '=');
- href = temp[0] + key + '=' + value + '&' + temp[1];
- } else {
- href = href + '&' + key + '=' + value;
- }
- location.href = href;
- }
- //更新页面的批量载入选择
- function loadShow()
- {
- if($(".show_input").length)
- {
- $(".show_input input:radio").each(function()
- {
- if ($(this).attr('checked'))
- {
- inputShow($(this), $(this).attr('show_id'), 'input');
- }
- var filter = $(this).attr('lay-filter');
- if (filter && filter.indexOf('_all') == -1) {
- form.on('radio('+filter+')', function(data) {
- inputShow($(this), $(this).attr('show_id'), 'input');
- })
- }
- })
- $(".show_input input:checkbox").each(function()
- {
- if ($(this).attr('checked'))
- {
- inputShow($(this), $(this).attr('show_id'), 'input');
- }
- var filter = $(this).attr('lay-filter');
- if (filter && filter.indexOf('_all') == -1) {
- form.on('checkbox('+filter+')', function(data) {
- inputShow($(this), $(this).attr('show_id'), 'input');
- })
- }
- })
- $(".show_input select").each(function()
- {
- if($(this).find('option:selected').text())
- {
- inputShow($(this), $(this).attr('show_id'));
- }
- })
- }
- if($(".control_url").length)
- {
- $(".control_url input:radio").each(function()
- {
- if ($(this).attr('checked'))
- {
- inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
- }
- var filter = $(this).attr('lay-filter');
- if (filter) {
- form.on('radio('+filter+')', function(data) {
- inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
- })
- }
- })
- $(".control_url input:checkbox").each(function()
- {
- if ($(this).attr('checked'))
- {
- inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
- }
- var filter = $(this).attr('lay-filter');
- if (filter) {
- form.on('checkbox('+filter+')', function(data) {
- inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
- })
- }
- })
- $(".control_url select").each(function()
- {
- if($(this).find('option:selected').text())
- {
- inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
- }
- })
- }
- }
- function menuGroup(id, e)
- {
- if (typeof(layer) != 'undefined' && admingroup) {
- layer.close(admingroup);
- }
-
- $('.menu_group').hide();
- $('.menu_group_' + id).show();
- $('.menu_group_' + id).eq(0).addClass('layui-nav-itemed');
- }
- function inputShow(e,n,t)
- {
- $(".show_" + n).hide();
- if (e.attr('v')) {
- var v = e.attr('v');
- } else {
- var v = e.val();
- }
-
-
- if (t == 'input') {
- var item = e.parent().find('input');
- item.each(function()
- {
- if($(this).get(0).checked == true)
- {
- inputShowOne($(this),n);
- }
- });
- } else {
- var item = e.parent().find('select');
- item.each(function()
- {
- if($(this).find('option:selected').text())
- {
- inputShowOne($(this),n);
- }
- });
- }
- var array = ['input', 'textarea'];
- for(var a in array)
- {
- if ($(".show_" + n).find(array[a]).length) {
- var s = $(".show_" + n).find(array[a]);
- var p = s.parent().parent().parent().css('display');
- var c = s.attr('class');
- if (c.indexOf('validate[required]') > -1 && p == 'none') {
- $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
- }
- if (c.indexOf('validates') > -1) {
- $(".show_" + n).find(array[a]).removeClass('validates').addClass('validate[required]');
- }
- }
- }
- }
- function inputShowOne(e,n)
- {
- var value = e.val();
- var ele = '.show_' + n + '_ajax';
- if ($(ele).length) {
- $(ele).each(function()
- {
- var self = $(this);
- var url = self.attr('dever-ajax');
- $.getJSON(url + value + '&callback=?', function(t) {
- self.find('.margin-top').html(t.data);
- inputShowOneValiDate(self);
- checkbox();
- })
- })
-
- } else {
- ele = '.show_' + n + '_' + value;
- inputShowOneValiDate($(ele));
- }
- }
- function inputShowOneValiDate(e)
- {
- e.show();
- var array = ['input', 'textarea'];
- for(var a in array)
- {
- if(e.length && e.attr('class').indexOf('show_no') == -1)
- {
- e.find(array[a]).each(function()
- {
- var parent = $(this).parent();
- if($(this).attr('class') && $(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
- {
- $(this).addClass('validate[required]');
- }
- })
- }
- }
- }
- //批量更新
- var list_mul_state = 1;
- function list_mul(e, t, url)
- {
- if (t == 1) {
- var type = parseInt($("#mul_type").val());
- if(type != 1 && type != 2)
- {
- showAlert('您还没有选择数据');
- return;
- }
- }
-
- if (list_mul_state == 2) {
- showAlert('请不要重复点击');
- return;
- }
- var index = layer.confirm('确定进行此项操作吗?', function()
- {
- list_mul_state = 2;
- $('#method').val('mul');
- $('#function').val('msg');
- layer.close(index);
- if (url) {
- $('#method').val('mul.' + url);
- }
- $('#form1').attr('target', 'f1').submit();
- })
- }
- //搜索
- function list_search(e)
- {
- $('#method').val('search');
- $('#function').val('');
- $('#form1').attr('target', '').submit();
- }
- //更新数据
- function update(e, id, project, table, notice, menu_id)
- {
- var call = function()
- {
- var col = e.attr('data-col').replace('up_col_', '');
- var value = e.val();
- var old = e.attr('data-old');
- var url = config.host + 'database.update_action_commit?json=1';
- $.post(url, {where_id:id,col:col,value:value,project:project,table:table,menu_id:menu_id}, function(t)
- {
- var t = eval('('+t+')');
- if (t.status == 1) {
- e.attr('data-old', value);
- notify('操作已成功!您的操作已修改当前选项!', e);
- preview();
- } else {
- msg(t);
- e.val(old);
- }
- })
- }
- if(notice)
- {
- var index = layer.confirm(notice, function(i, l)
- {
- $(l).find('.layui-layer-btn0').css('pointer-events','none');
- layer.close(index);
- call();
- });
- }
- else
- {
- call();
- }
- }
- function notify(msg, e)
- {
- if (!e) {
- layer.msg(msg);
- return;
- }
- layer.tips(msg, e, {
- tips: [1, '#3595CC']
- });
- /*
- var notice = new PNotify({
- title: '提示信息',
- text: msg,
- buttons: {
- closer: false,
- sticker: false
- }
- });
- notice.get().click(function() {
- notice.remove();
- });
- */
- }
- //模板选择
- function template()
- {
- if(config.template)
- {
- $('body').attr('class', 'theme-' + config.template);
- }
- if($(".selector").length)
- {
- $(".selector").each(function()
- {
- if($(this).data('check') == 'checked')
- {
- selector($(this));
- }
- })
- }
- }
- //选择器
- function selector(e)
- {
- var value = e.data('value');
- var name = e.data('name');
- $('#'+name+'_value').val(value);
- $('.'+name+'_selector').children().css({'border':'2px solid #ccc'});
- e.children().css({'border':'2px solid #1e9fff'});
- if(name == 'update_template')
- {
- $('body').attr('class', 'theme-' + value);
- }
- }
- //根据e的值,获取总数
- var manage_total = {};
- function total(e, data)
- {
- var value = e.val();
-
- if(data.url) {
- var parent = e.parent().parent();
- var tagName = parent.prop("tagName");
- var pid = '';
- if (tagName == 'TD') {
- pid = parent.parent().attr('id');
- }
- data.value = value;
- data.where_id = $('#update_where_id').val();
- data.table = $('#table').val();
- data.project = $('#project').val();
- if (data.col) {
- if (data.col.indexOf(',') != -1) {
- var s = data.col.split(',');
- for (var i in s) {
- if (i >= 0) {
- var a = s[i];
- var k = s[i];
- if (a.indexOf('=') != -1) {
- var t = a.split('=');
- a = t[0];
- k = t[1];
- }
- if (pid) {
- var b = $('#update_'+ (pid + '_i_' + a));
- if (b.length) {
- var ue = b;
- } else {
- var ue = $('#update_'+a);
- }
- } else {
- var ue = $('#update_'+a);
- }
-
- data[k] = ue.val();
- if (!data[k]) {
- data[k] = ue.attr('v');
- }
- if (!data[k]) {
- data[k] = ue.html();
- }
- }
- }
- } else {
- var a = data.col;
- var k = data.col;
- if (a.indexOf('=') != -1) {
- var t = a.split('=');
- a = t[0];
- k = t[1];
- }
- if (pid) {
- var b = $('#update_'+ (pid + '_i_' + a));
- if (b.length) {
- var ue = b;
- } else {
- var ue = $('#update_'+a);
- }
- } else {
- var ue = $('#update_'+a);
- }
- data[k] = ue.val();
- if (!data[k]) {
- data[k] = ue.attr('v');
- }
- if (!data[k]) {
- data[k] = ue.html();
- }
- }
- }
- var url = data.url;
- delete data.url;
- if (!pid) {
- pid = 'pid';
- }
- $.getJSON(url + '&json=1', data, function(s) {
- t = s.data;
- for (var i in t) {
- if (!manage_total[i]) {
- manage_total[i] = {};
- }
- manage_total[i][pid] = 0;
- manage_total[i][pid] += t[i];
- }
- for (var i in manage_total) {
- var s = $('#' + i);
- var n = 0;
- for (var j in manage_total[i]) {
- n += manage_total[i][j];
- }
- s.html(n);
- }
- });
- }
- }
- //根据e的值,来载入其他数据
- function loading(e, data, type)
- {
- if (type == 1) {
- var value = e.attr('v');
- } else {
- var value = e.val();
- if (e.attr('id') && e.attr('id').indexOf('_temp') != -1) {
- var id = e.attr('id').replace('_temp', '');
- if ($('#' + id).length) {
- var value = $('#' + id).val();
- }
- }
- }
-
- if (data.element) {
- if (data.url) {
- data.value = value;
- $.getJSON(data.url + '&json=1', data, function(t) {
- $('#update_'+data.element+'').val(t.data);
- });
- } else {
- $('#update_'+data.element+'').val(value);
- }
- } else if(data.url) {
- var parent = e.parent().parent();
- var tagName = parent.prop("tagName");
- var pid = '';
- if (tagName == 'TD') {
- pid = parent.parent().attr('id');
- }
- data.value = value;
- data.where_id = $('#update_where_id').val();
- data.table = $('#table').val();
- data.project = $('#project').val();
- if (data.col) {
- if (data.col.indexOf(',') != -1) {
- var s = data.col.split(',');
- for (var i in s) {
- if (i >= 0) {
- var a = s[i];
- var k = s[i];
- if (a.indexOf('=') != -1) {
- var t = a.split('=');
- a = t[0];
- k = t[1];
- }
- if (pid) {
- var b = $('#update_'+ (pid + '_i_' + a));
- if (b.length) {
- var ue = b;
- } else {
- var ue = $('#update_'+a);
- }
- } else {
- var ue = $('#update_'+a);
- }
-
- data[k] = ue.val();
- if (!data[k]) {
- data[k] = ue.attr('v');
- }
- if (!data[k]) {
- data[k] = ue.html();
- }
- }
- }
- } else {
- var a = data.col;
- var k = data.col;
- if (a.indexOf('=') != -1) {
- var t = a.split('=');
- a = t[0];
- k = t[1];
- }
- if (pid) {
- var b = $('#update_'+ (pid + '_i_' + a));
- if (b.length) {
- var ue = b;
- } else {
- var ue = $('#update_'+a);
- }
- } else {
- var ue = $('#update_'+a);
- }
- data[k] = ue.val();
- if (!data[k]) {
- data[k] = ue.attr('v');
- }
- }
- }
- var url = data.url;
- delete data.url;
- $.getJSON(url + '&json=1', data, function(s) {
- t = s.data;
- if (typeof(t) == 'object') {
- var r = t.remove;
- if (r) {
- for(var i in r) {
- $(r[i]).remove();
- }
- }
- var o = t.option;
- if (o) {
- for (var i in o) {
- if (pid) {
- var ti = pid + '_i_' + i;
- var ue = $('#update_'+ti);
- } else {
- var ue = $('#update_'+i);
- }
- ue.html(o[i]);
- }
- }
- var d = t.data;
- t = t.html;
- if (d) {
- for(var i in d) {
- if (pid) {
- var ti = pid + '_i_' + i;
- var ue = $('#update_'+ti);
- } else {
- var ue = $('#update_'+i);
- }
- var div = ue.prop("tagName");
- if (d[i] == 'onload') {
- ue.load();
- } else if (d[i] == 'onclick') {
- ue.click();
- } else if (d[i] == 'onkeyup') {
- ue.keyup();
- } else {
- if (div == 'DIV') {
- ue.html(d[i]);
- } else {
- ue.val(d[i]);
- }
- }
- }
- }
- }
- if (t) {
- if (t.indexOf('onblur') != -1) {
- eval(t);
- } else {
- if (t.indexOf('status') == -1) {
- if (data.type == 1) {
- $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- } else {
- $('.checking_-1,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- }
- if (!parent.parent().find('.bind_show').length) {
- if (tagName == 'TD') {
- parent.next().html('<div class="bind_show">' + t + '</div>');
- } else {
- parent.after('<div class="bind_show">' + t + '</div>');
- }
-
- } else if (parent.parent().find('.bind_show').html() != t) {
- parent.parent().find('.bind_show').html(t);
- }
- checkbox();
- }
- }
- }
-
- });
- }
- }
- //根据e的值,来载入其他数据,先检测是否选中
- function checking(name, e, data)
- {
- var value = [];
- $('.' + name).each(function()
- {
- if($(this).get(0).checked == true)
- {
- value.push($(this).val());
- }
- });
- if(data.url)
- {
- data.value = value.join(',');
- data.where_id = $('#update_where_id').val();
- data.table = $('#table').val();
- data.project = $('#project').val();
- if(data.check)
- {
- data.check_value = false;
- $(data.check).each(function()
- {
- if($(this).get(0).checked == true)
- {
- data.check_value = $(this).val();
- }
- });
- }
- var url = data.url;
- delete data.url;
- $.getJSON(url, data, function(s)
- {
- t = s.data;
- var parent = e.parent().parent().parent();
- if(t.indexOf('status') == -1)
- {
- if(data.type == 1)
- {
- $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- }
- else
- {
- $('.checking_-1,.checking_3,.checking_4').each(function()
- {
- $(this).remove();
- });
- }
- parent.after(t);
- checkbox();
- }
- });
- }
- }
- function autocomplete()
- {
- if ($("input").length) {
- $("input").each(function()
- {
- $(this).attr('autocomplete', 'off');
- });
- }
- if($("input[complete]").length)
- {
- $("input[complete]").each(function()
- {
- var cache = {};
- var self = $(this);
- self.autocomplete(
- {
- minLength: 2,
- source: function( request, response )
- {
- var term = request.term.split( /,\s*/ );
- request.term = term.pop();
- if ( request.term in cache ) {
- response( cache[ request.term ] );
- return;
- }
- var cate = self.attr('complete_cate');
- if (cate) {
- request[cate] = $('#update_' + cate).val();
- }
-
-
- $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
- data = data.data
- cache[ term ] = data;
- var state = true;
- for(var i in data)
- {
- if(data[i].id <=0)
- {
- state = false;
- }
- }
- if(state)
- {
- response( data );
- }
- });
- },
- focus: function() {
- // prevent value inserted on focus
- return false;
- },
- select: function( event, ui )
- {
- //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
- var value = self.attr('complete_callback');
- var id = self.attr('id').replace('_temp', '');
- var name = self.attr('name').replace('_temp', '');
- //var e = $("#" + id);
- var e = self;
- 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>';
- if (!$("#" + id + '_show').length) {
- e.parent().append(html);
- }
- if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
- {
- var link = '';
- var attr = '';
- var pic = '';
- if (ui.item['pic']) {
- pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
- }
- if (ui.item['link']) {
- link = ui.item['link'];
- attr = ' target="_blank"';
- }
- var html = '<tr><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+ui.item[value]+'"/> '+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>';
- $("#" + id + '_show').append(html);
-
- if (!autocomplete_value[id]) {
- autocomplete_value[id] = [];
- }
- autocomplete_value[id].push(ui.item[value]);
- }
- ui.item.value = '';
- }
- });
- })
- }
- }
- function autocomplete_del(e, id, value, name)
- {
- e.parent().parent().remove();
- autocomplete_value[id].remove(value);
- var len = autocomplete_value[id].length;
- if (len < 1 && !($('#del_' + name).length)) {
- $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
- }
- }
- function searchbox(id, e)
- {
- var self = e.parent().find("input");
- var v = self.val();
- var key = self.attr('id').replace('_temp', '');
-
- var request = {};
- request.term = v;
- var cate = self.attr('searchbox_cate');
- if (cate) {
- var c = cate.split(',');
- for (var i in c) {
- if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
- request[c[i]] = $('#'+c[i]).val();
- }
- }
- }
- var index = layer.msg('加载中...');
- $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
- layer.close(index);
- var data = data.data;
- if (!data) {
- showAlert('没有搜索到数据');
- return;
- }
- 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+'\')"/> 全选<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>';
- if (data) {
- var j = 0;
- var c = '';
- var s = '';
- var cateHtml = '';
- var content = '';
- for (var i in data) {
- if (j == 0) {
- c = 'class="layui-this"';
- s = 'layui-show';
- } else {
- c = '';
- s = '';
- }
- cateHtml += '<li '+c+'>'+data[i].name+'</li>';
- j++;
- 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}';
- var p = false;
- for (var k in data[i].child) {
- if (data[i].child[k].name) {
- var pic = '';
- if (data[i].child[k].pic) {
- pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
- p = true;
- }
- var check = '';
- if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
- check = 'checked';
- }
- 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>';
- }
- }
- item += '</table></div></div>';
- 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>';
- if (p) {
- head = head.replace('</td><td>', '</td><td>图片</td><td>');
- }
- item = item.replace('{head}', head);
- content += item;
- }
- if (cateHtml) {
- html = html.replace('{cate}', cateHtml);
- }
- if (content) {
- html = html.replace('{content}', content);
- }
- }
-
- var config = {
- type: 1,
- shade: 0.3,
- title : false,
- shadeClose : true,
- area : ['800px', '600px'],
- content: html
- };
- layer.open(config);
- layui.use('element', function(){
- var element = layui.element;
- });
- });
- }
- function searchbox_checkall(e, id)
- {
- $('.' + id).each(function()
- {
- $(this).get(0).checked = e.get(0).checked;
- //$(this).click();
- })
- }
- function searchbox_checkone(e, id, key, value)
- {
- if (!e.get(0).checked) {
- $('#searchbox_check_' + key + '_' + value).remove();
- searchbox_value.remove(value);
- var len = searchbox_value.length;
- var name = key.replace('_value', '');
- if (len < 1 && !($('#del_' + name).length)) {
- $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
- }
- } else {
- var c = '.' + e.attr('data-class');
- searchbox_yes(id, c, false);
- }
- }
- function searchbox_yes(e, c, state)
- {
- var self = $("#" +e);
- $(c).each(function()
- {
- if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
- var value = self.attr('searchbox_callback');
- var id = self.attr('id').replace('_temp', '');
- var name = self.attr('name').replace('_temp', '');
- 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>';
- if (!$("#" + id + '_show').length) {
- self.parent().append(html);
- }
- if (!$("#" + id + '_show').find('#searchbox_check_'+id+'_'+$(this).attr('data-value')).length)
- {
- var link = '';
- var attr = '';
- var pic = '';
- if ($(this).attr('data-pic') && $(this).attr('data-pic') != 'undefined') {
- pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
- }
- if ($(this).attr('data-link')) {
- link = $(this).attr('data-link');
- attr = ' target="_blank"';
- }
- 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')+'"/> '+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>';
- $("#" + id + '_show').append(html);
-
- if (!searchbox_value[id]) {
- searchbox_value[id] = [];
- }
- searchbox_value[id].push($(this).attr('data-value'));
- }
- }
- })
- if (state == true) {
- layer.closeAll();
- }
-
- }
- function searchbox_del(e, id, value, name)
- {
- e.parent().parent().remove();
- searchbox_value.remove(value);
- var len = searchbox_value.length;
- if (len < 1 && !($('#del_' + name).length)) {
- $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
- }
- }
- //后台通用的提示
- function msg(value)
- {
- $("#dever_modal_no").click();
- if(!value.data)
- {
- value.data = value.msg;
- }
- if(value == 1)
- {
- location.reload();
- return;
- }
- submit();
- var url = '';
- if(value.data != 'reload' && value.status == 2 && value.code == 1)
- {
- if ($('#dever_submit').length && value.uuid) {
- $('#dever_submit').val(value.uuid);
- }
- showAlertFlag = false;
- list_mul_state = 1;
- showAlert(value.msg, false, '错误提示');
- //alert(value.data);
- //location.reload();
- return;
- }
- else if(value.data == 'reload')
- {
- if(typeof(config.layout) != "undefined" && $(config.layout).length)
- {
- pjax({url: location.href, container: config.layout})
- }
- else
- {
- location.reload();
- }
- return;
- }
- else if(value.data == 'refer')
- {
- history.back();
- return;
- }
- else
- {
- if(value.data.indexOf('http') != -1)
- {
- url = value.data;
- }
- else if($("#url").length)
- {
- url = $("#url").val();
- }
- else
- {
- notify(value.data)
- return;
- }
- if(url)
- {
- if(typeof(config.layout) != "undefined" && $(config.layout).length)
- {
- pjax({url: url, container: config.layout});
- }
- else
- {
- location.href = url;
- }
- }
- else
- {
- if(typeof(config.layout) != "undefined" && $(config.layout).length)
- {
- pjax({url: location.href, container: config.layout});
- }
- else
- {
- location.reload();
- }
- }
- }
-
- return;
- }
- /**
- * 处理多选问题,处理全选按钮
- */
- function checkbox()
- {
- if($(".autoload").length)
- {
- $(".autoload").each(function()
- {
- if($(this).get(0).checked == true)
- {
- $(this).removeClass('autoload');
- $(this).load();
- }
- });
- }
- if($(".autoload_text").length)
- {
- $(".autoload_text").each(function()
- {
- if($(this).val())
- {
- $(this).removeClass('autoload_text');
- $(this).load();
- }
- });
- }
- var name = 'checkbox-checkall';
- var checkbox = $("." + name);
- if(checkbox.length)
- {
- if (checkbox.attr('title')) {
- checkbox.each(function()
- {
- var self = $(this);
- var ele = "." + name + "-" + self.val();
- var len = $(ele).length;
- $(ele).each(function()
- {
- if(this.checked == true)
- {
- self.get(0).checked = true;
- if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
- inputShow($(this), 'col');
- }
- }
- var filter = $(this).attr('lay-filter');
- if (filter) {
- form.on('checkbox('+filter+')', function (data) {
- var next = $(this).next();
- var state = $(this).attr('data-state');
- if(data.elem.checked == true)
- {
- if (state == 2) {
- self.get(0).checked = true;
- } else {
- if ($("." + name + "-" + self.val()+":checked").length >= len) {
- self.get(0).checked = true;
- }
- }
- if(self.attr('type') == 'radio')
- {
- //如果父选项是radio类型,做下限制
- //alert(1);
- }
- if($("#mul_type").length)
- {
- $("#mul_type").val(1);
- }
-
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', false);
- }
- }
- else
- {
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', true);
- }
- }
- var num = 0;
- var id = $(this).attr('name');
- var hidden = id;
- id = id.replace('[]', '');
- $(ele).each(function()
- {
- if($(this).get(0).checked == true)
- {
- num = 1;
- /*
- if ($('#' + id).length) {
- $('#' + id).remove();
- }*/
- }
- });
- if(num == 0)
- {
- self.get(0).checked = false;
-
- if($("#mul_type").length)
- {
- $("#mul_type").val(0);
- }
- if (state == 2) {
- } else if (!$('#' + id).length) {
- self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+id+'" />');
- }
- }
- form.render('checkbox');
- });
- }
- });
- var filter = self.attr('lay-filter');
- form.on('checkbox('+filter+')', function (data) {
- $("." + name + "-" + $(this).val()).each(function()
- {
- this.checked = data.elem.checked;
- var next = $(this).next();
-
- if(this.checked == true)
- {
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', false);
- }
- if($("#mul_type").length)
- {
- $("#mul_type").val(1);
- }
- }
- else
- {
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', true);
- }
-
- if($("#mul_type").length)
- {
- $("#mul_type").val(0);
- }
- }
- if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('Show') > 0) {
- //inputShow($(this), 'col');
- inputShow($(this), $(this).attr('show_id'), 'input');
- }
- form.render('checkbox');
- });
- });
- form.render('checkbox');
- });
- } else {
- checkbox.unbind('click').bind('click', function()
- {
- var self = $(this);
- $("." + name + "-" + self.val()).each(function()
- {
- $(this).get(0).checked = self.get(0).checked;
-
- var next = $(this).next();
-
- if($(this).get(0).checked == true)
- {
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', false);
- }
- if($("#mul_type").length)
- {
- $("#mul_type").val(1);
- }
- }
- else
- {
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', true);
- }
-
- if($("#mul_type").length)
- {
- $("#mul_type").val(0);
- }
- }
- if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('Show') > 0) {
- //inputShow($(this), 'col');
- inputShow($(this), $(this).attr('show_id'), 'input');
- }
- })
- });
- checkbox.each(function()
- {
- var self = $(this);
- var len = $("." + name + "-" + self.val()).length;
- $("." + name + "-" + self.val()).each(function()
- {
- $(this).unbind('click').bind('click', function()
- {
- var next = $(this).next();
- var state = $(this).attr('data-state');
- if($(this).get(0).checked == true)
- {
- if (state == 2) {
- self.get(0).checked = true;
- } else {
- if ($("." + name + "-" + self.val()+":checked").length >= len) {
- self.get(0).checked = true;
- }
- }
- if(self.attr('type') == 'radio')
- {
- //如果父选项是radio类型,做下限制
- //alert(1);
- }
- if($("#mul_type").length)
- {
- $("#mul_type").val(1);
- }
-
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', false);
- }
- }
- else
- {
- if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
- {
- next.attr('disabled', true);
- }
- }
- var num = 0;
- $("." + name + "-" + self.val()).each(function()
- {
- if($(this).get(0).checked == true)
- {
- num = 1;
- }
- });
-
- var id = $(this).attr('name');
- var hidden = id;
- id = id.replace('[]', '');
- if(num == 0)
- {
- self.get(0).checked = false;
-
- if($("#mul_type").length)
- {
- $("#mul_type").val(0);
- }
- if (state == 2) {
- } else if (!$('#' + id).length) {
- self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
- }
- } else {
- /*
- if ($('#' + id).length) {
- $('#' + id).remove();
- }*/
- }
- })
- if($(this).get(0).checked == true)
- {
- self.get(0).checked = true;
- if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
- inputShow($(this), 'col');
- }
- }
- });
- })
- }
- }
- }
- /**
- * 处理双击编辑
- */
- function edit()
- {
- if($(".edit").length)
- {
- $(".edit").each(function()
- {
- $(this).bind('dblclick', function()
- {
-
- var col = $(this).attr('data-col');
- var project = $(this).attr('data-project');
- var table = $(this).attr('data-table');
- var url = $(this).attr('data-url');
- var id = $(this).attr('data-id');
- var html = $(this).attr('data-content');
- var type = $(this).attr('data-type');
- if($(this).find(".edit-content").length)
- {
- html = $(this).find(".edit-content").html();
- html = html.replace('<!--', '<');
- html = html.replace('-->', '>');
- }
- if (html == '点此编辑') {
- html = '';
- }
- if(html.indexOf('input') == -1)
- {
- if(type && type == 'textarea')
- {
- $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
- }
- else
- {
- $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
- }
- var self = $(this);
- self.find("#edit").focus();
- self.find("#edit").blur(function()
- {
- var value = self.find("#edit").val();
- if(!value)
- {
- alert('不能为空');
- return;
- }
-
- if($(this).find(".edit-content").length)
- {
- $(this).find(".edit-content").html(value);
- }
- else
- {
- self.attr('data-content', value);
- }
-
- self.html(value);
-
- $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
- {
- notify('修改成功', self);
- preview();
- /*
- if(type && type == 'textarea')
- {
- self.html(t);
- }
- */
- })
- })
- }
- });
- })
- }
- }
- function preview()
- {
- if($("#preview").length)
- {
- var time = Date.parse(new Date());
- var src = $('#preview').attr('src').split('#');
- $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
- }
- }
- function del()
- {
- if($(".oper_delete").length)
- {
- $(".oper_delete").each(function()
- {
- var href = $(this).attr('href');
- $(this).attr('href', '#');
- $(this).unbind('click');
-
- $(this).bind('click', function()
- {
- del_act(href);
- });
- })
- }
- }
- /**
- * 处理删除
- */
- function del_act(href)
- {
- var index = layer.confirm('确定进行此项操作吗?', function(i, l)
- {
- $(l).find('.layui-layer-btn0').css('pointer-events','none');
- $.getJSON(href + '&json=1&callback=?', {}, function(t)
- {
- msg(t);
- layer.close(index);
- })
- });
- }
- /**
- * 处理特殊加载的按钮
- */
- function load(href, content, title)
- {
- if (!content) {
- content = '确定进行此项操作吗?';
- }
- if (!title) {
- title = '温馨提示';
- }
- var i = 0;
- var flag = false;
- var send = {title:title}
- var index = layer.confirm(content, send, function(i, l)
- {
- if (!flag) {
- i++;
- $(l).find('.layui-layer-btn0').css('pointer-events','none');
- if(href.indexOf('&') == -1)
- {
- href += '?json=1&callback=?';
- }
- else
- {
- href += '&json=1&callback=?';
- }
- $.getJSON(href, {}, function(t)
- {
- if (t.status == 2) {
- flag = false;
- showAlert(t.msg, false, '错误提示');
- return;
- } else {
- // 修改标志位
- flag = true;
- msg(t);
- layer.close(index);
- //location.reload();
- }
- })
- }
- })
- /*
- showAlert('确定进行此项操作吗?', function()
- {
- $("#dever_modal_no").click();
- $.getJSON(href + '&json=1', {}, function(t)
- {
- msg(t);
- })
- });
- */
- }
- /**
- * 处理特殊页面
- */
- function loadPage(href, title, submit)
- {
- if(href.indexOf('&') == -1)
- {
- href += '?json=1&callback=?';
- }
- else
- {
- href += '&json=1&callback=?';
- }
- $.getJSON(href, {}, function(t)
- {
- var func = false;
- if (submit) {
-
- }
- showAlert(t.data, func, title);
- })
- }
- /**
- * 处理特殊加载的按钮
- */
- function jump(href, form)
- {
- if (form) {
- var param = formData(form);
- href += param[1];
- }
- if (href.indexOf('list_excel') != -1) {
- layer.confirm('确认导出数据吗?', function()
- {
- Excel.export(href);
- })
- } else {
- location.href = href;
- }
- }
- /**
- * 处理change
- */
- function change()
- {
- if($(".change").length)
- {
- $(".change").each(function()
- {
- var key = $(this).attr('data-child');
- /*
- $('.' + key).each(function()
- {
- if($(this).find('select option:selected').val())
- {
- $(this).show();
- $('#set_cate_id_child').get(0).value = $(this).attr('parent');
- }
- });
- */
- $(this).change(function()
- {
- $('.' + key).hide();
- var v = $('.' + key + '_' + $(this).val());
- var s = v.find('select');
- s.change(function()
- {
- $('.' + key + '_value').val($(this).val());
- })
- if(v.length)
- {
- $('.' + key + '_value').val(s.val());
- v.show();
- }
- else
- {
- $('.' + key + '_value').val(-1);
- }
- });
-
- if($(this).val() > 0)
- {
- $(this).change();
- }
- });
- }
- }
- /**
- * 处理图库系统
- */
- function image()
- {
- if($(".dever-note").length)
- {
- $(".dever-note").each(function()
- {
- var key = $(this).attr('key');
- $(this).inlineattachment(
- {
- uploadUrl: config.upload + '.drag?key='+ key
- });
- });
- }
- if($(".image_upload").length)
- {
- $(".image_upload").each(function(i)
- {
- //如果是大文件
- if ($(this).attr('l')) {
- loadUploadL(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');
- } else {
- var parent = $(this).parent().parent();
- //alert(parent.attr('id'));
- if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
- {
- return;
- }
- loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
- }
-
- })
- }
- if($(".upload_show").length)
- {
- $(".upload_show").each(function(i)
- {
- var parent = $(this).parent().parent();
- if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
- {
- return;
- }
- showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
- })
- }
- if($(".upload_cover").length)
- {
- $(".upload_cover").each(function(i)
- {
- var parent = $(this).parent().parent();
- if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
- {
- return;
- }
- showUploadCover(i,$(this),$(this).attr('key'),config.upload + '.videoCover', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
- })
- }
- if($(".upload_show_editor").length)
- {
- $(".upload_show_editor").each(function(i)
- {
- var parent = $(this).parent().parent();
- if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
- {
- return;
- }
- showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 3);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
- })
- }
- }
- /**
- * 修改密码
- */
- function pass(e)
- {
- var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
- html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
- html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
- html += '</div>';
- var edit = function()
- {
- var old_password = $("#edit_old_password").val();
- var new_password = $("#edit_new_password").val();
-
- if(!old_password || !new_password)
- {
- alert('请输入密码');
- return;
- }
- if(old_password == new_password)
- {
- alert('旧密码和新密码相同');
- return;
- }
- $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
- {
- alert(t);
- })
- };
- showAlert(html, edit, '修改密码');
- /*
- $('#dever_modal_body').html(html);
-
- $('#dever_modal_title').html('修改密码');
-
-
- */
- }
- var MSG = [];
- /**
- * 打开弹窗
- */
- //function showMsg(title, e, id, func)
- function showMsg(title, e, id, func, param)
- {
- if(id.indexOf('http://') == -1)
- {
- if($(id).length)
- {
- var html = $(id).html();
-
- if($(id).html())
- {
- var html = $(id).html();
- MSG[id] = html;
- $(id).html('');
- }
- else
- {
- var html = MSG[id];
- }
- }
- else
- {
- var html = id;
- }
- showAlert(html, func, title);
- /*
- $('#dever_modal_body').html(html);
-
- $('#dever_modal_title').html(title);
-
- if (func) {
- $("#dever_modal_yes").unbind('click').bind('click', func);
- } else {
- $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
- }
- */
- }
- else
- {
- var url = id;
- var send = {};
- if (param) {
- send = param;
- }
- if (e && e.attr('msg-send')) {
- send.data = e.attr('msg-send');
- }
- if (url.indexOf('?') != -1) {
- url = url + '&';
- } else {
- url = url + '?';
- }
- $.getJSON(url+'json=1&callback=?',send,function(t)
- {
- t = t.data;
- showAlert(t, func, t);
- /*
- $('#dever_modal_body').html(t);
-
- $('#dever_modal_title').html(title);
-
- if(func)
- {
- $("#dever_modal_yes").unbind('click').bind('click', func);
- }
- */
- });
- }
- }
- function updateMsg(id)
- {
- $("#"+id).submit();
- }
- var showAlertFlag = false;
- function showAlert(msg, func, title, index, t)
- {
- if (!title) {
- title = '温馨提示';
- }
- var type = 0;
- if (msg.indexOf('<') != -1) {
- type = 1;
- }
- if (t) {
- type = t;
- }
- var config = {
- type: 0,
- title: title,
- shade: 0.1,
- shadeClose : true,
- content: msg
- };
- if (index) {
- config.zIndex = index;
- }
- config.scrollbar = false;
- if (type == 1) {
- config.type = 1;
- if (func) {
- config.btn = ['保存', '关闭'];
- } else {
- config.btn = ['关闭'];
- }
- if (window.screen.width >= 800) {
- config.area = ['800px', '550px'];
- }
- } else if (type == 2) {
- config.type = 1;
- config.btn = [];
- if (window.screen.width >= 800) {
- config.area = ['800px', '550px'];
- }
- }
-
- config.cancel = config.btn2 = function(index)
- {
- layer.close(index);
- };
- if (msg.indexOf('保存成功') != -1) {
- config.end = function(index)
- {
- layer.closeAll();
- };
- }
-
- if (func) {
- config.yes = function(index)
- {
- if (!showAlertFlag) {
- showAlertFlag = true;
- func(index);
- }
- };
- } else {
- config.yes = config.cancel;
- }
- config.success = function() {
- //$('.layui-layer-content').css('padding', '10px');
- }
- config.end = function() {
- $('.layui-layer-content').css('overflow-x', 'auto');
- $('#update_button').show();
- }
-
- var index = layer.open(config);
- }
- function fastEdit(e, url, title, col, index, type)
- {
- var func = function()
- {
- $(".fast").submit();
- };
- var send = {};
- if (col) {
- send.col = col;
- }
- $.get(url + '&fast=1',send,function(t)
- {
- var html = '';
- var valid = '';
- var action = '';
- //if ($(t).find('form').length && !$(t).find('#form1').length) {
- if ($(t).find('form').length) {
- if ($(t).find('form').length > 1 && $(t).find('form').eq(1).html()) {
- var form_1 = $(t).find('form').eq(1);
- form_1.addClass('layui-card-body');
- } else {
- var form_1 = $(t).find('form').eq(0);
- }
- action = form_1.attr('action');
- form_1.addClass('fast');
- form_1.find('#function').eq(0).val('showYes');
- var html = form_1.prop("outerHTML");
- if ($(t).find('#valid').length) {
- var valid = $(t).find('#valid').prop("outerHTML");
- html = html + valid;
- }
-
- if (html.indexOf('left: 740px') != -1) {
- html = html.replace('left: 740px', 'left:583px;')
- }
- if ($(t).find('.dever_no_save').length) {
- func = false;
- }
- } else {
- html = t;
- func = false;
- }
- /*
- if ($(html).find('.layui-card-body').length > 0) {
- html = html.replace('class="layui-card-body"', 'class="layui-card-body" style="display:none"');
- html = html.replaceAll('class="layui-btn layuiadmin-btn-list"', 'class="layui-btn layuiadmin-btn-list" style="display:none"');
- }
- */
- if (!action) {
- type = 2;
- func = false;
- }
- showAlertFlag = false;
- if (index == 1) {
- showAlert(html, func, title, 19850422, type);
- } else {
- showAlert(html, func, title, false, type);
- }
- $('.layui-layer-content').css('overflow-x', 'hidden');
- if ($('#update_button').length) {
- $('#update_button').hide();
- }
- layui.use(['form'], function(){
- layui.form.render();
- /*
- $('select').each(function() {
- if ($(this).attr('xm-select')) {
- layui.formSelects.render($(this).attr('xm-select'));
- }
- });*/
- });
- init(560);
- });
- }
- /*
- var test =
- {
- refreshPage: false,
- addAjaxFlag: true,
- //添加收藏
- add: function(cfg)
- {
- }
- }
- */
- function showToggle(e)
- {
- var id = e.attr('toggle');
- var child = e.attr('toggle_child');
- var parent = e.parent();
- parent.parent().find('li').removeClass('active');
- parent.addClass('active');
-
- $(child).fadeOut(100);
- $(id).fadeIn(500);
- initEditor($(id).find('.editor'));
- }
- function addChange(e)
- {
- var val = e.val();
- if (val == 0) {
- var o = e.find('option:selected');
- var type = o.attr('data-type');
- if (type && type == 'add') {
- var url = o.attr('data-url');
- var p = e.parent();
- if (p.find('.addchange').length < 1) {
- p.html(p.html() + '<div class="addchange" style="display: inline-block;margin-left: 10px;"></div>');
- }
- var id = e.attr('id');
- 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>');
- }
- e.val('0');
- }
- }
- function addChangeAction(url, id, self)
- {
- var send = {};
- var e = $('#' + id);
- send.value = $('#add_' + id).val();
- if (!send.value) {
- layer.alert('没有填写内容');
- return;
- }
- send.json = 1;
- $.getJSON(url, send, function(t)
- {
- if (t.status == 1) {
- e.append('<option value="'+t.data.id+'">'+send.value+'</option>');
- e.val(t.data.id);
- self.parent().remove();
- } else {
- layer.alert(t.msg);
- }
- });
- }
- function inputShowUrl(e, url, id)
- {
- if (e.attr('v')) {
- var val = e.attr('v');
- } else {
- var val = e.val();
- }
- var send = {};
- send['json'] = 1;
- send['id'] = id;
- send['value'] = val;
- if (url.indexOf('{') != -1) {
- var start = url.split('{');
- var end = start[1].split('}');
- url = start[0] + end[1];
- if (end[0].indexOf(',')) {
- var param = end[0].split(',');
- } else {
- var param = [];
- param[0] = end[0];
- }
-
- for (var i in param) {
- if (typeof(param[i]) == 'string') {
- var e = $('#update_'+param[i]);
- if (e.length > 1) {
- e.each(function() {
- if ($(this).get(0).checked) {
- send[param[i]] = $(this).val();
- }
- })
- } else {
- send[param[i]] = e.val();
- }
- }
- }
- }
- $.getJSON(url, send, function(t)
- {
- if (t.status == 1) {
- for (var i in t.data) {
- var e1 = $('#update_' + i).parent().parent();
- e1.html(t.data[i]);
- e1.parent().show();
- }
- layui.use(['form'], function(){
- layui.form.render();
- });
- checkbox();
- }
- });
- }
- function loadChange(e, load)
- {
- if (e.attr('v')) {
- var val = e.attr('v');
- } else {
- var val = e.val();
- }
-
- showLoad(load, [val]);
- }
- function showLoad(id, value)
- {
- var e = $('#update_' + id);
- if (!value) {
- e.html('');
- return;
- }
- e.html('加载中...');
- var url = e.attr("data-load");
- var cate = e.attr("data-cate");
- var id = e.attr("data-id");
- var send = {};
- send['json'] = 1;
- if (cate) {
- send[cate] = value.join(',');
- }
- if (id) {
- send['id'] = id;
- }
- $.getJSON(url, send, function(t)
- {
- if (t.status == 1) {
- if (t.data == 'no') {
- if (e.html() == '加载中...') {
- e.html('');
- }
- } else {
- e.html(t.data);
- }
- } else {
- e.html('');
- }
- layui.use(['form'], function(){
- layui.form.render();
- });
- checkbox();
- });
- }
- var level_value = [];
- var select_api = {};
- var select_api_name = [];
- var select_api_title = '';
- var select_api_open = '';
- function select_linkage(level, id, url, name, value, valid, w, total, search, level_param, col, api, type, title, open, load)
- {
- var e = '#' + id;
- var parent = value.split(',');
- var cur = parent[0];
- parent.remove(cur);
- value = parent.join(',');
- var html = '';
- var old = level;
- var level_name = '';
- if (!total) {
- level_id = 0;
- } else {
- level_id = $(e + '_' + level).val();
- if (level_id.indexOf('|') != -1) {
- var temp = level_id.split('|');
- if (level == 1) {
- select_api_name = [];
- }
- level_id = temp[0];
- level_name = temp[1];
- select_api_name[level-1] = level_name;
- }
- if (level >= total) {
- //$(e).show();
- if (load) {
- var key = total-1;
- if (level_value[key]) {
- level_value[key] = level_id;
- } else {
- level_value.push(level_id);
- }
-
- showLoad(load, level_value);
- }
- return;
- }
-
- level = parseInt(level) + 1;
- }
- var api_name = '';
- if (col && api) {
- select_api_title = title;
- select_api_open = open;
- if (name.indexOf('_no') == -1) {
- api_name = name;
- } else {
- var t = name.split('_no');
- api_name = t[0];
- }
-
- name += '_no';
- }
- $.getJSON(url + '&json=1&callback=?', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
- var check = '';
- if (t.status == 1) {
- if (level == 2) {
- level_value = [];
- }
- if (load && level_id > 0) {
- level_value.push(level_id);
- showLoad(load, level_value);
- }
- var total = t.data.level_total;
- var data = t.data.list;
- if(!$(e + '_' + level).length) {
- 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+'\');">';
- }
- for (a in data) {
- if (data[a].value) {
- check = '';
- if (cur == data[a].value) {
- check = ' selected';
- }
- var v = data[a].value;
- if (col && api) {
- v = data[a].value + '|' + data[a].name;
- }
- html += '<option value="'+v+'" '+check+'>'+data[a].name+'</option>';
- }
- }
- if(!$(e + '_' + level).length) {
- html += '</select><span> </span>';
- $(e).append(html);
- $(e + '_' + level).change();
- } else {
- $(e + '_' + level).html(html);
- $(e + '_' + level).change();
- }
- $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
-
- } else {
- if (level == 2) {
- level_value = [];
- if (load && level_id < 0) {
- showLoad(load, false);
- }
- }
- if (load && level_id > 0) {
- level_value.push(level_id)
- showLoad(load, level_value);
- }
- $(e + '_' + old).nextAll('select').remove();
- $(e + '_' + old).next('span').nextAll('span').remove();
- }
- if (col && api && level_id > 0) {
- var send = {};
- send[col] = level_id;
- $.getJSON(api + '&json=1&callback=?', send, function(r) {
- var h = '<ul style="list-style:none;margin-top: 20px;display:;" class="">';
- if (type == 'checkbox') {
- 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=""/> 全选</li>';
- }
- for (var i in r.data) {
- if (r.data[i]['name']) {
- var checked = false;
- 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) {
- checked = true;
- }
- 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'] + '"/> ' + r.data[i]['name'] + '</li>';
- }
- }
-
- h += '</ul>';
- $(e + '_content').html(h);
- });
- }
- /*
- if ($('#' + name + '_level_value').length) {
- var total = $(id).find('select').length;
- $('#' + name + '_level_value').val(total);
- }
- if ($('#' + name + '_up_value').length) {
- $('#' + name + '_up_value').val($(id + '_-2').val());
- }
- */
- });
- if (col && api) {
- select_linkage_check_show(e, api_name);
- }
- }
- function select_linkage_check_all(e, cur, level_id, level_name, id, api_name)
- {
- var checked = e.prop('checked');
- $('.' + cur).each(function() {
- $(this).prop('checked', checked);
- select_linkage_check($(this), level_id, level_name, id, api_name);
- })
- }
- function select_linkage_check(e, level_id, level_name, id, api_name, cid)
- {
- var level_key = 'level_' + level_id;
- if (!select_api[level_key]) {
- select_api[level_key] = {};
- select_api[level_key]['id'] = level_id;
- select_api[level_key]['name'] = level_name;
- select_api[level_key]['value'] = {};
- }
- var value = e.val();
- var temp = value.split('|');
- var key = 'id_' + temp[0];
- if (e.prop('checked')) {
- select_api[level_key]['value'][key] = {};
- select_api[level_key]['value'][key]['id'] = temp[0];
- select_api[level_key]['value'][key]['name'] = temp[1];
- select_api[level_key]['value'][key]['state'] = 1;
- } else {
- if (select_api[level_key] && select_api[level_key]['value'] && select_api[level_key]['value'][key]) {
- select_api[level_key]['value'][key]['state'] = 2;
- }
- if (cid) {
- $(cid).prop('checked', false);
- }
- }
- select_linkage_check_show(id, api_name);
- }
- function select_linkage_check_show(id, api_name)
- {
- if (select_api) {
- var select_api_json = JSON.stringify(select_api);
- var html = '<div style="margin-top: 20px;display:;border: 1px solid #5050b1;padding: 10px;">';
- for (var i in select_api) {
- if (select_api[i]['value']) {
- html += '[' + select_api[i]['name'] + ']:<ul style="list-style:none;" class="">';
- for (var j in select_api[i]['value']) {
- var n = ' ' + select_api[i]['value'][j]['name'];
- if (select_api_open) {
- var o = select_api_open.replace('{id}', select_api[i]['value'][j]['id']);
- n = '<a href="javascript:;" onclick="fastEdit($(this), \''+o+'\', \''+select_api_title+'\', \'\', 1,1)">'+n+'</a>';
- }
- if (select_api[i]['value'][j]['state'] == 2) {
- n += '[已删除]';
- var checked = false;
- } else {
- var checked = true;
- }
- 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>';
- }
- html += '</ul>';
- }
- }
- html += '</div>';
- html += '<textarea name="'+api_name+'" style="display:none">'+select_api_json+'</textarea>';
- $(id + '_data').html(html);
- }
- }
- /*
- function select_mul(level, id, url, name, value, valid, w, num)
- {
- if(level == 0)
- {
- $(id).find('select').remove();
- $(id).find('span').remove();
- return;
- }
- var parent = value.split(',');
- var cur = parent[0];
- parent.remove(cur);
- value = parent.join(',');
- var html = '';
- var old = level;
- if(level != -1)
- {
- if($(id + '_' + level).length)
- {
- level = $(id + '_' + level).val();
- }
- alert(level);
- if(level == 0)
- {
- $(id + '_' + old).nextAll('select').remove();
- $(id + '_' + old).next('span').nextAll('span').remove();
- if($('#' + name + '_level_value').length)
- {
- var total = $(id).find('select').length;
- $('#' + name + '_level_value').val(total);
- }
- if(old == -2 && $('#' + name + '_value_value').length)
- {
- $('#' + name + '_value_value').val(level);
- }
- return;
- }
- if(old == -2)
- {
- $(id + '_' + old).nextAll('select').remove();
- $(id + '_' + old).next('span').nextAll('span').remove();
- }
- if($('#' + name + '_value_value').length)
- {
- $('#' + name + '_value_value').val(level);
- }
- }
- var total = $(id).find('select').length;
- if(num > 0 && total >= num)
- {
- return;
- }
- var get = url.replace('{level}', level);
- if(level == -1)
- {
- level = -2;
- }
- if(!$(id + '_' + level).length)
- {
- $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
- {
- var check = '';
- if(t.status == 1)
- {
- 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+');">';
- console.log(t.data);
- for(a in t.data)
- {
- if(t.data[a].value)
- {
- check = '';
- if(cur == t.data[a].value)
- {
- check = ' selected';
- }
- html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
- }
- }
- html += '</select><span> </span>';
- $(id).append(html);
- $(id + '_' + level).change();
- }
- else
- {
- $(id + '_' + old).nextAll('select').remove();
- $(id + '_' + old).next('span').nextAll('span').remove();
- }
- if($('#' + name + '_level_value').length)
- {
- var total = $(id).find('select').length;
- $('#' + name + '_level_value').val(total);
- }
- if($('#' + name + '_up_value').length)
- {
- $('#' + name + '_up_value').val($(id + '_-2').val());
- }
- });
- }
- }
- */
- //处理更新页面的一些功能,写到一起吧
- var dever_update =
- {
- addIndex : 2,
- index : [],
- auto : false,
- save_key : '',
- init : function()
- {
- var self = this;
- self.index = [];
- // 增加整个更新的表单
- if($(".dever_update_add").length)
- {
- $('.dever_update_add').unbind('click').bind('click', function()
- {
- self.add($(this));
- })
- }
-
- /* 以后再增加 同时更新另外一个表
- if($(".form-add-content").length)
- {
- var url = config.host + 'auth.password';
- var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
- $.get(url, function(t)
- {
- $(".form-add-content").html(t);
- init();
- })
- }
- */
- //增加某一部分表单
- if($(".dever_form_add").length)
- {
- $('.dever_form_add').each(function()
- {
- var key = $.attr('toggle_key');
- if(typeof(self.index[key]) == "undefined")
- {
- self.index[key] = 0;
- }
- $(this).unbind('click').bind('click', function()
- {
- self.append($(this));
- })
- })
- self.del();
- }
-
- // 开启自动保存
- if($("#struct").length)
- {
- var save = $("#struct").attr('save');
-
- if(save == 'yes')
- {
- //检测
- self.save_key = location.href + 'test';
- self.check();
- }
- }
-
- if($('.dever-note').length)
- {
- $('.dever-note').each(function()
- {
- var mditor = new Mditor($(this),{
- fixedHeight:true
- });
-
- mditor.openPreview();
- })
- }
- },
-
- save : function()
- {
- //var data = $("#data-1").html();
- var data = [];
- $(".update_value").each(function(i)
- {
- if($(this).attr("update_type") == 'checked')
- {
- data[i] = $(this).get(0).checked;
- }
- else if($(this).attr("update_type") == 'html')
- {
- data[i] = $(this).html();
- }
- else if($(this).attr("update_type") == 'src')
- {
- data[i] = $(this).attr('src');
- }
- else
- {
- data[i] = $(this).val();
- }
- });
-
- store.set(this.save_key, data.join('|||'));
- //console.info(data);
- },
-
- recover : function()
- {
- var index = layer.confirm('确定恢复上次保存的数据吗?', function(i, l)
- {
- $(l).find('.layui-layer-btn0').css('pointer-events','none');
- var data = store.get(this.save_key).split('|||');
- if(data)
- {
- var value = $(".update_value");
- for(var k in data)
- {
- var e = value.eq(k);
- if(e.attr('update_type') == 'checked')
- {
- if(data[k] == 'true')
- {
- e.get(0).checked = true;
- }
- else
- {
- e.get(0).checked = false;
- }
- }
- else if(e.attr('update_type') == 'html')
- {
- e.html(data[k]);
- }
- else if(e.attr('update_type') == 'src')
- {
- e.attr('src', data[k]);
- }
- else
- {
- if(e.attr('id'))
- {
- var id = e.attr('id');
- if(typeof(editors[id]) != "undefined")
- {
- editors[id].html(data[k]);
- }
- }
-
- e.val(data[k]);
- }
- }
-
- store.set(this.save_key, '');
-
- this.check();
- }
- })
- },
-
- check : function()
- {
- var data = store.get(this.save_key);
- var self = this;
- if(data)
- {
- $(".dever_save").unbind('click').bind('click', function()
- {
- self.recover();
- }).show();
- }
- else
- {
- $(".dever_save").hide();
- self.auto = setInterval(function(){self.save()}, 3000);
- }
- },
-
- del : function()
- {
- var self = this;
- if($(".dever_form_delete").length)
- {
- $('.dever_form_delete').each(function()
- {
- $(this).unbind('click').bind('click', function()
- {
- var parent = $(this).parent();
-
- var id = parent.attr('id');
- var index = parseInt($('#tab-' + id).attr('toggle_id'));
- var key = $('#tab-' + id).attr('toggle_key');
- if(index <= 1 && self.index[key] <= index)
- {
-
- }
- else if(index <= 1 && self.index[key] > index)
- {
- index = index+1;
- $("#tab-"+key+"-child-" + index).click();
- }
- else
- {
- index = index-1;
- $("#tab-"+key+"-child-" + index).click();
- };
-
- $('#tab-' + id).parent().remove();
- parent.remove();
- self.index[key]--;
- })
- })
- }
- },
- append : function(e)
- {
- var self = this;
- var key = e.attr('toggle_key');
- var parent = e.parent().parent().parent();
- var child = '.dever_'+key+'_child';
-
- if(typeof(self.index[key]) == "undefined")
- {
- self.index[key] = 0;
- }
- if (isNaN(self.index[key])) {
- self.index[key] = 0;
- }
-
- if(self.index[key] <= 0)
- {
- self.index[key] = parent.find(child).length;
- }
-
- if(self.index[key] > 100)
- {
- layer.showAlert('最多只能增加100条');
-
- return;
- }
-
- var p = e.parent();
-
- var id = key + '-child-' + self.index[key];
-
- var name = '第' + (self.index[key]) + '条';
-
- 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>');
-
-
- var e = e.parent().parent();
-
- var n = e.next();
- var p = e.parent();
-
- var content = n.html();
-
- content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
-
- var cname = n.attr('class');
- if (cname.indexOf('layui-tab') > -1) {
- content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+'">' + content + '</div>';
- } else {
- //content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
- content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+'">' + content + '</div>';
- }
-
- p.append(content);
- if ($("#" + id).find('.ke-container').length >= 1) {
- $("#" + id).find('.ke-container').eq(0).remove();
- }
- $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order').val())+1);
-
- self.del();
- //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
-
- self.index[key]++;
- image();
-
- loadShow();
- autocomplete();
- change();
- form.render();
- initPic();
- initDate();
- /*
- layui.use(['formSelects'], function(){
- $('#' + id + " select").each(function()
- {
- if ($(this).attr('xm-select')) {
- layui.formSelects.render($(this).attr('xm-select'));
- }
- })
- });
- */
- },
- add : function(e)
- {
- var self = this;
-
- var p = e.parent();
-
- var id = 'data-' + this.addIndex;
-
- var name = '新增数据-' + (this.addIndex-1);
-
- p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
-
- var content = $("#content").find('.tab-pane').eq(0).html();
-
- content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
-
- content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
-
- $("#content").append(content);
-
- $('#update_' + this.addIndex + '__where_id').val('-1');
- this.addIndex++;
- }
- }
- $.fn.pasteEvents = function( delay ) {
- if (delay == undefined) delay = 20;
- return $(this).each(function() {
- var $el = $(this);
- $el.on("paste", function() {
- $el.trigger("prepaste");
- setTimeout(function() { $el.trigger("postpaste"); }, delay);
- });
- });
- };
- $("textarea").on("postpaste", function()
- {
- if($(this).val().indexOf('<') != -1)
- {
- $(this).val(toMarkdown($(this).val()));
- }
- }).pasteEvents();
-
- function showYes(msg)
- {
- if (msg.msg == 'reload') {
- location.reload();
- return;
- }
- showAlertFlag = false;
- if (msg.status == 2) {
- list_mul_state = 1;
- layer.alert(msg.msg);
- } else {
- showAlert('保存成功', function() {
- if (select_api_open) {
- $('.layui-layer-content').css('overflow-x', 'auto');
- $('#update_button').show();
- layer.closeAll();
- } else {
- if(msg.data.indexOf('http') != -1) {
- location.href = msg.data;
- } else if (msg.data && msg.data == 'refer') {
- history.back();
- } else {
- location.reload();
- }
-
- }
- });
- }
- }
- function setDay(e, d)
- {
- $('#search_option_sday').val(d);
- $('.sday_button').removeClass('sday_button_border');
- e.addClass('sday_button_border');
- var date = new Date();
- var year = date.getFullYear();
- var month = date.getMonth()+1;
- var day = date.getDate();
- var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
- //获取30天前得日期
- var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
- var lastY = lastDate.getFullYear();
- var lastM = lastDate.getMonth()+1;
- var lastD = lastDate.getDate();
- var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
- $('.manage_sday').eq(0).val(LDate);
- $('.manage_sday').eq(1).val(nowDate);
- }
- function setDate(e, d)
- {
- $('#search_option_sdate').val(d);
- $('.sdate_button').removeClass('sdate_button_border');
- e.addClass('sdate_button_border');
- var date = new Date();
- var year = date.getFullYear();
- var month = date.getMonth()+1;
- var day = date.getDate();
- var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
- //获取30天前得日期
- var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
- var lastY = lastDate.getFullYear();
- var lastM = lastDate.getMonth()+1;
- var lastD = lastDate.getDate();
- var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
- $('.manage_sdate').eq(0).val(LDate + ' 00:00:00');
- $('.manage_sdate').eq(1).val(nowDate + ' 23:59:59');
- }
- function showVideo(video)
- {
- var html = '<meta name="referrer" content="no-referrer"><video width="400" height="300" controls autoplay="autoplay"><source src="'+video+'" type="video/mp4">您的浏览器不支持Video标签。</video>';
- showAlert(html);
- }
- function sku(e)
- {
- var data = $('#sku_table_col').html();
- data = JSON.parse(data);
- var thead = [];
- var tbody = [];
- var mthead = [];
- var mtbody = [];
- for (var i in data) {
- if (data[i]['verify'] == 'number') {
- var type = 'required|number';
- var value = '0';
- } else {
- var type = 'required';
- var value = '';
- }
- if (data[i]['type'] == 'input') {
- var icon = 'layui-icon-cols';
- } else {
- var icon = '';
- }
- mthead.push({title: data[i]['name'], icon: icon});
- var option = {type: data[i]['type'], field: i, value: value, verify: type, reqtext: data[i]['name'] + '不能为空'};
- if (option.type == 'select') {
- option.option = eval("(" + data[i]['option'] + ")");
- }
- mtbody.push(option);
- if (option.type != 'image') {
- thead.push({title: data[i]['name'], icon: 'layui-icon-cols'});
- tbody.push(option);
- }
- }
- var obj = skuTable.render({
- //规格类型 1统一规格 2多规格
- isAttributeValue: e.attr('data-type'),
- //规格类型容器id
- isAttributeElemId: 'sku_spec_type',
- //规格表容器id
- specTableElemId: 'sku_spec_table',
- //sku表容器id
- skuTableElemId: 'sku_table',
- //规格拖拽排序
- sortable: true,
- //sku表相同属性值是否合并行
- rowspan: true,
- //请求成功返回状态码值
- requestSuccessCode: 1,
- //上传接口地址
- //接口要求返回格式参考 upload.json
- uploadUrl: e.attr('data-upload'),
- //统一规格配置项
- singleSkuTableConfig: {
- thead: thead,
- tbody: tbody
- },
- //多规格配置项
- multipleSkuTableConfig: {
- thead: mthead,
- tbody: mtbody
- },
- //商品id 配合specDataUrl和skuDataUrl使用
- productId: e.attr('data-id'),
- //规格数据, 一般从后台获取,
- specData: [],
- specDataUrl: e.attr('data-spec'),
- skuData : [],
- skuDataUrl: e.attr('data-sku'),
- show : parseInt(e.attr('data-show')),
- });
- }
- var append_total = 10;
- function append(self, id)
- {
- var e = self.parent().parent().parent().find('.table_copy');
- var html = e.html();
- var parent = e.parent();
- var total = parent.find('tr').length-1;
- append_total++;
- total += append_total;
- html = html.replaceAll('_-1_', '_' + total + '_');
- html = html.replaceAll('dever_up_', 'update_');
- var class_name = 'update_' + id;
- id = class_name + '_c_' + total;
- parent.append('<tr id="'+id+'" class="'+class_name+'">' + html + '</tr>');
- form.render();
- /*
- $('#' + id + " select").each(function()
- {
- if ($(this).attr('xm-select')) {
- layui.formSelects.render($(this).attr('xm-select'));
- }
- });
- */
- image();
- initDate();
- }
- function init_xm(xm_id, xm_radio, xm_tips, xm_url, xm_data, xm_value, xm_on)
- {
- if (!xm_on) {
- xm_on = function(){};
- }
- var xm_table = xm_id + '_table';
- var xm = xmSelect.render({
- el: "#" + xm_id,
- data: xm_data,
- tips:xm_tips,
- name:xm_id,
- initValue: xm_value,
- radio:xm_radio,
- clickClose: xm_radio,
- layVerify: "required",
- layVerType: "msg",
- autoRow: true,
- toolbar: { show: false },
- model: xm_radio ? { label: { type: 'text' } } : {},
- filterable: true,
- autoRow: true,
- height: 'auto',
- paging: xm_url ? true : false,
- pageRemote: xm_url ? true : false,
- remoteSearch: xm_url ? true : false,
- on: xm_on,
- //direction: 'down',
- remoteMethod: function(val, cb, show, pageIndex) {
- if (!pageIndex) {
- pageIndex = 1;
- }
- if(!val){
- //return cb([]);
- }
- if (!xm_url) {
- return cb(xm_data);
- }
- var data = {
- id: xm_table,
- keyword: val,
- pg: pageIndex
- };
- if (xm_url.indexOf('{') != -1) {
- var start = xm_url.split('{');
- var end = start[1].split('}');
- xm_url = start[0] + end[1];
- if (end[0].indexOf(',')) {
- var param = end[0].split(',');
- } else {
- var param = [];
- param[0] = end[0];
- }
- for (var i in param) {
- if (typeof(param[i]) == 'string') {
- var k = param[i];
- if (param[i].indexOf('=') != -1) {
- var t = param[i].split('=');
- param[i] = t[0];
- k = t[1];
- }
- var e = $('#update_'+param[i]);
- if (e.length > 1) {
- e.each(function() {
- if ($(this).get(0).checked) {
- data[k] = $(this).val();
- }
- })
- } else {
- var v = e.val();
- if (!v) {
- e = $('input[name="update_'+param[i]+'"]');
- if (e.val()) {
- v = e.val();
- }
- }
- data[k] = v;
- }
- if (!data[k]) {
- data[k] = -1;
- }
- }
- }
- }
- var success = function(response) {
- if (typeof response == "string") {
- response = JSON.parse(response);
- }
- if (response.status == 2) {
- cb([]);
- return;
- }
- if (!response.data.list) {
- if (response.page && response.page.total_page) {
- cb(response.data, response.page.total_page)
- } else {
- cb(response.data)
- }
- } else {
- if (response.page && response.page.total_page) {
- cb(response.data.list, response.page.total_page)
- } else {
- cb(response.data.list)
- }
- }
-
- /*
- if (response.data.table) {
- xm.update({
- content: response.data.table,
- });
- layui.table.init(xm_table, response.data.table_config).on('row('+xm_table+')', function(obj) {
- var values = xm.getValue();
- var item = obj.data;
- var has = values.find(function(i){
- return i.value === item.value
- });
- var send = {};
- send.arr = [ item ];
- if (has) {
- xm.delete(send.arr);
- } else if (xm_radio) {
- xm.setValue(send.arr);
- xm.closed();
- } else {
- xm.append(send.arr);
- }
-
- xm_on && xm_on(send)
- })
- }*/
- };
-
- $.ajax({
- dataType: "json",
- url: xm_url,
- data: data,
- timeout:0,
- success: success
- });
- },
- });
- }
|