import Vue from 'vue'

console.log(123)
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css
import '@/icon/iconfont.css'

import App from './App'
import router from './router'
import store from './store'
import * as echarts from 'echarts'
import '@/icons' // icon
import '@/permission' // permission control
import curd from '@/utils/curd'
import time from 'time-formater'

import htmlToPdf from '@/vendor/htmlToPdf'
// import VueBarcode from '@xkeshi/vue-barcode'
import Direction from 'vue-direction-key'
import elDragDialog from '@/directive/el-dragDialog'
// 全局数字、金额输入框组件
import directive from './components/AmountInputBox/index.js'
Vue.use(directive)

Vue.use(elDragDialog)
Vue.use(Direction)
Vue.use(curd)
Vue.use(htmlToPdf)
Vue.use(ElementUI)
// 关闭点弹窗周围关闭功能 -- 20200218
ElementUI.Dialog.props.closeOnClickModal.default = false

// 处理时间字符串格式全局过滤器 '2018/1/23 00:00:00' to '2018-01-23'
Vue.filter('formatTime', function(value) {
  if (!value) return ''
  const isTime = /^\d{4}([-/.])\d{1,2}\1\d{1,2}/
  if (!isTime.test(value)) return value
  let result = time(value).format('YYYY-MM-DD')
  result = result.indexOf('1900-01-01') > -1 ? '' : result
  return result
})
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})

// end--->

// 哈希表
export function HashTable() {
  let size = 0
  // eslint-disable-next-line no-new-object
  let entry = new Object()
  this.add = function(key, value) {
    if (!this.containsKey(key)) {
      size++
    }
    entry[key] = value
  }
  this.getValue = function(key) {
    return this.containsKey(key) ? entry[key] : null
  }
  this.remove = function(key) {
    if (this.containsKey(key) && (delete entry[key])) {
      size--
    }
  }
  this.containsKey = function(key) {
    return (key in entry)
  }
  this.containsValue = function(value) {
    for (const prop in entry) {
      if (entry[prop] === value) {
        return true
      }
    }
    return false
  }
  this.getValues = function() {
    // eslint-disable-next-line no-array-constructor
    const values = []
    for (const prop in entry) {
      values.push(entry[prop])
    }
    return values
  }
  // this.getKey = function(value) {
  //   for (const prop in entry) {
  //     if (entry[key]) {
  //       return prop
  //     }
  //   }
  // }
  this.getKeys = function() {
    // eslint-disable-next-line no-array-constructor
    const keys = new Array()
    for (const prop in entry) {
      keys.push(prop)
    }
    return keys
  }
  this.getSize = function() {
    return size
  }
  this.clear = function() {
    size = 0
    // eslint-disable-next-line no-new-object
    entry = new Object()
  }
}
import Router from 'vue-router'
const originalReplace = Router.prototype.replace
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}
