main.js 2.5 KB

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