分类 代码 下的文章

webpack 热加载

npm install webpack-dev-server -g
npm install webpack-dev-server --save-dev

设置 npm 全局路径

在nodejs安装目录下增加node_global和node_cache文件夹。

npm config set cache "D:\nodejs\node_global"
npm config set prefix "D:\nodejs\node_cache"

MUI - 动态生成多个picker

html

<div class="form-picker-container"
 id="a"
 data-layer="1"
 data-setData='[{"value":"加重","text":"加重"},{"value":"减轻","text":"减轻"},{"value":"无变化","text":"无变化"}]'>
 <span>请选择</span>
</div>

阅读全文

git - 分支

git branch
git status
git checkout -b re-v1.0.1
git branch
git push origin re-v1.0.1:re-v1.0.1
git push origin --delete re-v1.0.1

git常用命令

gitea

博客服务器快到期了,续费了几年,忽然发现阿里云在搞活动。(这不是个广告)
1年1核1G的ecs只要293,果断买了一台。
既然又闲置了一台服务器,那么用它来干吗呢。
可以自己搭建VPN,但是服务器是阿里云的,GG
可以搞个挖矿机,但是&%¥#,GG
可以挂点广告,有点浪费,GG
可以搞个色情网站,但是
&%¥#,GG
可以再搞个博客网站,累了,不折腾了,GG
要不搞个代码托管工具吧,OK,开搞。

阅读全文

JS - 解决图片压缩 + IOS下拍照图片翻转问题

核心代码

var file = document.getElementById('#file');
//获取的图片文件
var fileList = file.files;
/**************************************************************************************************/
// 压缩图片需要的一些元素和对象
var reader = new FileReader();
var img = new Image();
// 缩放图片需要的canvas
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
//图片大小
var fileSize = fileList[0].size;
reader.readAsDataURL(fileList[0]);
reader.onload = function(e) {
    //e.target.result就是图片的base64地址信息
    img.src = e.target.result;
};
img.onload = function(e) {
    EXIF.getData(img, function() {
        var Orientation = EXIF.getTag(this, 'Orientation');
        console.log('方向:' + Orientation);
        console.log('大小:' + fileSize/(1024*1024));
        var wph = (img.height*1)/(img.width*1);
        var hpw = wph.toFixed(2)*1;
        var square = 700;   //定义画布的大小,也就是图片压缩之后的像素
        var imageWidth = 0;    //压缩图片的大小
        var imageHeight = 0;
        var offsetX = 0;
        var offsetY = 0;
        var hsquare = Math.ceil(square*hpw);
        var u = navigator.userAgent;
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
        if(isiOS){
            if(Orientation === 6){
                canvas.width = hsquare;
                canvas.height = square;
                context.clearRect(0, 0, hsquare, square);
            }else if(Orientation === 8){
                canvas.width = hsquare;
                canvas.height = square;
            }else{
                canvas.width = square;
                canvas.height = hsquare;
                context.clearRect(0, 0, square, hsquare);
            }
        }else{
            canvas.width = square;
            canvas.height = hsquare;
            context.clearRect(0, 0, square, hsquare);
        }
        if(isiOS){
            var degree;
            switch(Orientation){
                case 3:
                    degree = 180;
                    imageWidth = -square;
                    imageHeight = -hsquare;
                    break;
                case 6:
                    degree = 90;
                    imageWidth = square;
                    imageHeight = -hsquare;
                    break;
                case 8:
                    degree = 270;
                    imageWidth = -square;
                    imageHeight = hsquare;
                    break;
                default:
                    degree = 0;
                    imageWidth = square;
                    imageHeight = hsquare;
            }
            context.rotate(degree * Math.PI / 180.0);
        }else{
            if (img.width > img.height) {
                imageWidth = square;
                imageHeight = hsquare;
                offsetX = - Math.round((imageWidth - square) / 2);
            } else {
                imageHeight = hsquare;
                imageWidth = square;
                offsetY = - Math.round((imageHeight - hsquare) / 2);
            }
        }
        context.drawImage(this, offsetX, offsetY, imageWidth, imageHeight);
        //压缩处理得到的base64
        var blob = canvas.toDataURL('image/jpeg', 1.0);
        //base64转blob
        var blobs = toBlob(blob);
    });
});
//base64转blob
function toBlob(urlData) {
    var bytes = window.atob(urlData.split(',')[1]);
    // 去掉url的头,并转换为byte
    // 处理异常,将ascii码小于0的转换为大于0
    var ab = new ArrayBuffer(bytes.length);
    var ia = new Uint8Array(ab);
    for (var i = 0; i < bytes.length; i++) {
        ia[i] = bytes.charCodeAt(i);
    }
    return new Blob([ab],{type : 'image/jpeg'});
}

阅读全文