main.js 4.41 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
import {componentInstall, appStyle} from 'hls-easy-ui'
/**
 * 指令
 */
import directives from './scripts/directives'

import filter from './scripts/filter'

李晓兵's avatar
李晓兵 committed
27
import './scripts/prototype'
李晓兵's avatar
李晓兵 committed
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 60
/**
 * 组件
 */
// 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'

JingChao's avatar
JingChao committed
61
if (process.env.CONFIG_ENV === 'uat' || process.env.CONFIG_ENV === 'dev') {
JingChao's avatar
JingChao committed
62 63 64
  const VConsole = require('vconsole')
  new VConsole() // eslint-disable-line
}
李晓兵'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

Vue.config.productionTip = false

let backButtonPressedOnceToExit

vum.$vumPlatform.ready(function () {
  if ((vum.Platform.isAndroid()) || (vum.Platform.isIOS())) {
JingChao's avatar
JingChao committed
124
    /* window.getRegistrationID = function (callback){
李晓兵's avatar
李晓兵 committed
125
      callback('')
JingChao's avatar
JingChao committed
126
    } */
李晓兵's avatar
李晓兵 committed
127 128 129
    try {
      setTimeout(function () {
        navigator.splashscreen.hide()
李晓兵's avatar
李晓兵 committed
130
        if (window.plugins.jPushPlugin) {
李晓兵's avatar
李晓兵 committed
131 132 133 134
          Jpush._init()
        }
        if (window.JMessagePlugin) {
          Jmessage._init({'isOpenMessageRoaming': true})
李晓兵's avatar
李晓兵 committed
135
        }
李晓兵's avatar
李晓兵 committed
136 137 138 139
      }, 40)
    } catch (e) {
    }
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
李晓兵's avatar
李晓兵 committed
140
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true)
李晓兵's avatar
李晓兵 committed
141 142 143 144 145
      cordova.plugins.Keyboard.disableScroll(true)
    }

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

    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
159
vum.$vumPlatform.registerBackButtonAction(function (e) {
786817560's avatar
786817560 committed
160
  // let vm = this
李晓兵's avatar
李晓兵 committed
161 162 163
  let time
  let path = router.currentRoute.path

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

/* 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')