main.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import App from './App'
  2. // #ifndef VUE3
  3. import Vue from 'vue'
  4. import store from './store'
  5. import { initLocale } from '@/locales/i18n'
  6. import loadCloudFontFace from '@/utils/font'
  7. import Dialog from '@/wxcomponents/vant/dialog/dialog'
  8. import './uni.promisify.adaptor'
  9. Vue.config.productionTip = false
  10. Vue.prototype.$config = {
  11. pageHeight: 0
  12. }
  13. Vue.prototype.onInitNavbar = function(e) {
  14. this.$config.pageHeight = e.detail.pageHeight
  15. }
  16. Vue.prototype.checkAuth = function(pagePath) {
  17. console.log(pagePath)
  18. console.log(store.getters.user)
  19. if (!store.getters.user) {
  20. this.redirectTo('/pages/user/login?redirect=' + encodeURIComponent(pagePath))
  21. return false
  22. } else {
  23. return true
  24. }
  25. }
  26. Vue.prototype.redirectTo = function(pagePath) {
  27. console.log(pagePath)
  28. if (pagePath.indexOf('https') === -1) {
  29. uni.redirectTo({
  30. url: pagePath
  31. })
  32. } else {
  33. uni.redirectTo({
  34. url: '/pages/index/webview?url=' + encodeURIComponent(pagePath)
  35. })
  36. }
  37. }
  38. Vue.prototype.navigateTo = function(pagePath) {
  39. console.log(pagePath)
  40. if (pagePath.indexOf('http') === 0) {
  41. this.webviewTo(pagePath)
  42. } else {
  43. uni.navigateTo({
  44. url: pagePath
  45. })
  46. }
  47. }
  48. Vue.prototype.webviewTo = function(url) {
  49. uni.navigateTo({
  50. url: '/pages/index/webview?url=' + encodeURIComponent(url)
  51. })
  52. }
  53. Vue.prototype.showToast = function(title, complete) {
  54. uni.showToast({
  55. icon: 'none',
  56. title: title
  57. })
  58. if (complete)
  59. setTimeout(complete, 2000)
  60. }
  61. Vue.prototype.showSuccessToast = function(title, complete) {
  62. uni.showToast({
  63. icon: 'success',
  64. title: title,
  65. duration: 2000
  66. })
  67. if (complete)
  68. setTimeout(complete, 2000)
  69. }
  70. Vue.prototype.showFailToast = function(title, complete) {
  71. uni.showToast({
  72. icon: 'fail',
  73. title: title,
  74. duration: 2000
  75. })
  76. if (complete)
  77. setTimeout(complete, 2000)
  78. }
  79. Vue.prototype.showLoading = function(options) {
  80. options = options || {
  81. forbidClick: true,
  82. loadingType: 'spinner',
  83. }
  84. if (!options.title) {
  85. options.title = '加载中'
  86. }
  87. uni.showLoading(options)
  88. }
  89. Vue.prototype.hideLoading = function() {
  90. uni.hideLoading()
  91. }
  92. // 所在页面需放置元素
  93. // <van-dialog id="van-dialog" />
  94. Vue.prototype.showAlertDialog = function(message, title) {
  95. return Dialog.alert({
  96. title: title || '系统提示',
  97. message: message
  98. })
  99. }
  100. // 所在页面需放置元素
  101. // <van-dialog id="van-dialog" />
  102. Vue.prototype.showConfirmDialog = function(message, title) {
  103. const options = {
  104. title: title || '系统提示',
  105. message: message
  106. }
  107. return Dialog.confirm(options)
  108. }
  109. Vue.prototype.loadFontFace = function(fontFamily) {
  110. const fontUrls = {
  111. 'Poppins': 'https://oss.starify.cn/test/Poppins-Regular.ttf'
  112. }
  113. loadCloudFontFace(fontUrls[fontFamily], fontFamily + '.ttf', fontFamily)
  114. }
  115. App.mpType = 'app'
  116. const app = new Vue({
  117. App,
  118. store
  119. })
  120. app.$mount()
  121. const token = uni.getStorageSync('token')
  122. const user = uni.getStorageSync('user')
  123. if (user) {
  124. store.commit('SET_USER', user)
  125. }
  126. if (token) {
  127. store.commit('SET_TOKEN', token)
  128. store.dispatch('getInfo')
  129. }
  130. initLocale()
  131. // #endif
  132. // #ifdef VUE3
  133. import {
  134. createSSRApp
  135. } from 'vue'
  136. export function createApp() {
  137. const app = createSSRApp(App)
  138. return {
  139. app
  140. }
  141. }
  142. // #endif