main.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Vue from 'vue'
  2. import App from './App'
  3. //引入 vuex 和 ajax 并将其关联
  4. import store from './store.js' //引入 vuex
  5. import ajax from './common/js/ajax.js' //引入 ajax 方法
  6. Vue.prototype.$store = store //挂载 vuex
  7. Vue.prototype.$ajax = ajax(store) //挂在 ajax 执行后的 ajax 对象
  8. //在Vue 原型上挂载的一些方法
  9. Vue.prototype.$verified = function() { //判断用户是否已经验证的全局方法
  10. return store.state.userServerInfo.token ? true : false
  11. }
  12. Vue.prototype.$scrollViewHeight = function (className) { //设置页面内 scroll view 的高度
  13. this.$nextTick(() => { //在 mounted 以后获取到 className 的高度,赋给 scroll view
  14. const query = uni.createSelectorQuery().in(this)
  15. query.select(className).boundingClientRect()
  16. query.exec(res => this.scrollViewHeight = res[0].height)
  17. })
  18. }
  19. Vue.prototype.$hideLoading = function() { //异步操作结束,停止 loading
  20. this.$nextTick(() => {
  21. uni.hideLoading()
  22. })
  23. }
  24. Vue.prototype.$drawHonour = function(ctx, infoArr) { //绘制荣誉证书
  25. ctx.setTextAlign('center')
  26. ctx.setFontSize(infoArr[0][0])
  27. ctx.fillText(infoArr[0][1], infoArr[0][2], infoArr[0][3])
  28. ctx.setFontSize(infoArr[1][0])
  29. ctx.fillText(infoArr[1][1], infoArr[1][2], infoArr[1][3])
  30. ctx.setFontSize(infoArr[2][0])
  31. ctx.fillText(infoArr[2][1], infoArr[2][2], infoArr[2][3])
  32. ctx.setFontSize(infoArr[3][0])
  33. ctx.fillText(infoArr[3][1], infoArr[3][2], infoArr[3][3])
  34. ctx.setFontSize(infoArr[4][0])
  35. ctx.fillText(infoArr[4][1], infoArr[4][2], infoArr[4][3])
  36. ctx.setFontSize(infoArr[5][0])
  37. ctx.fillText(infoArr[5][1], infoArr[5][2], infoArr[5][3])
  38. ctx.draw()
  39. }
  40. //自定义的一些全局组件
  41. import nav from './components/custom-nav.vue' //自定义头部导航栏
  42. import toast from './components/custom-toast.vue' //自定义消息提示
  43. import counter from './components/custom-counter.vue' //自定义计数器
  44. import reachBot from './components/custom-reach-bottom.vue' //自定义滚动到底部提示
  45. Vue.component('custom-nav', nav) //注册自定义头部导航栏
  46. Vue.component('custom-toast', toast) //注册自定义消息提示
  47. Vue.component('custom-counter', counter) //注册自定义计数器
  48. Vue.component('custom-reach-bottom', reachBot) //注册自定义滚动到底部提示
  49. //将一些常用的方法定义在过滤器上
  50. import * as filters from './common/js/filters.js'
  51. Object.keys(filters).forEach(e => {
  52. Vue.filter(e, filters[e])
  53. })
  54. Vue.config.productionTip = false
  55. ;( new Vue( { ...App } ) ).$mount()