import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import store from './store'
import { initLocale } from '@/locales/i18n'
import loadCloudFontFace from '@/utils/font'
import Dialog from '@/wxcomponents/vant/dialog/dialog'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
Vue.prototype.$config = {
pageHeight: 0
}
Vue.prototype.onInitNavbar = function(e) {
this.$config.pageHeight = e.detail.pageHeight
}
Vue.prototype.checkAuth = function(pagePath) {
if (!store.getters.user) {
this.redirectTo('/pages/user/login?redirect=' + encodeURIComponent(pagePath))
return false
} else {
return true
}
}
Vue.prototype.redirectTo = function(pagePath) {
if (pagePath.indexOf('https') === -1) {
uni.redirectTo({
url: pagePath
})
} else {
uni.redirectTo({
url: '/pages/index/webview?url=' + encodeURIComponent(pagePath)
})
}
}
Vue.prototype.navigateTo = function(pagePath) {
if (pagePath.indexOf('http') === 0) {
this.webviewTo(pagePath)
} else {
uni.navigateTo({
url: pagePath
})
}
}
Vue.prototype.webviewTo = function(url) {
uni.navigateTo({
url: '/pages/index/webview?url=' + encodeURIComponent(url)
})
}
Vue.prototype.showToast = function(title, complete) {
uni.showToast({
icon: 'none',
title: title
})
if (complete)
setTimeout(complete, 2000)
}
Vue.prototype.showSuccessToast = function(title, complete) {
uni.showToast({
icon: 'success',
title: title,
duration: 2000
})
if (complete)
setTimeout(complete, 2000)
}
Vue.prototype.showFailToast = function(title, complete) {
uni.showToast({
icon: 'fail',
title: title,
duration: 2000
})
if (complete)
setTimeout(complete, 2000)
}
Vue.prototype.showLoading = function(options) {
options = options || {
forbidClick: true,
loadingType: 'spinner',
}
if (!options.title) {
options.title = '加载中'
}
uni.showLoading(options)
}
Vue.prototype.hideLoading = function() {
uni.hideLoading()
}
// 所在页面需放置元素
//
Vue.prototype.showAlertDialog = function(message, title) {
return Dialog.alert({
title: title || '系统提示',
message: message
})
}
// 所在页面需放置元素
//
Vue.prototype.showConfirmDialog = function(message, title) {
const options = {
title: title || '系统提示',
message: message
}
return Dialog.confirm(options)
}
Vue.prototype.loadFontFace = function(fontFamily) {
const fontUrls = {
'Poppins': 'https://oss.starify.cn/test/Poppins-Regular.ttf'
}
if (fontFamily === 'Poppins') {
// 开发者工具没有该字体
wx.getSystemInfo({
success(res) {
// if (res.platform === 'devtools') {
loadCloudFontFace(fontUrls[fontFamily], fontFamily + '.ttf', fontFamily)
// }
}
})
} else {
loadCloudFontFace(fontUrls[fontFamily], fontFamily + '.ttf', fontFamily)
}
}
App.mpType = 'app'
const app = new Vue({
App,
store
})
app.$mount()
const token = uni.getStorageSync('token')
const user = uni.getStorageSync('user')
if (user) {
store.commit('SET_USER', user)
}
if (token) {
store.commit('SET_TOKEN', token)
store.dispatch('getInfo')
}
initLocale()
// #endif
// #ifdef VUE3
import {
createSSRApp
} from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif