2020年10月

Git相关资源

Git官网: https://git-scm.com

TortoisGit官网:https://tortoisegit.org

Sourcetree官网:https://www.sourcetreeapp.com/

Git命令(官方网站: https://git-scm.com/docs

删除远程仓库的地址
$ git remote rm origin
重置到提交 (恢复到f4df19d提交)
$ git reset --hard f4df19d
重置到远程自己最后一次提交(有可能会抹掉别人的提交)
$ git push origin HEAD --force
取消上一次本地提交(同时清空提交的内容)
$ git reset HEAD~ && git checkout . && git clean -xdf
清除本地提交
$ git reset --hard FETCH_HEAD
清除缓存区所有的内容(不包含本地提交)
$ git checkout . && git clean -xdf

添加远程地址(比如远程地址:git@git.kjwoo.cn:bowen/test.git)
$ git remote add origin git@git.kjwoo.cn:bowen/test.git
修改远端地址
$ git remote set-url origin xxx

使用yum安装git2.X(wandisco的yum源)
[root@wkjhost ~]# yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm
[root@wkjhost ~]# yum install git

git push到远程分支时报错error: RPC failed; HTTP 411 curl 22 The requested URL returned error: 411 Length Req
git config http.postBuffer 524288000

清理本地存储
$ git gc --prune=now
$ git remote prune origin

使用合并策略

git config --global pull.rebase true
git config --global branch.autoSetupRebase always

标签

//创建标签
git tag -a 标签名字 -m "标签注释"
//推送所有的分支到远端
git push origin --tags

sourcetree 还原配置

确保SourceTree已关闭。
  
确保在删除文件之前在以下文件夹中备份文件
  
删除~/Library/Application Support/SourceTree/
中的所有内容   
删除~/Library/Preferences/com.torusknot.SourceTreeNotMAS.plist(您应该使用SourceTree的直接版本,因此“NotMAS”)

安装环境shell脚本(centos7)

#!/bin/bash
#suppor china
yum install wqy-microhei-fonts wqy-zenhei-fonts

#office to pdf
yum install unoconv -y

#pdf to slide image
yum install ImageMagick -y

使用node构造核心类officeCovert.js

const unoconv = require('awesome-unoconv');
const fs = require('fs');
const child_process = require("child_process");

class OfficeCovert{
    //file to pdf 
    file2pdf(sourceFile, generateFile){
        return unoconv.convert(sourceFile, generateFile);
    }

    //file to image list
    file2images(file, path, prefix = '', suffix ='', ext = 'png'){
        return new Promise((resolve, reject)=> {
            if(fs.existsSync(file)){
                this.rm(path);
                this.mkdir(path);
                child_process.exec(`convert ${file} ${path}/${prefix}%d${suffix}.${ext} `, (...args) =>{
                    if(args && args[0] === null){
                        resolve(path);
                    }else{
                        reject(...args);
                    }
                }, err => {
                    reject(err);
                });
            }else{
                reject('file not found');
            }
        });
    }

    //delete file or path
    rm(path){
        let files = [];
        if(fs.existsSync(path)){
            if(fs.statSync(path).isDirectory()){
                files = fs.readdirSync(path);
                files.forEach((file, index)=> {
                    let curPath = path + '/' + file;
                    if(fs.statSync(curPath).isDirectory()){
                        this.rm(curPath);
                    }else{
                        fs.unlinkSync(curPath);
                    }
                });
            }else{
                fs.unlinkSync(path);
            }
        }
    }
    //create path
    mkdir(path){
        if(!fs.existsSync(path)){
            fs.mkdir(path,{ recursive: true }, res=>  {
                if(res){
                    console.warn(res);
                }
            });    
        }
    }
}

module.exports = OfficeCovert;

入口文件index.js

const {resolve} = require('path');

const OfficeCovert = require('./officeCovert');
//定义需要转换的文件
const pptFile = resolve('./office/test2.pptx');
//生成pdf名称
const pdfFile = resolve('./output/test2.ppf');
//设置图片目录
const imgFile = resolve('./output/test2/tst');
const oc = new OfficeCovert();

//geneate pdf
oc.file2pdf(pptFile, pdfFile).then(gFile =>{
    //generate image
    oc.file2images(gFile, imgFile, 'test11', 'mytest', 'png').then(path=> {
        console.log('generate image success !!!!', path);
        //clean file 
        oc.rm(gFile);
    }).catch((...args) => {
        console.log(args);
    });
});

简单的一个拖拽例子

index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <script src="https://unpkg.com/rxjs/bundles/rxjs.umd.min.js"></script>
        <title>rxjs实现拖拽</title>
        <style>
            #drag {
                width: 200px;
                height: 200px;
                background-color: yellow;
                position: absolute;
                cursor: pointer;
            }
        </style>
    </head>
    <body>
        <div id="drag"></div>
        <script src="./rx-drag.js"></script>
    </body>
