分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

自用公共js文件

发布时间:2023-09-06 01:12责任编辑:赖小花关键词:js

// 加载配置文件
var instance = axios.create({
baseURL: ‘http://zy-shop.tincent.me/Wechat/‘,
???headers: {
???????‘Content-Type‘: ‘application/x-www-form-urlencoded‘
???}
??// withCredentials:true
});
//公共函数
function Public(){
  this.get=function(){
    console.log(1)
  },
  this.post=function(){
    console.log(2)
  },
  //顶部提示的弹框方法
  this.remind=function(that,remind){
    that.remindShow=true;
    that.remind=remind;
    setTimeout(function(){
      that.remindShow=false
    },1000)
  },
  //60秒倒计时、
  this.countdown=function(that){
    var time=60;
    that.downTime=time+"秒后获取";
    var timer=setInterval(function(){
      time--;
      //当时间降低成0时
      if(time==0){
        that.downTime="再次获取";
        clearInterval(timer);
      }else{
        that.downTime=time+"秒后获取";
      }
     },1000)
   }
    //前后台数据传递解析
  this.json2Form=function(json) {
???    var str = "";
???    for(var p in json){
?????    // 判断对象是否为数组
?????      if(typeof json[p]=="object"){
???????        var m=String(p)
?????????        for(var i=0;i<json[p].length;i++){
???????????          for(var x in json[p][i]){
???????????????            str+=m+"["+i+"]"+"["+x+"]"+ "=" +json[p][i][x]+"&";
???????????          }
?????????        }
?????      }else{
???????        str+=p + "=" + json[p]+"&";
?????      }
???    }  
???    // 截取字符串最后一位&
???    var length=str.length-1;
???    str=str.substring(0,length);
???    // 返回字符串str
???    return str; ???
?  },
?  //提交表单时的加锁处理
?  this.getCsrfToken=function(){
?    instance.get(‘Service/getCsrfToken‘).then(function(res){
?      sessionStorage.setItem(‘submitKey‘,JSON.stringify({‘submitKey‘:res.data.data.submitKey}))
?    })
?  },
?  //session存储
?  this.saveSession=function(key,data){
???    sessionStorage.setItem(key,JSON.stringify(data));
?  },
?  //session提取
?  this.getSession=function(key,str){
?    //判断取值方式
??????    var user = JSON.parse(sessionStorage.getItem(key));
???????  if(user){
???????????    if(str){
???????????????      return user[str];
???????????    }
???????????    return user;
???????    }
???????????
?  },
?  //session清楚
?  this.removeSession=function(key){
?    sessionStorage.removeItem(key)
?  }
?  //local存储
?  this.saveLocal=function(key,data){
???    localStorage.setItem(key,JSON.stringify(data));
?  },
?  //local提取
?  this.getLocal=function(key,str){
?    //判断取值方式
???????    var user = JSON.parse(localStorage.getItem(key));
???????      if(user){
???????????        if(str){
???????????????          return user[str];
???????????        }
???????????      return user;
???????    }
?  },
?  //清除local
?  this.removeLocal=function(key){
?    localStorage.removeItem(key)
?  },
?  //获取URL传递的参数
?  this.getUrlParam=function(name){
?    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
???    var r = window.location.search.substr(1).match(reg);
???    if(r!=null)return ?unescape(r[2]); return null;
?  },
?  //页面lodding函数
?  this.loadding=function(type){
?    //判断是否是启动loadding
?    if (type==‘load‘) {
?      toast.loading({
??        title:"加载中",
??        duration:2000
        },function(ret){
      });
?    } else if(type=‘hide‘){
?  setTimeout(function(){
    toast.hide();
   },500)
?  }
?  },
?  //定义加载中时的文字显示
?  this.pageWord=function(that,pageflag,title){
?    if (pageflag==1) {
?      that.pageWord=title;
?    }else{
?    that.pageWord="暂无更多"
?    }
?   }
}
var toast = new auiToast();
var public=new Public();

自用公共js文件

原文地址:http://www.cnblogs.com/bluesky1024/p/7567467.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved