12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477 |
- //这里的代码是最早写的,很乱,以后整合优化
- var editors = [];
- var editors_index = [];
- var tables = [];
- var select = '';
- var submitButton = '';
- var editorWidth = 0;
- 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);
- }
- };
- $(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();
- //更新页面一些功能,上边的一些功能等找时间再优化吧
- dever_update.init();
- hljs.initHighlightingOnLoad();
- table();
- }
- 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');
- $.get(url, {}, function(t)
- {
- var func = function() {
- var url = $('#editor_applet_pic').val();
- var appid = $('#editor_applet_id').val();
- var path = $('#editor_applet_path').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+'"/>');
- 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')
- });
- });
- });
- });
- }
- 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_time").length)
- {
- $(".manage_time").each(function()
- {
- $(this).datetimepicker(
- {
- //inline:true,
- timepicker:false,
- format:'Y-m-d',
- lang:'ch'
- });
- });
- }
-
- if($(".manage_date").length)
- {
- $(".manage_date").each(function()
- {
- $(this).datetimepicker(
- {
- //datepicker:false,
- format:'Y-m-d H:i:s',
- lang:'ch'
- });
- });
- }
- }
- 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 yun = {};
- if (token && host) {
- yun.token = token;
- yun.host = host;
- yun.domain = domain;
- yun.path = path;
- }
- if (!media) {
- media = key;
- }
- var view = config.upload.replace('save', 'view');
- var param = {
- height : "400px",
- allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
- allowImageRemote : true, //上传图片框网络图片的功能,false为隐藏,默认为true
- allowFileManager : true, //浏览图片空间
- allowMediaUpload : true,
- filterMode : true, //HTML特殊代码过滤
- themeType : 'default',
- filePostName : 'file',
- dialogOffset : 0, //对话框距离页面顶部的位置,默认为0居中,
- uploadJson : config.upload + '.kindeditor?key=' + key,
- uploadMediaJson : config.upload + '.kindeditor?key=' + media,
- uploadYunJson : yun,
- fileManagerJson : view + '.files?key=' + media,
- htmlTags : {
- 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'
- ]
- /*
- 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 loadShow()
- {
- if($(".show_input").length)
- {
- $(".show_input input").each(function()
- {
- if($(this).attr('checked'))
- {
- inputShow($(this), $(this).attr('show_id'), 'input');
- }
- })
- $(".show_input select").each(function()
- {
- if($(this).find('option:selected').text())
- {
- inputShow($(this), $(this).attr('show_id'));
- }
- })
- }
- }
- function inputShow(e,n,t)
- {
- $(".show_" + n).hide();
-
- var array = ['input', 'textarea'];
- for(var a in array)
- {
- if ($(".show_" + n).find(array[a]).length) {
- var c = $(".show_" + n).find(array[a]).attr('class');
- if (c.indexOf('validate[required]') > -1) {
- $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
- }
- }
- }
-
- 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);
- }
- });
- }
- }
- 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') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
- {
- $(this).addClass('validate[required]');
- }
- })
- }
- }
- }
- //批量更新
- function list_mul(e)
- {
- var type = parseInt($("#mul_type").val());
- if(type != 1 && type != 2)
- {
- alert('您还没有选择数据更新方式');
- return;
- }
- var index = layer.confirm('确定进行此项操作吗?', function()
- {
- $('#method').val('mul');
- $('#function').val('msg');
- layer.close(index);
- $('#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)
- {
- var call = function()
- {
- var col = e.attr('name').replace('up_col_', '');
- var value = e.val();
- var old = e.attr('data-old');
- var url = config.host + 'database.update_action?json=1';
- $.post(url, {where_id:id,col:col,value:value,project:project,table:table}, 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()
- {
- 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':'1px solid #ccc'});
- e.children().css({'border':'1px solid black'});
- if(name == 'update_template')
- {
- $('body').attr('class', 'theme-' + value);
- }
- }
- //根据e的值,来载入其他数据
- function loading(e, data)
- {
- 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, data, function(t)
- {
- $('#update_'+data.element+'_value').val(t.data);
- });
- }
- else
- {
- $('#update_'+data.element+'_value').val(value);
- }
- }
- else if(data.url)
- {
- data.value = value;
- data.where_id = $('#update_where_id').val();
- data.table = $('#table').val();
- data.project = $('#project').val();
- $.getJSON(data.url, data, function(s)
- {
- t = s.data;
- if(t.indexOf('onblur') != -1)
- {
- eval(t);
- }
- else
- {
- var parent = e.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();
- }
- }
- });
- }
- }
- //根据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();
- }
- });
- }
- $.getJSON(data.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', 'new-password');
- });
- }
- 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 + '_value').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)
- {
- e.parent().parent().remove();
- autocomplete_value[id].remove(value);
- var len = autocomplete_value.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)
- {
- 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.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)
- {
- 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');
- }
- })
- });
- 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();
-
- if($(this).get(0).checked == true)
- {
- 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 (!$('#' + 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.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").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()
- {
- $.getJSON(href + '&json=1&callback=?', {}, function(t)
- {
- msg(t);
- layer.close(index);
- })
- });
- }
- /**
- * 处理特殊加载的按钮
- */
- function load(href)
- {
- var index = layer.confirm('确定进行此项操作吗?', function()
- {
- if(href.indexOf('&') == -1)
- {
- href += '?json=1&callback=?';
- }
- else
- {
- href += '&json=1&callback=?';
- }
- $.getJSON(href, {}, function(t)
- {
- msg(t);
- layer.close(index);
- //location.reload();
- })
- })
- /*
- showAlert('确定进行此项操作吗?', function()
- {
- $("#dever_modal_no").click();
- $.getJSON(href + '&json=1', {}, function(t)
- {
- msg(t);
- })
- });
- */
- }
- /**
- * 处理特殊加载的按钮
- */
- function jump(href, form)
- {
- if (form) {
- var param = formData(form);
- href += param[1];
- }
- 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_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',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();
- }
- function showAlert(msg, func, title, index)
- {
- if (!title) {
- title = '提醒您';
- }
- var type = 0;
- if (msg.indexOf('<') != -1) {
- type = 1;
- }
- var config = {
- type: 0,
- title: title,
- shade: 0.1,
- shadeClose : true,
- content: msg
- };
- config.scrollbar = false;
- if (type == 1) {
- if (index) {
- config.zIndex = index;
- config.type = 1;
- config.btn = ['确定'];
- }
- config.area = '800px';
- //config.type = 1;
-
- }
- if (func) {
- config.yes = function(index)
- {
- func(index);
- };
- } else {
- config.yes = function(index)
- {
- layer.close(index);
- };
- }
- var index = layer.open(config);
- }
- function fastEdit(e, url, title, col, index)
- {
- var func = function()
- {
- submit_action();
- };
- var send = {};
- send.col = col;
- $.get(url,send,function(t)
- {
- var html = '';
- var valid = '';
- if ($(t).find('form').length && $(t).find('#valid').length) {
- var html = $(t).find('form').prop("outerHTML");
- var valid = $(t).find('#valid').prop("outerHTML");
- html = html + valid;
- if (html.indexOf('left: 740px') != -1) {
- html = html.replace('left: 740px', 'left:583px;')
- }
- } else {
- html = t;
- func = false;
- }
- if (index == 1) {
- showAlert(html, func, title, 19850422);
- } else {
- showAlert(html, func, title);
- }
-
- $('.layui-layer-content').css('overflow-x', 'hidden');
- $('#update_button').hide();
- layui.use(['formSelects'], function(){
- $("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 select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
- {
- var e = '#' + id;
- var parent = value.split(',');
- var cur = parent[0];
- parent.remove(cur);
- value = parent.join(',');
- var html = '';
- var old = level;
- if (!total) {
- level_id = 0;
- } else {
- if (level >= total) {
- //$(e).show();
- return;
- }
- level_id = $(e + '_' + level).val();
- level = parseInt(level) + 1;
- }
- $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
- var check = '';
- if (t.status == 1) {
- var total = t.data.level_total;
- var data = t.data.list;
- if(!$(e + '_' + level).length) {
- html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\');">';
- }
- for (a in data) {
- if (data[a].value) {
- check = '';
- if (cur == data[a].value) {
- check = ' selected';
- }
- html += '<option value="'+data[a].value+'" '+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();
- }
- } else {
- $(e + '_' + old).nextAll('select').remove();
- $(e + '_' + 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());
- }
- */
- });
- }
- /*
- 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()
- {
- 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 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] = $(child).length;
- }
-
- if(self.index[key] > 30)
- {
- layer.showAlert('最多只能增加30条');
-
- return;
- }
-
- var p = e.parent();
-
- var id = key + '-child-' + self.index[key];
-
- var name = '第' + (self.index[key]) + '条';
-
- p.before('<li><a href="javascript:;" id="tab-'+id+'" toggle_key="'+key+'" toggle_id="'+self.index[key]+'" toggle_child="'+child+'" toggle="#'+id+'" onclick="showToggle($(this))">'+name+'</a></li>');
-
-
- 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_');
-
- content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + 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_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').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();
- },
- 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();
-
|