Vue.directive("scroll", {
  // 当绑定元素插入到 DOM 中。
  inserted: function(el, binding) {
    let options = binding.expression
      ? JSON.parse(binding.expression)
      : {
          axis: "yx",
          theme: "dark",
          scrollInertia: 300
        };
  }
});
Vue.directive("drag", {
  bind: function(el, binding, vnode, oldVnode) {
    let header = el.querySelector(".el-dialog__header") || el;
    let body = el.querySelector(".el-dialog") || el;
    header.onmousedown = e => {
      if (e.button != 0) {
        return false;
      }
      {
        if (!body.isInitDrag) {
          body.style.cssText = `transform:none;
                    width:${body.offsetWidth}px;
                    height:${body.offsetHeight}px;
                    left:${parseInt(body.offsetWidth / document.body.offsetWidth) + "%"};
                    top:${body.offsetTop}px;
                    bottom:"auto"`;

          body.isInitDrag = true;
        }
      }
      window.onselectstart = window.ondragstart = () => {
        return false;
      };
      let offsetX = e.clientX;
      let offsetY = e.clientY;
      let domLeft = parseFloat(body.style.left);
      let domTop = parseFloat(body.style.top);
      window.onmousemove = _.throttle(e => {
        body.style.left = e.clientX - offsetX + domLeft + "px";
        body.style.top = e.clientY - offsetY + domTop + "px";
        if (parseInt(body.style.top) < 0) {
          body.style.top = 0;
        }
      }, 20);
      window.onmouseup = () => {
        window.onmouseup = window.onmousemove = window.onselectstart = window.ondragstart = null;
      };
    };
  }
});
