main.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import { VueJsonp } from 'vue-jsonp'
  5. Vue.use(VueJsonp)
  6. import App from './App'
  7. import router from './router'
  8. import store from './store/store' // 引入store
  9. import resource from 'vue-resource' // 引入vue-resource
  10. import tabbar from './components/tabbar.vue'
  11. import banner from './components/banner.vue'
  12. import back from './components/back.vue'
  13. import backIndex from './components/backindex.vue'
  14. import Vant from 'vant'
  15. import clipboard from 'clipboard'
  16. import 'vant/lib/index.css'
  17. import wx from 'weixin-js-sdk'
  18. import VConsole from 'vconsole';
  19. const vconsole = new VConsole()
  20. import request from "@/utils/request"
  21. Vue.prototype.$axios = request
  22. Vue.prototype.$wx = wx
  23. Vue.component('tabbar', tabbar)
  24. Vue.component('banner', banner)
  25. Vue.component('back', back)
  26. Vue.component('backindex', backIndex)
  27. Vue.config.productionTip = false
  28. Vue.use(Vant)
  29. Vue.use(resource)
  30. import common from './script/common.js'
  31. Vue.use(common)
  32. Vue.prototype.clipboard = clipboard
  33. // 时间戳过滤器
  34. Vue.filter('dateFormat', (dataStr) => {
  35. var time = new Date(dataStr)
  36. function timeAdd0(str) {
  37. if (str < 10) {
  38. str = '0' + str
  39. }
  40. return str
  41. }
  42. var y = time.getFullYear()
  43. var m = time.getMonth() + 1
  44. var d = time.getDate()
  45. var h = time.getHours()
  46. var mm = time.getMinutes()
  47. var s = time.getSeconds()
  48. return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) + ' ' + timeAdd0(h) + ':' + timeAdd0(mm) + ':' + timeAdd0(s)
  49. })
  50. // import { getWxOpenId } from './script/wxGetOpenId.js'
  51. export { getWxOpenId } from './script/wxGetOpenId.js'
  52. const whiteList = ['/Login']
  53. router.beforeEach((to, from, next) => {
  54. // if (to.matched.some(record => record.meta.needLogin)) { // 判断该路由是否需要登录权限
  55. if (!whiteList.includes(to.path)) {
  56. console.log('有登录权限')
  57. if (!localStorage.getItem('userId')) { // 判断当前用户的登录信息userId是否存在
  58. console.log('无userId')
  59. next('/Login')
  60. } else if (!localStorage.getItem('openid')) {
  61. console.log('无openId')
  62. // overallExample.getOpenid()
  63. getWxOpenId()
  64. console.log('overallExample.getOpenid()走完了')
  65. } else {
  66. console.log('什么都有')
  67. next()
  68. }
  69. } else {
  70. console.log('无登录权限')
  71. next();
  72. }
  73. })
  74. new Vue({
  75. el: '#app',
  76. router,
  77. store: store,
  78. components: { App },
  79. template: '<App/>',
  80. })