/*
 * @Author: WangQiBiao
 * @Date: 2019-09-24 17:50:53
 * @LastEditors: wjc
 * @LastEditTime: 2025-12-01 17:21:02
 * @Description:
 */
import Vue from 'vue'
import App from './App.vue'
import router from './route'
import store from './store'
import 'reset.css'
import 'babel-polyfill'
import * as filters from './filters'
import VueTianditu from 'vue-tianditu'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/css/element-variables.scss'

Vue.use(ElementUI)
// 引入全局过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.filter('safeGet', function (obj, path, defaultValue = '无') {
  // 分割路径（如 'service.work_template.display_name' 拆分为数组）
  const keys = path.split('.')
  let result = obj
  for (const key of keys) {
    // 若中间层级为 null/undefined，直接返回默认值
    if (result === null || result === undefined) return defaultValue
    result = result[key]
  }
  // 最终值为空时返回默认值
  return result || defaultValue
})
Vue.filter('formatNumber', function (num = 0) {
  return (+num).toLocaleString('zh', {
    maximumFractionDigits: 2
  })
})

Vue.use(VueTianditu, {
  v: '4.0',
  tk: 'c1dc742aa22263a258fdc7b2a9ae8172'
})

Vue.config.productionTip = false

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