import popup from './popup';

let copyEl:HTMLInputElement | undefined = undefined;

export default {

    // 复制
    copy(text:string,toast=false) {

        if (copyEl === undefined) {
            copyEl = document.createElement('input');

            copyEl.setAttribute('style','position:absolute;top:0;bottom:0;z-index:-9;height:0');

            document.body.appendChild(copyEl);

        }

        copyEl.value = text;


        copyEl.select(); // 选中文本
        document.execCommand("copy"); // 执行浏览器复制命令
        return toast && popup.$toast('复制成功');
    },
}