12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- $(".layui-side .layui-nav-item").not('.layui-nav-itemspec').mouseenter(function() {
- if($(".layui-side-menu").hasClass('layui-sideact')) {
- $(this).addClass('layui-nav-itemact')
- }
- })
- $(".layui-side .layui-nav-item").not('.layui-nav-itemspec').mouseleave(function() {
- if($(".layui-side-menu").hasClass('layui-sideact')) {
- $(".layui-sideact .layui-nav-item").not('.layui-nav-itemspec').removeClass('layui-nav-itemact')
- }
- })
- $(".layui-nav-itemspec").find('.layui-icon').on("click",function() {
- if($(".layui-side-menu").hasClass('layui-sideact')) {
- $(".layui-side-menu").removeClass('layui-sideact')
- $(".layui-body").removeClass('layui-bodyact')
- }else{
- $(".layui-side-menu").addClass('layui-sideact')
- $(".layui-body").addClass('layui-bodyact')
- }
- })
- // 时间标准格式的转换
- function isZero(m){
- return m<10?'0'+m:m
- }
- function formatDate(timestamp) {
- var time = new Date(timestamp);
- var y = time.getFullYear();
- var m = time.getMonth()+1;
- var d = time.getDate();
- var h = time.getHours();
- var mm = time.getMinutes();
- var s = time.getSeconds();
- return y+'-'+isZero(m)+'-'+isZero(d)+' '+isZero(h)+':'+isZero(mm)+':'+isZero(s);
- }
- //只能输入两位并且保留两位小数
- function clearNoNum(obj){
- obj.value = obj.value.replace(/[^\d.]/g,""); //清除“数字”和“.”以外的字符
- obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
- obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
- obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
- if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
- obj.value= parseFloat(obj.value);
- }
- }
- // 获取地址栏的参数
- function getUrlParam(name){
- var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
- var r = window.location.search.substr(1).match(reg);
- if (r!=null) return unescape(r[2]); return null;
- }
- /**
- * 图片压缩,默认同比例压缩
- * @param {Object} path
- * pc端传入的路径可以为相对路径,但是在移动端上必须传入的路径是照相图片储存的绝对路径
- * @param {Object} obj
- * obj 对象 有 width, height, quality(0-1)
- * @param {Object} callback
- * 回调函数有一个参数,base64的字符串数据
- */
- function dealImage(path, obj, callback) {
- var img = new Image();
- img.src = path;
- img.onload = function () {
- var that = this;
- // 默认按比例压缩
- var w = that.width,
- h = that.height,
- scale = w / h;
- w = obj.width || w;
- h = obj.height || (w / scale);
- var quality = 0.7; // 默认图片质量为0.7
- //生成canvas
- var canvas = document.createElement('canvas');
- var ctx = canvas.getContext('2d');
- // 创建属性节点
- var anw = document.createAttribute("width");
- anw.nodeValue = w;
- var anh = document.createAttribute("height");
- anh.nodeValue = h;
- canvas.setAttributeNode(anw);
- canvas.setAttributeNode(anh);
- ctx.drawImage(that, 0, 0, w, h);
- // 图像质量
- if (obj.quality && obj.quality <= 1 && obj.quality > 0) {
- quality = obj.quality;
- }
- // quality值越小,所绘制出的图像越模糊
- var base64 = canvas.toDataURL('image/jpeg', quality);
- // 回调函数返回base64的值
- callback(base64);
- }
- }
|