123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- //【公共操作对象】
- var ActionObject= {
- /* AjaxSend-----Ajax发送*/
- "AjaxSend" :function(url,data,type='get'){
- var result;
- $.ajax({cache:true,type:type,url:url,data:data,async:false,dataType:"json",
- error : function(request) {alert("操作失败");},
- success : function(data) {result = data;}
- });
- return result;
- },
- /*常规事件------选项卡*/
- "Cevent" :function(e){
- $('[AT='+e.AT+']').on('click',function(){
- var obj = $('[Aobject='+e.AT+']['+e.CORID+'='+$(this).attr(e.CORID)+']');
- obj.siblings().hide();
- obj.show();
- $(this).addClass(e.CLASS).siblings().removeClass(e.CLASS);
- });
- $('[AT='+e.AT+']').eq(0).trigger('click');
- },
- /*列表删除事件*/
- "Delete":function(e){
- var self = this;
- $('[AT='+e.AT+']').on('click',function(){
- if(e.CORID) var ID = $(this).attr(e.CORID);
- layer.confirm('确认要删除吗?',function(index){
- if(ID != undefined){
- var result = self.AjaxSend(e.URL,{id:ID});
- if(result.code == 1) $('[AT='+e.AT+']['+e.CORID+'='+ID+']').parents(e.DLABEL).remove();
- }else{
- var Actiondata = $('input[Aobject='+e.AT+']');
- var data = '';
- for(var i=0;i<Actiondata.length;i++){
- if(Actiondata.eq(i).prop('checked') == true){
- data += Actiondata.eq(i).attr('data')+",";
- }
- }
- if(data.length != 0){
- data = data.substr(0,data.length - 1);
- var result = self.AjaxSend(e.URL,{data:data});
- if(result.code == 1){
- var arr = data.split(",");
- for(key in arr){
- $('input[Aobject='+e.AT+'][data='+arr[key]+']').parents(e.DLABEL).remove();
- }
- }
- }else{
- var result = {msg:'未选中节点',code:3};
- }
- }
- layer.msg(result.msg,{icon:result.code,time:2000});
- });
- });
- },
- // 全选事件
- "CheckAll":function(e){
- e.box.on('click',function(){
- var ID = $(this).attr(e.boxID);
- if($(this).prop('checked') == true){
- $('input['+e.sonID+'='+ID+']').prop('checked',true);
- }else{
- $('input['+e.sonID+'='+ID+']').prop('checked',false);
- }
- });
- },
- //表单阻止 (单个节点)
- "FormCode":function(e){
- e.FORM.submit(function(){
- var Code = $(this).find('input[name='+e.INPUT+']').val();
- if($.trim(Code).length == 0){
- layer.msg('输入不能为空',{icon:2,time:2000});
- return false;
- }
- });
- },
- // 设置状态
- "Upsate":function(e){
- var self = this;
- $('[AT='+e.AT+']').on('click',function(){
- var ID = $(this).attr(e.CORID);
- var state = $(this).find('.move');
- var result = self.AjaxSend(e.URL,{id:ID,state:state.attr('data-state')});
- if(result.state == "on"){
- state.animate({
- left: "21"
- }, 300, function() {
- state.attr("data-state",result.state);
- });
- state.parent().removeClass("off").addClass(result.state);
- }else if(result.state == "off"){
- state.animate({
- left: "0"
- }, 300, function() {
- state.attr("data-state",result.state);
- });
- state.parent().removeClass("on").addClass(result.state);
- }
- });
- },
- //本地单图预览
- "Preview_one_Local":function(e){
- var path;
- var data = e.imgFile;
- if(data.files[0]){
- e.preview.css('display','block');
- }else{
- e.preview.css('display','none');
- }
- path = window.URL.createObjectURL(data.files[0]);
- e.preview.attr('src',path);
- e.preview.parent().prev('input[path=filepath]').val(path);
- $('.close').show();
- },
- //本地多图预览
- "Preview_more_Local":function(e){
- var path;
- var data = e.imgFile;
- $('.atlas_start_up').hide();
- $('.atlas_more_action').show();
- e.preview.parent().show();
- for(var i=0;i<data.files.length;i++){
- path=window.URL.createObjectURL(data.files[i]);
- e.preview.append("<li id='imgdel"+e.preview.children().length+"'><span class='moreclose' data='atlas' onclick='PreviewImageDel("+e.preview.children().length+")'></span><img src='"+path+"'/><input type='text' name='alt[]' placeholder='图片标题'></li>");
- }
- },
- //单图片远程预览
- "PreviewRemote":function(e){
- e.imgFile.on('keyup',function(){
- e.preview.attr('src',this.value);
- $('.close').show();
- });
- },
- // 删除图集节点
- "Delatlasnode":function(id,key,action){
- var self = this;
- layer.confirm('确认要删除吗?',function(index){
- var reuslt = self.AjaxSend(action,{id:id,key:key});
- PreviewImageDel(key);
- layer.msg(reuslt,{icon:2,time:2000});
- });
- },
- // 修改 alt图集--------------------------------------------------------------------
- "Amendlasnode":function(e){
- var _index,txt,content,box,
- _Class = $(e.AT),
- _this = this;
- var TxtNumber;
- _Class.on('focus','input[type="text"]', function(){
- _index =$(this).parent().index()+1;
- txt = $(this).val();
- _this.FoundDiv({COUNT:_index,DATA:txt});
- TxtNumber=getStrLength(txt)
- $('#shot_text_box').find('i').html(TxtNumber);
- });
- },
- // 创建一个div盒子,插body中
- "FoundDiv":function(e){
- var ShotBox,
- _div ='',
- _self=this,
- Chooser = $('.atlas_preview ul li');
- _div +='<div id="shot_text_box"><span class="moreclose"></span>';
- _div +='<p class="txt_title" id="txt_title">第<span>'+e.COUNT+'</span>张缩略图</p>';
- _div +='<div class="textbox"><textarea rows="5" cols="20" autofocus="autofocus">'+e.DATA+'</textarea>';
- _div +='<span><i>0</i>/<em>30</em></span></div>'
- _div +='<p class="btn_box mt-5"><a class="btn" href="javascript:;">确定</a></p></div>'
- // 判断不存在才插入
- ShotBox = $('#shot_text_box').text();
- if(!ShotBox){
- $('body').append(_div);
- }else{
- $('#txt_title span').html(e.COUNT);
- $('.textbox textarea').val(e.DATA);
- }
- //获取当前坐标
- var CoordinateX = Chooser.eq(e.COUNT-1).find('input[type="text"]').offset().left;
- var CoordinateY = Chooser.eq(e.COUNT-1).find('input[type="text"]').offset().top;
- $('#shot_text_box').css({'top':CoordinateY,'left':CoordinateX});
- $('#shot_text_box .moreclose').on('click',function(){
- $(this).parent().remove();
- })
- $('#shot_text_box a.btn').on('click',function(){
- var i = $(this).parent().siblings('#txt_title').children().html()-1,
- NewContent = $(this).parent().siblings('.textbox').children().val();
- Chooser.eq(i).find('input[type="text"]').val(NewContent);
- var InitialData =e.DATA;
- var oURL=Chooser.eq(i).find('input[type="text"]').attr('url');
- var Aid=Chooser.eq(i).find('input[type="text"]').attr('aid');
- var Key=Chooser.eq(i).find('input[type="text"]').attr('key');
- if(oURL != undefined){
- if(NewContent != InitialData){
- var result = _self.AjaxSend(oURL,{id:Aid,key:Key,alt:NewContent});
- if(result == true){
- Chooser.eq(i).find('input[aid="'+Aid+'"][key="'+Key+'"]').val(NewContent);
- }else{
- layer.msg('修改失败!',{time:2000});
- }
- }
- }
- $(this).parents('#shot_text_box').remove();
- })
- // 添加两个输入框同时响应
- $('.textbox').on('keyup','textarea',function(){
- var txt = $(this).val();
- var i = $(this).parent().siblings('#txt_title').children().html()-1;
- var TxtNumber= getStrLength(txt);
- if(TxtNumber>30){
- txt = txt.substr(0,30);
- $(this).val(txt);
- }else{
- $(this).siblings('span').find('i').html(TxtNumber);
- }
- })
- },
- //多选框限制选中数量
- "Checkbox":function(id,Num,Num2){
- var wuye=$(id).find(":checkbox");
- if(wuye.size()>=Num){
- wuye.removeAttr("checked");
- wuye.attr("disabled","disabled");
- wuye.removeAttr("disabled");
- }
- var num = 0;
- wuye.each(function(){
- $(this).click(function(){
- if($(this)[0].checked) {
- ++num;
- if(num == Num) {
- //alert("最多选择 的上限已满, 其他选项将会变为不可选.");
- wuye.each(function(){
- if(!$(this)[0].checked) {
- $(this).attr("disabled", "disabled");
- }
- });
- }
- } else {
- --num;
- if(num <= Num2) {
- wuye.each(function(){
- if(!$(this)[0].checked) {
- $(this).removeAttr("disabled");
- }
- });
- }
- }
- });
- });
- }
- };
- // ActionObject END
- /*------------------------------------------------------------------------------------------------------------------------*/
- // 中文字符半角、全角判断
- function getStrLength(str) {
- var len = str.length;
- var reLen = 0;
- for (var i = 0; i < len; i++) {
- if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
- reLen += 1;
- } else {
- reLen++;
- }
- }
- return reLen;
- }
- //删除预览图
- function PreviewImageDel(e){
- if(typeof(e) == 'object'){
- $("."+e.className).parent().children('img').attr('src',"");
- $('input[name='+$("."+e.className).attr('data')+']').val("");
- $("."+e.className).parent().append("<input type='hidden' name='del[]' value=0 />");
- $(".close").hide();
- $(".mt-15 .input-text").attr("value","");
- }else if(typeof(e) == 'number'){
- var obj = $('#imgdel'+e);
- obj.parent().append("<input type='hidden' name='moredel[]' value="+e+" />");
- if(obj.siblings('li').length == 0){
- obj.parent().parent().hide()
- $('.atlas_start_up').show();
- $('.atlas_more_action').hide();
- }
- obj.remove();
- }
- }
- // 时间范围验证不为空。
- $('.Wdate').parent('form').submit(function(){
- var ctime = $(this).find('input[name=ctime]');
- var etime = $(this).find('input[name=etime]');
- if(ctime.val() && !etime.val()){
- layer.msg('请输入'+etime.attr('placeholder')+'时间',{icon:2,time:2000});
- return false;
- }
- if(etime.val() && !ctime.val()){
- layer.msg('请输入'+ctime.attr('placeholder')+'时间',{icon:2,time:2000});
- return false;
- }
- })
|