main.js 5.72 KB
Newer Older
葛齐林's avatar
葛齐林 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
// polyfill
import 'babel-polyfill'
// Vue
import Vue from 'vue'
import App from './App'
import { mapState } from 'vuex'
import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'
import 'vue-directive-image-previewer/dist/assets/style.css'
// import Pug from 'pug'
// store
import store from '@/store/index'
// 模拟数据
// import '@/mock'
// 多国语
import i18n from './i18n'
// 核心插件
import d2Admin from '@/plugin/d2admin'

// [ 可选插件组件 ]D2-Crud
import D2Crud from '@d2-projects/d2-crud'
// [ 可选插件组件 ] 图表
import VCharts from 'v-charts'
// [ 可选插件组件 ] 图表
import echarts from 'echarts'
// [ 可选插件组件 ] 右键菜单
// import contentmenu from 'v-contextmenu'
// import 'v-contextmenu/dist/index.css'
// [ 可选插件组件 ] JSON 树状视图
import vueJsonTreeView from 'vue-json-tree-view'
// [ 可选插件组件 ] 网格布局组件
import { GridLayout, GridItem } from 'vue-grid-layout'
// [ 可选插件组件 ] 区域划分组件
import SplitPane from 'vue-splitpane'
import VueCropper from 'vue-cropper'
// 菜单和路由设置
import router from './router'
// import { menuHeader, menuAside } from '@/menu'
import { frameInRoutes } from '@/router/routes'
import httpRequest from '@/plugin/axios'
import { isAuth } from '@/util'
import elTableInfiniteScroll from 'el-table-infinite-scroll'
//重复点击校验
import { preventReClick } from '@/util/plugins'
// import './promission'
//自定义提示框
import toastRegistry from './components/toast/index'
xiexingan's avatar
xiexingan committed
47
import cardWarp from '@/pages/components/cardWarp.vue'
葛齐林's avatar
葛齐林 committed
48
import ElementUI from 'element-ui' //element-ui的全部组件
xiexingan's avatar
xiexingan committed
49

xiexingan's avatar
xiexingan committed
50
import './assets/style/iconfont/iconfont.css'
xiexingan's avatar
xiexingan committed
51

xiexingan's avatar
xiexingan committed
52
Vue.component('cardWarp', cardWarp)
葛齐林's avatar
葛齐林 committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
// import 'element-ui/lib/theme-chalk/index.css'
Vue.use(toastRegistry)//element-ui的css
Vue.use(ElementUI) //使用elementUI

//全局

// 核心插件
Vue.use(d2Admin)
Vue.use(VueDirectiveImagePreviewer, {
  zIndex: 9999, //层级显示
  previewSize: 6 //六倍图
})
Vue.use(VueCropper)
// 可选插件组件
Vue.use(D2Crud)
Vue.use(VCharts)
Vue.use(echarts)
// Vue.use(contentmenu)
Vue.use(vueJsonTreeView)
Vue.component('d2-grid-layout', GridLayout)
Vue.component('d2-grid-item', GridItem)
Vue.component('SplitPane', SplitPane)
//无限滚动组件
Vue.use(elTableInfiniteScroll)
// 挂载全局
Vue.prototype.$echarts = echarts //echarts统计插件
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.isAuth = isAuth // 权限方法
Vue.prototype.$showLoading = (val) => { // 加载等待弹窗
  let loading = Vue.prototype.$loading({
    lock: true,
    text: '正在操作,请稍后...',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  })
  setTimeout(() => {
    loading.close()
  }, 3000)
  if (val === 'close') {
    loading.close()
  }
}

new Vue({
  router,
  store,
  i18n,
  render: h => h(App),
  computed: {
    ...mapState('d2admin/menu', [
      'header'
    ])
  },
  created () {
    // 处理路由 得到每一级的路由设置
    this.$store.commit('d2admin/page/init', frameInRoutes)
    // // 设置顶栏菜单
    // this.$store.commit('d2admin/menu/headerSet', menuHeader)
    // // 初始化菜单搜索功能
    // this.$store.commit('d2admin/search/init', menuHeader)
co_dengxiongwen's avatar
co_dengxiongwen committed
113
    const pattern = /[`~^*|{}<>¥……*|&‘”“/#【】《》\\[\]$%+=]/ //这些字段不允许输入
葛齐林's avatar
葛齐林 committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    const testMark = function (s) {
      return pattern.test(s)
    }
    const replaceMark = function (s, isOutSpace) {
      let rs = ''
      for (let i = 0; i < s.length; i++) {
        rs = rs + s.substr(i, 1).replace(pattern, '')
        rs = rs.replace('-', '')
        // rs = rs.replace('\\', '');
        if (!isOutSpace) {
          rs = rs.replace(' ', '')
        }
      }
      return rs
    }
129

葛齐林's avatar
葛齐林 committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    const timeReplaceMark = function (obj) {
      if (testMark(obj.value)) {
        obj.value = replaceMark(obj.value, true)
      } else if (/'/.test(obj.value)) {
        const tempValue = obj.value.replace(/'/gi, '')
        if (tempValue == '') { //如果全是'',代表不是输入词语,可以替换
          obj.value = tempValue
        }
      } else if (/"/.test(obj.value)) {
        const tempValue = obj.value.replace(/"/gi, '')
        if (tempValue == '') { //如果全是'',代表不是输入词语,可以替换
          obj.value = tempValue
        }
      }
    }
    document.addEventListener('input', function (ev) {
      // console.log(ev);
      if (ev.target.type === 'text' || ev.target.type === 'textarea') {
        timeReplaceMark(ev.target)
      }
150
    }, true)
葛齐林's avatar
葛齐林 committed
151
  },
152
  beforeDestroy() {
葛齐林's avatar
葛齐林 committed
153 154 155 156 157
    window.removeEventListener('input', function (ev) {
      // console.log(ev);
      if (ev.target.type === 'text' || ev.target.type === 'textarea') {
        timeReplaceMark(ev.target)
      }
158
    }, true)
葛齐林's avatar
葛齐林 committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  },
  mounted () {
    // 展示系统信息
    this.$store.commit('d2admin/releases/versionShow')
    // 检查最新版本 // 临时关闭git的自动检查更新
    // this.$store.dispatch('d2admin/releases/checkUpdate')
    // 用户登录后从数据库加载一系列的设置
    this.$store.dispatch('d2admin/account/load')
    // 获取并记录用户 UA
    this.$store.commit('d2admin/ua/get')
    // 初始化全屏监听
    this.$store.dispatch('d2admin/fullscreen/listen')
  },
  watch: {
    // 监听路由 控制侧边栏显示

    // 现在没有侧边栏 不需要
    // '$route.matched' (val) {
    //   const _side = this.header.filter(menu => menu.path === val[0].path)
    //   this.$store.commit('d2admin/menu/asideSet', _side.length > 0 ? _side[0].list : [])
    // }
  }
}).$mount('#app')