日常记录

DES加密和MD5加密

先引入des.js
<script src="mayDay/js/des.js"></script>
//获取10位时间戳
        var timestamp = Date.parse(new Date()) / 1000;
        //获取16位随机字符串
        function randomString(length, chars) {
            var result = '';
            for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
            return result;
        }
        var rString = randomString(16, 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678');//****默认去掉了容易混淆的字符
        //获取随机uuid
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }
        function guid() {
            return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
        }
        var uuid = guid();
        var newrandom = 'deviceIdentifier=' + uuid + '&nonceStr=' + rString + '&platform=PC' + '&timestamp=' + timestamp + '&userCode=' + this.query + '&userPhonenum=' + this.inputPhone + '&verificationCode=' + this.something1 + this.something2 + this.something3 + this.something4;
        // console.log(newrandom);
        var newarr = newrandom.split("&");
        var s1 = Array.prototype.sort.call(newarr, function (a, b) {
            for (var i = 0; i < a.length; i++) {
                if (a.charCodeAt(i) == b.charCodeAt(i)) continue;
                return a.charCodeAt(i) - b.charCodeAt(i);
            }
        });
        var newnewrandom = s1.join("&") + "&key=x41IIYwgdltKspjcMEznjy2ymHj7YTXk";
        // console.log(newnewrandom,hex_md5(newnewrandom).toUpperCase());
        var Data = {
            nonceStr: rString,
            timestamp: timestamp,
            platform: 'PC',
            userPhonenum: this.inputPhone,
            verificationCode: this.something1 + this.something2 + this.something3 + this.something4,
            deviceIdentifier: uuid,
            userCode: this.query,
            sign: hex_md5(newnewrandom).toUpperCase(),
        }
        // des加密
        var key = "zeoBA6F8D6HIjRkf47G3cpdmeSVXfj8P";
        var iv = "01234567";
        function encryptByDES(message) {
            var keyHex = CryptoJS.enc.Utf8.parse(key);
            var encrypted = CryptoJS.TripleDES.encrypt(message, keyHex, {
                iv: CryptoJS.enc.Utf8.parse(iv),
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            });
            return encrypted.toString();
        };
        //
        var newsign = JSON.stringify(Data);
        var postData = { h7: encryptByDES(newsign) }
        axios({
            url: '你的请求路径',
            method: 'post',
            data: postData,
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
        }).then(res => {
            console.log(res, res.data.status);
            if (res.data.status == 200) {
                //请求成功
            }
        });

Vue中layui日期时间框附带时间大小判断

<div class="layui-inline">
     <input type="text" class="layui-input" id="strDate" />
</div>
<div class="layui-inline">
     <input type="text" class="layui-input" id="endDate" />
</div>
mounted(){
	timeInterval("#strDate", "#endDate");
    //提示弹窗
    function promptPopup(txt) {
      layui.use("layer", function() {
        var layer = layui.layer;
        layer.msg(txt);
      });
    }
    //处理时间格式
    Date.prototype.toLocaleString = function() {
      var moth = this.getMonth() + 1;
      var data = this.getDate();
      if (moth < 10) {
        moth = "0" + moth;
      }
      if (data < 10) {
        data = "0" + data;
      }
      return this.getFullYear() + "-" + moth + "-" + data;
    };
    //处理选择日期
    function doneTime(date) {
      console.log(date.month);
      return {
        year: date.year,
        month: date.month - 1,
        date: date.date
      };
    }
    //处理当天日期
    function nowTime(date) {
      return {
        year: date.getFullYear(),
        month: date.getMonth(),
        date: date.getDate()
      };
    }
    //输入框时间处理
    function iptTime(date) {
      return {
        year: date.substring(0, 4) - 0,
        month: date.substring(5, 7) - 1,
        date: date.substring(8, 10) - 0
      };
    }
    function timeInterval(strDateId, endDateId) {
      layui.use("laydate", function() {
        //开始时间
        var strDate = layui.laydate;
        var start = strDate.render({
          elem: strDateId, //指定元素
          btns: ["now", "confirm"],
          max: "new Date()",
          value: new Date(),
          ready: function() {
            end.config.min = iptTime("1990-01-01");
            start.config.max = nowTime(new Date());
          },
          done: function(value, date) {
            end.config.min = doneTime(date);
            //判断时间大小
            var startDate = new Date(value).getTime();
            var endTime = new Date($(endDateId).val()).getTime();
            // console.log(strDate, 11);
            if (endTime < startDate) {
              promptPopup("开始时间不能大于结束时间");
              start.config.max = nowTime(new Date());
              end.config.min = nowTime(new Date());
              $(strDateId).val(new Date().toLocaleString());
              $(endDateId).val(new Date().toLocaleString());
            }
          }
        });
        //结束时间
        var endDate = layui.laydate;
        var end = endDate.render({
          elem: endDateId, //指定元素
          btns: ["now", "confirm"],
          value: new Date(),
          max: "new Date()",
          ready: function() {
            end.config.min = iptTime("1990-01-01");
            start.config.max = nowTime(new Date());
          },
          done: function(value, date) {
            start.config.max = doneTime(date);
            //判断时间大小
            var startDate = new Date($(strDateId).val()).getTime();
            var endTime = new Date($(endDateId).val()).getTime();
            // console.log(endTime, 12);
            var nowDate = new Date().getTime();
            if (endTime < startDate) {
              promptPopup("结束时间不能小于开始时间");
              $(strDateId).val(new Date().toLocaleString());
              $(endDateId).val(new Date().toLocaleString());
              start.config.max = nowTime(new Date());
              end.config.min = nowTime(new Date());
            }
            if (endTime > nowDate) {
              promptPopup("时间最大值不能大于当天的值");
              $(strDateId).val(new Date().toLocaleString());
              $(endDateId).val(new Date().toLocaleString());
            }
          }
        });
      });
    }
}
//时间清空
$("#strDate").val(new Date().toLocaleString());
$("#endDate").val(new Date().toLocaleString());

