// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import iView from 'view-design'
import i18n from '@/locale'
import config from '@/config'
import baseMethod from '@/api/base-method'
import importDirective from '@/directive'
import {directive as clickOutside} from 'v-click-outside-x'
import installPlugin from '@/plugin'
import './libs/base/prototype'
import Loading from '_c/loading'
import '@/assets/al-icon/iconfont.css'
import '@/assets/al-icon/iconfont.js'
import 'viewerjs/dist/viewer.css'

import 'bootstrap/scss/bootstrap.scss';

import '@/libs/tools/date-tools'
import '@/libs/tools/array-tools'
import '@/libs/tools/string-tools'
import '@/libs/tools/tools'
import '@/libs/tools/user-tools'
import '@/libs/tools/user-tools'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import tools from '@/libs/tools/tools'
import './index.less'
import {localRead} from "@/libs/base/util";

//周选择器
import '_c/base/date-week/index.less'

let fontSize = localRead('fontSize');
// 根据字体读取不同的字体样式文件
if (fontSize === '14') {
  import  ('./font-less/font-14.less')
} else if(fontSize === '13'){
  import  ('./font-less/font-13.less')
} else {
  import  ('./font-less/font-12.less')
}
// 实际打包时应该不引入mock
/* eslint-disable */
//iview 4.0
import 'view-design/dist/styles/iview.css';


/* 签名 */
import vueEsign from 'vue-esign'
Vue.use(vueEsign)


/* 饿了么 */
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'


Vue.use(ElementUI)

/* 共通方法*/
import libaray from '@/libs/tools/libaray'

Object.defineProperty(Vue.prototype, '$libaray', {value: libaray})

/* 更新列*/
import updateColumns from '@/libs/update-columns/index'

Object.defineProperty(Vue.prototype, '$updateColumns', {value: updateColumns})

import appfunc from '_c/base/dk-approval-flow/js/preload.js'
Vue.prototype.$appfunc = appfunc;

/* vxe */
Vue.use(VXETable)
Vue.prototype.$VXETable = VXETable
VXETable.setup({
  // 对组件内置的提示语进行国际化翻译
  i18n: (key, args) => i18n.t(key, args),
  table: {
    //行的唯一键
    rowId: '_X_ID'
  }
})

/* 打印 */
import Print from 'vue-printjs'
Vue.use(Print)

/* 打印 */
import {hiPrintPlugin} from 'vue-plugin-hiprint'
Vue.use(hiPrintPlugin, '$dkprint')
hiPrintPlugin.disAutoConnect(); // 取消自动连接直接打印客户端
import printUtil from '@/utils/printUtil.js'
Vue.prototype.$printUtil=printUtil

/* 拖动组件 */
// import VueDragResize from 'vue-drag-resize'
// Vue.component('vue-drag-resize', VueDragResize)
//
// //组织机构图
// import DkOrgTree from '_c/base/dk-org-tree'
// Vue.component('DkOrgTree', DkOrgTree)
//照片墙
import DkPicWall from '_c/base/dk-pic-wall'
Vue.component('DkPicWall', DkPicWall)
/* 全局引入组件 */
import SearchCond from '_c/business/search-cond'
Vue.component('SearchCond', SearchCond)

import InputPop from '_c/base/input-pop'
Vue.component('InputPop', InputPop)

import InputNumberPop from '_c/base/input-number-pop'
Vue.component('InputNumberPop', InputNumberPop)

import SelectPop from '_c/base/select-pop'
Vue.component('SelectPop', SelectPop)

import DkFilterButton from '_c/base/dk-filter-button'
Vue.component('DkFilterButton', DkFilterButton)

import SelectInputPop from '_c/base/select-input-pop'
Vue.component('SelectInputPop', SelectInputPop)

import DatePickerPop from '_c/base/dk-date-picker-pop'
Vue.component('DatePickerPop', DatePickerPop)

