/**
 * v-clipboard 剪切板
 */
import Vue from 'vue';
const clipboard = {
  bind(el, binding, vnode, oldVnode) {
    el.val = binding.value;
    el.handler = function() {
      const val = el.val;
      const input = document.createElement('input');
      el.appendChild(input);
      input.value = val;
      input.select();
      document.execCommand('Copy');
      Vue.prototype.$message({ type: 'success', message: '复制成功' });
      input.parentNode.removeChild(input);
    };
    el.addEventListener('click', el.handler);
  },
  update(el, binding, vnode, oldVnode) {
    el.val = binding.value;
  },
  unbind: function(el) {
    el.removeEventListener('click', el.handler);
  }
};
const linkMap = {
  codeList: 'https://www.yuque.com/exnmlu/oo64hg/thm172#WRdju',
  codeGl: 'https://www.yuque.com/exnmlu/oo64hg/thm172#ADEzt',
  codeCkmx: 'https://www.yuque.com/exnmlu/oo64hg/thm172#mDlza',
  linkList: 'https://www.yuque.com/exnmlu/oo64hg/lggf7q#WRdju',
  linkGl: 'https://www.yuque.com/exnmlu/oo64hg/lggf7q#ADEzt',
  linkCkmx: 'https://www.yuque.com/exnmlu/oo64hg/lggf7q#mDlza'
};
const jumpLink = {
  bind(el, binding) {
    const { arg } = binding;
    el.handler = function() {
      window.open(linkMap[arg]);
    };
    el.addEventListener('click', el.handler);
  },
  unbind: function(el) {
    el.removeEventListener('click', el.handler);
  }
};
export default { clipboard, jumpLink };