vue通过七牛云上传图片并获取到图片路径

<input @change="uploadInputchange"  id="uploadFileInput" type="file" accept="image/jpeg, image/png, image/gif">
import axios from 'axios';

methods: {
    //触发input change事件
    uploadInputchange(){
        let file = document.getElementById("uploadFileInput").files[0];   //选择的图片文件
        this.uploadImgToQiniu(file);
    },
    //上传图片到七牛
    uploadImgToQiniu(file){
        const axiosInstance = axios.create({withCredentials: false});    //withCredentials 禁止携带cookie,带cookie在七牛上有可能出现跨域问题
        let data = new FormData();
        data.append('token', 得到的token);     //七牛需要的token,叫后台给,是七牛账号密码等组成的hash
        data.append('file', file);
        axiosInstance({
            method: 'POST',
            url: 'http://upload.qiniup.com/',  //上传地址,这个有可能变动
            data: data,
            timeout:30000,      //超时时间,因为图片上传有可能需要很久
            onUploadProgress: (progressEvent)=> {
                //imgLoadPercent 是上传进度,可以用来添加进度条
                let imgLoadPercent = Math.round(progressEvent.loaded * 100 / progressEvent.total);
            },
        }).then(data =>{
            document.getElementById("uploadFileInput").value = ''        //上传成功,把input的value设置为空,不然 无法两次选择同一张图片
            //上传成功...  (登录七牛账号,找到七牛给你的 URL地址) 和 data里面的key 拼接成图片下载地址
        }).catch(function(err) {
            //上传失败
        });
    }
},
添加多张图片
<input type="file" name="file" multiple accept="image/png,image/gif,image/jpeg" @change="inputFile">
				inputFile(e) {
					if (e.target.files.length > 9) {
						alert('最多只能选择九张图片')
					} else {
						for (let index = 0; index < e.target.files.length; index++) {
							const axiosInstance = axios.create({ withCredentials: false });    //withCredentials 禁止携带cookie,带cookie在七牛上有可能出现跨域问题
							const file = e.target.files[index];
							// console.log(e.target.files,file)
							let data = new FormData();
							data.append('token', 得到的token);     //七牛需要的token,叫后台给,是七牛账号密码等组成的hash
							data.append('file', file);
							axiosInstance({
								method: 'POST',
								url: 'http://up-z1.qiniup.com/',  //上传地址,这个有可能变动
								data: data,
								timeout: 30000,      //超时时间,因为图片上传有可能需要很久
								onUploadProgress: (progressEvent) => {
									//imgLoadPercent 是上传进度,可以用来添加进度条
									let imgLoadPercent = Math.round(progressEvent.loaded * 100 / progressEvent.total);
								},
							}).then(data => {
								// console.log(data)
								//上传成功...  (登录七牛账号,找到七牛给你的 URL地址) 和 data里面的key 拼接成图片下载地址
							}).catch(function (err) {
								// console.log(err)
								alert(err)
								//上传失败
							});
						}
					}
				},

杂记

## 正则判断手机号
if (!(/^1[3456789]\d{9}$/.test(要判断的手机号))) {
	alert("手机号码有误,请重填");
}else{
	//手机号正确
}
##单行文本过长显示...需要给出width:xxpx;
text{

overflow:hidden; //超出一行文字自动隐藏

text-overflow:ellipsis;//文字隐藏后添加省略号

white-space:nowrap; //强制不换行

}
或者多行的用这些:
 display: -webkit-box;
    word-break: break-all;
    text-overflow: ellipsis;
    font-size: 32rpx;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp:2;
————————————————

Overflow:scoll; 失效试试不给高
-webkit-border-radius:6px;//适配以webkit为核心的浏览器(chrome、safari等)
     -moz-border-radius:6px;//适配firefox浏览器
     -ms-border-radius:6px;//适配IE浏览器
     -o-border-radius:6px;//适配opera浏览器
     border-radius:6px;//适配所有浏览器(需要放在最后面,类似于if..else if..else..)
input输入框设置圆角后,出现阴影只需重新设置一下边框属性
input 字体缩进 text-indent:xxpx

取出数组里的数据
下标或者直接arr.['里边的字段']

选择倒数第二个标签元 素名:nth-last-child(2)
选择最后一个标签 元素名:last-child
选择器 :not(:last-child) 选择除了最后一个元素以外的
:冒号前后不能有空格
vue中v-if是销毁元素, 可以起到刷新的作用,
##给一个数组的值添加一个对象key值
var arr = [1,2,3,]
var arr1 = []
for (let i = 0; i < arr.length; i++) {
	var obj = {};
	obj.classifyId = arr[i]
	arr1.push(obj)
}
console.log(arr1)//[{classifyId:1},{classifyId:2},{classifyId:3}]
##获取当前网页的url以及url后面的参数
    var url = document.location.toString();//获取url地址
    var urlParmStr = url.slice(url.indexOf('?')+1);//获取问号后所有的字符串
    var arr = urlParmStr.split('&');//通过&符号将字符串分割转成数组
    var courseId = arr[0].split("=")[1];//获取数组中第一个参数
    var unit_title=arr[1].split("=")[1];//第二个参数
    unit_title=decodeURI(unit_title);//转码将解码方式unscape换为decodeURI,将中文参数获取
    console.log(unit_title);

vue写的项目可以在其他电脑上测试:修改config->index.js 找到host:'localhost’改成host:‘0.0.0.0’

this.$forceUpdate()  强制刷新
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值