import MonthRangePickerPop from '_c/base/dk-month-range-picker-pop'
Vue.component('MonthRangePickerPop', MonthRangePickerPop)

import {DkForm, DkFormItem} from '_c/base/dk-form'
Vue.component('DkForm', DkForm)

Vue.component('DkFormItem', DkFormItem)
import {BaseIndexButtonGroup, BaseIndexButton} from '_c/base/index-button-group'

Vue.component('BaseIndexButtonGroup', BaseIndexButtonGroup)
Vue.component('BaseIndexButton', BaseIndexButton)

import DkTabs from '_c/base/dk-tabs'
Vue.component('DkTabs', DkTabs)

import DkRadio from '_c/base/dk-radio'
Vue.component('DkRadio', DkRadio)

import DkRow from '_c/base/dk-row'
Vue.component('DkRow', DkRow)

import DkSwitch from '_c/base/dk-switch'
Vue.component('DkSwitch', DkSwitch)

import DkCol from '_c/base/dk-col'
Vue.component('DkCol', DkCol)

import DkSplit from '_c/base/dk-split'
Vue.component('DkSplit', DkSplit)

import DkCollapse from '_c/base/dk-collapse'
Vue.component('DkCollapse', DkCollapse)

import DkPanel from '_c/base/dk-collapse/dk-panel'
Vue.component('DkPanel', DkPanel)

import DkButton from '_c/base/dk-button'
Vue.component('DkButton', DkButton)

import DkSaveButton from '_c/base/dk-save-button'
Vue.component('DkSaveButton', DkSaveButton)

import DkPageButton from '_c/base/dk-page-button'
Vue.component('DkPageButton', DkPageButton)

import DkModal from '_c/modal/dk-modal'
Vue.component('DkModal', DkModal)

import {DkTableColumn, DkTable} from '_c/table/dk-table'
Vue.component('DkTableColumn', DkTableColumn)
Vue.component('DkTable', DkTable)

import DkTree from '_c/table/dk-tree'

Vue.component('DkTree', DkTree)

import PrependTransparent from '_c/base/prepend-transparent'
Vue.component('PrependTransparent', PrependTransparent)

import EditTable from '_c/table/edit-table'
Vue.component('EditTable', EditTable)

import EditTreeTable from '_c/table/edit-tree-table'
Vue.component('EditTreeTable', EditTreeTable)

import RegionsChoose from '_c/base/regions-choose'
Vue.component('RegionsChoose', RegionsChoose)

import SelectMagnifier from '_c/business/select-magnifier'
Vue.component('SelectMagnifier', SelectMagnifier)

import ModalReceipt from '_c/business/modal-receipt'
Vue.component('ModalReceipt', ModalReceipt)

import DkList from '_c/base/dk-list'
Vue.component('DkList', DkList)

import MultiSelect from '_c/business/multi-select'
Vue.component('MultiSelect', MultiSelect)

import Message from '_c/modal/dk-message'
Vue.prototype.$IBMessage = Message.install

import SearchForm from '_c/business/modal-search-form'
Vue.prototype.$SearchForm = SearchForm.install

import Position from '_c/modal/dk-position'
Vue.prototype.$Position = Position.install

import DkTableMax from '_c/table/dk-table-max'
Vue.prototype.$TableMax = DkTableMax.install

import Perspective from '_c/base/dk-perspective'
Vue.prototype.$Perspective = Perspective.install

import Export from '_c/modal/dk-export'
Vue.prototype.$Export = Export.install

import Function from '_c/modal/dk-function'
Vue.prototype.$Function = Function.install

import ModalBatchEdit from '_c/business/modal_batch_edit'
Vue.prototype.$BatchEdit = ModalBatchEdit.install

import ModalTableFilter from '_c/business/modal_table_filter'
Vue.prototype.$TableFilter = ModalTableFilter.install

//点击复制
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

/* Tour */
import VueTour from 'vue-tour'

require('vue-tour/dist/vue-tour.css')
Vue.use(VueTour)

