import {
    createApp
} from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/css/icon.css'
import './assets/font/iconfont.css'
import 'default-passive-events'
import 'virtual:windi.css'
import dialogDrag from '/@/assets/js/dialogDrag.js' // 地址就是dialogDrag.js在位置
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import {
    ElMessage
} from 'element-plus'

// 引入请求工具
import axios from "@api/axios2";

// 引入基础工具
import basicTool from "@tools/basicTool";

/**
 * 对 Date 的扩展，将 Date 转化为指定格式的字符串
 * @param {String} fmt 传入一个字符串，根据所传字符串的格式返回转换后特定格式的日期。
 * 调用姿势：new Date().formatDate("yyyy-MM-dd hh:mm:ss");
 */
Date.prototype.formatDate = function (fmt) {
    let o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (let k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }

    }
    return fmt;
}

const VUE = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    VUE.component(key, component)
}

const messageToast = () => { //作为eventListener时, 必须使用外部定义函数
    ElMessage.error('5秒内请勿重复点击')
}
/**阻止多次重复点击指令  延时暂定5秒 示例 v-prevdbclick:arg='func' */
const funListener = (el, binding) => {
    let time = null
    el.removeEventListener('click', messageToast)
    el.addEventListener('click', () => {
        binding.value()
        el.addEventListener('click', messageToast, false)
        time = setTimeout(() => {
            clearTimeout(time)
            funListener(el, binding)
        }, Number(binding.arg) || 5000)
    }, {
        once: true
    })
}
VUE.directive('prevdbclick', {
    mounted(el, binding) {
        funListener(el, binding)
    }
})

window.__STATICVUE__ = VUE;

window.__STATICVUE__.use(router).use(store).use(dialogDrag).use(ElementPlus, {
    size: 'small'
});
window.__STATICVUE__.config.globalProperties.API = axios; //全局注册
window.__STATICVUE__.config.globalProperties.BASE = basicTool; //全局注册

window.__STATICVUE__.mount('#app');