</html>

rx-drag.js

const {
    fromEvent,
    operators: { map, takeUntil, concatAll, withLatestFrom }
} = rxjs;

const target = document.getElementById("drag");

const mouseDown = fromEvent(target, "mousedown");
const mouseMove = fromEvent(document, "mousemove");
const mouseUp = fromEvent(document, "mouseup");

mouseDown
    .pipe(
        map(e => {
            const { left, top } = e.target.getBoundingClientRect();
            const clickOffsetX = e.clientX - left;
            const clickOffsetY = e.clientY - top;
            return {
                clickOffsetX,
                clickOffsetY
            };
        }),
        map(({ clickOffsetX, clickOffsetY }) => {
            return mouseMove.pipe(
                takeUntil(mouseUp),
                map(moveEvent => ({
                    x: moveEvent.clientX - clickOffsetX,
                    y: moveEvent.clientY - clickOffsetY
                }))
            );
        }),
        concatAll()
    )
    .subscribe(({ x, y }) => {
        target.style.left = `${x}px`;
        target.style.top = `${y}px`;
    });

react中

在src目录下新建文件setupProxy.js

const {createProxyMiddleware} = require('http-proxy-middleware')

//代理设置
module.exports = function (app) {
    app.use(createProxyMiddleware("/api", {
      target: 'http://localhost:3300',
      secure: false,
      changeOrigin: true,
      pathRewrite: {
        "^/api": "/test"
      }
    }));
}

vue项目中

在config/index.js的dev节点下新增代理信息

    //设置代理
    proxyTable: {
      '/api': {
        target: 'http://localhost:3300',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          "^/api": "/test"
        }
      }
    }

建立专门的代理项目(egg项目举例)

config.js

const host = 'http://test.tms.loji.com';

//公共头部
var commonHeaders =  {
  'content-type': 'application/json',
  Cookie: '登录之后cookie'
};
module.exports = {
    host,
    commonHeaders
}

home.js

'use strict';
const Controller = require('egg').Controller;
const {host, commonHeaders} = require('../../config');

class HomeController extends Controller {
  getHeaderAndData(ctx){
      let data = ctx.request.body;
      let contentType = ctx.headers['content-type'];
      let headers = JSON.parse(JSON.stringify(commonHeaders));
      if(!/json/.test(contentType)){
        headers['content-type'] = contentType;
      }else{
        data = JSON.stringify(data);
      }
      return {data, headers}
  }
  
  //匹配所有路由(作为代理处理)
  async allRoute(){
    const {ctx} = this;
    const {data = null, headers} = this.getHeaderAndData(ctx);
    let response = await ctx.curl(host + ctx.originalUrl, {
      method: ctx.method,
      data,
      headers
    });
    try{
        ctx.body = JSON.parse(response.data);
    }catch(e){
        console.error('解析json失败!!!', response);
        ctx.body = {
          status: 0,
          msg: '解析json错误'
        }
    }
  }
}
module.exports = HomeController;

route.js

'use strict';
module.exports = app => {
  const { router, controller } = app;
  router.all('*', controller.home.allRoute);
};

egg配置(与代理无关)

'use strict';
const path = require('path');
module.exports = appInfo => {
  const config = exports = {};
  //跨域允许
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
  };
  //使用ejs模板
  config.view = {
    mapping: {
      '.html': 'ejs',
    },
  };
  //禁止表单报错
  config.security = {
    csrf: {
      enable: false,
    },
  };
  //规定静态资源路劲
  config.static = {
      prefix:'/',
      dir: [path.join(appInfo.baseDir, 'app/public')]
  }
  //设置系统加密串
  config.keys = appInfo.name + '_1592967337826_1169';
  //使用的中间件
  config.middleware = [];
  //自定义配置
  const userConfig = {
    // myAppName: 'egg',
  };
  return {
    ...config,
    ...userConfig,
  };
};

Centos 7防火墙firewalld开放80端口

开启80端口

1、firewall-cmd --zone=public --add-port=80/tcp --permanent

出现success表明添加成功
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议=
--permanent #永久生效,没有此参数重启后失效

2、重启防火墙

systemctl restart firewalld.service