main.js 3.5 KB

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