import Prepend from '_c/sub/prepend'

Vue.component('Prepend', Prepend)


// import echarts from 'echarts';
// Echarts 5.x 不再支持上面的引入方式
import * as echarts from 'echarts'

Vue.prototype.$echarts = echarts

/* vant */
import VantTabs from 'vant/es/tabs/index';
Vue.component('van-tabs', VantTabs)

import VantTab from 'vant/es/tab/index';
Vue.component('van-tab', VantTab)
import 'vant/lib/index.css';

// 引入相关css
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'


Vue.use(iView)

// Vue.component(Tree.name, Tree);
Vue.component(Loading.name, Loading);
/**
 * @description 注册admin内置插件
 */
installPlugin(Vue)
/**
 * @description 生产环境关掉提示
 */
Vue.config.productionTip = false
/**
 * @description 全局注册应用配置
 */

// Vue.prototype.$appfunc = appfunc;

/**
 * @desc   : 读取所有的服务实体
 * @author : 周兴
 * @date   : 2022/12/13 15:27
 */
const services = require.context("@/api/pages", true, /\.js$/);
let commonRoute = null;
let serviceKeys = services.keys();
// 获取common
for (let i = 0; i < serviceKeys.length; i++) {
  if (serviceKeys[i] === './common/common.js') {
    commonRoute = services(serviceKeys[i]).routeUrl;
    break;
  }
}

let res_services = {};
let routeUrl = {search: {key: 'search'}}
serviceKeys.forEach((item) => {
  let comp = services(item);
  // 路由地址
  if (comp.routeUrl && Object.keys(comp.routeUrl).length !== 0) {
    // 如果存在就加进去
    if (!item.includes('common.js')) {
      let key = Object.keys(comp.routeUrl)[0];
      tools.objectMergeByMainJs(comp.routeUrl[key], commonRoute)
      // Object.assign(comp.routeUrl[key], commonRoute)
    }
  } else {
    // 没有那么按照列名进行
    let itemName = item;
    if (itemName) {
      itemName = itemName.substring(itemName.lastIndexOf('/') + 1).replace('.js', '');
      // 中划线转驼峰
      itemName = itemName.getCamelCase();
      let route = {}
      route[itemName] = commonRoute;
      if (comp.routeUrl) {
        tools.objectMergeByMainJs(comp.routeUrl, route)
        // Object.assign(comp.routeUrl, route)
      } else {
        Object.assign(comp, {routeUrl: route})
      }
    }
  }
  if (!item.includes('common.js')) {
    Object.assign(routeUrl, comp.routeUrl);
  }
  if (comp.default) {
    let item = comp.default
    let keys = Object.keys(item)
    if (keys && keys.length > 0) {
      for (let i = 0; i < keys.length; i++) {
        let values = item[keys[i]];
        // 给每个value增加基本方法
        Object.assign(values, baseMethod);
      }
    }
    Object.assign(res_services, item);
  }
});
console.log('33334', routeUrl)
Vue.prototype.$service = res_services;
Object.assign(config, {routeUrl: routeUrl})
Vue.prototype.$config = config

/**
 * 注册指令
 */
importDirective(Vue)
Vue.directive('clickOutside', clickOutside)

/* eslint-disable no-new */
let vueMain = window.vm = new Vue({
  el: '#app',
  router,
  i18n,
  store,
  service:res_services,
  render: h => h(App)
})
export default vueMain


//[iview]Table中点击图片预览放大
import Viewer from 'v-viewer'

Vue.use(Viewer);
Viewer.setDefaults({
  Options: {
    "inline": true,
    "button": true,
    "navbar": true,
    "title": true,
    "toolbar": true,
    "tooltip": true,
    "movable": true,
    "zoomable": true,
    "rotatable": true,
    "scalable": true,
    "transition": true,
    "fullscreen": true,
    "keyboard": true,
    "url": "data-source"
  }
});



