main.js 4.27 KB
Newer Older
786817560's avatar
786817560 committed
1 2 3 4 5 6 7
/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-24 12:34:06
 * @LastEditTime: 2019-09-24 12:34:06
 * @LastEditors: your name
 */
李晓兵's avatar
李晓兵 committed
8 9 10
// 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'
786817560's avatar
786817560 committed
11
import FastClick from 'fastclick'
李晓兵's avatar
李晓兵 committed
12 13 14 15 16 17
import router from './router'
import App from './App'
import Vuex from 'vuex'
import vuexI18n from 'vuex-i18n'

import flexible from './common/ydui.flexible'
JingChao's avatar
JingChao committed
18
import components from './components/component'
李晓兵's avatar
李晓兵 committed
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 47 48 49 50 51 52 53 54 55 56 57 58 59
import {componentInstall, appStyle} from 'hls-easy-ui'
/**
 * 指令
 */
import directives from './scripts/directives'

import filter from './scripts/filter'

/**
 * 组件
 */
// import component from './components/component.js'

import {
  Tabbar,
  TabbarItem,
} from 'vux'

/**
 * 弹框组件
 */
import hlsPopup from './scripts/hlsPopup'

/**
 * http
 */
import {post, get} from './scripts/hlsHttp'

/** 全局函数hlsUtil**/

import hlsUtil from './scripts/hlsUtil'

/** end**/

/**
 * jpush jmessage
 */
import Jpush from './scripts/jpushService'

import Jmessage from './scripts/jmessageService'

60
// if (process.env.CONFIG_ENV === 'uat') {
李晓兵's avatar
李晓兵 committed
61 62
//  const VConsole = require('vconsole')
//  new VConsole() // eslint-disable-line
63
// }
JingChao's avatar
JingChao committed
64

李晓兵's avatar
李晓兵 committed
65
Vue.use(componentInstall)
JingChao's avatar
JingChao committed
66
Vue.use(components)
李晓兵's avatar
李晓兵 committed
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 113 114 115
Vue.use(appStyle)
Vue.use(flexible)
Vue.use(directives)

Vue.use(filter)

// Vue.use(component)

Vue.use(Vuex)
Vue.component('tabbar', Tabbar)
Vue.component('tabbar-item', TabbarItem)

/** i18n **/
let store = new Vuex.Store({
  modules: {
    i18n: vuexI18n.store,
  },
})
Vue.use(vuexI18n.plugin, store)

Vue.prototype.hlsPopup = window.hlsPopup = hlsPopup
Vue.prototype.$devicePixelRatio = 2

Vue.prototype.$post = post
Vue.prototype.$get = get
let hlsHttp = {
  get: get,
  post: post,
}
Vue.prototype.hlsHttp = window.hlsHttp = hlsHttp

Vue.prototype.hlsUtil = window.hlsUtil = hlsUtil

Vue.prototype.Jpush = window.Jpush = Jpush

Vue.prototype.Jmessage = window.Jmessage = Jmessage

/**
 * 全局返回上一页面
 * @param index
 */
let routeGo = function (index) {
  if (!index) {
    index = -1
  }
  this.$router.go(index)
}
Vue.prototype.$routeGo = routeGo

李晓兵's avatar
李晓兵 committed
116
FastClick.attach(document.body)
李晓兵's avatar
李晓兵 committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

Vue.config.productionTip = false

let backButtonPressedOnceToExit

vum.$vumPlatform.ready(function () {
  if ((vum.Platform.isAndroid()) || (vum.Platform.isIOS())) {
    try {
      setTimeout(function () {
        navigator.splashscreen.hide()
        if (window.plugins.jPushPlugin) {
          Jpush._init()
        }
        if (window.JMessagePlugin) {
          Jmessage._init({'isOpenMessageRoaming': true})
        }
      }, 40)
    } catch (e) {
    }
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
李晓兵's avatar
李晓兵 committed
137
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true)
李晓兵's avatar
李晓兵 committed
138 139 140 141 142
      cordova.plugins.Keyboard.disableScroll(true)
    }

    if (window.StatusBar) {
      window.StatusBar.styleDefault()
李晓兵's avatar
李晓兵 committed
143
      window.StatusBar.backgroundColorByName('white')
李晓兵's avatar
李晓兵 committed
144 145 146 147 148 149 150 151 152 153 154 155
    }

    const winSize = vum.$vumPlatform.getWinSize()
    if (winSize.width) {
      window.localStorage.setItem('width', winSize.width)
    }
    if (winSize.height) {
      window.localStorage.setItem('height', winSize.height)
    }
  }
})

李晓兵's avatar
李晓兵 committed
156
vum.$vumPlatform.registerBackButtonAction(function (e) {
786817560's avatar
786817560 committed
157
  // let vm = this
李晓兵's avatar
李晓兵 committed
158 159 160
  let time
  let path = router.currentRoute.path

李晓兵's avatar
李晓兵 committed
161
  if (path === '/tab/home' || path === '/tab/message' || path === '/tab/my-info') {
李晓兵's avatar
李晓兵 committed
162 163 164 165 166 167 168 169 170 171 172
    // 进入主界面清除缓存
    if (backButtonPressedOnceToExit === true) {
      vum.Platform.exitApp()
    } else {
      backButtonPressedOnceToExit = true
      hlsPopup.showLongBottom('再次点击返回键退出应用')
      clearTimeout(time)
      time = setTimeout(function () {
        backButtonPressedOnceToExit = false
      }, 1500)
    }
JingChao's avatar
JingChao committed
173
  } else if (path === '/login' || path === '/finger-login' || path === '/gesture') {
李晓兵's avatar
李晓兵 committed
174 175 176 177 178 179
    vum.Platform.exitApp()
  } else {
    router.go(-1)
  }
  e.preventDefault()
  return false
李晓兵's avatar
李晓兵 committed
180
}, 101)
李晓兵's avatar
李晓兵 committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

/* eslint-disable no-new */
new Vue({
  data () {
    return {
      pathList: [],
      transitionName: null,
    }
  },
  router,
  watch: { // 监听路由变化
    $route (to, from) {
      document.body.scrollTop = 0
      document.documentElement.scrollTop = 0
    },
  },
  render: h => h(App),
}).$mount('#app-box')