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 Toast from '@/wxcomponents/vant/toast/toast' 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.refreshData = function() { const pages = getCurrentPages(); // 获取当前页面栈 if (pages.length - 2 >= 0) { const currentPage = pages[pages.length - 2]; // 当前页面实例 const route = currentPage.route; // 页面路径 if (route === 'pages/index/index') { uni.$emit('refreshData', store.getters.page[store.getters.page.length - 1]); } else { uni.$emit('refreshData', route); } } } Vue.prototype.checkAuth = function(pagePath) { if (!store.getters.user) { this.navigateTo('/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, animationType: 'pop-in', animationDuration: 200 }) } } Vue.prototype.webviewTo = function(url) { uni.navigateTo({ url: '/pages/index/webview?url=' + encodeURIComponent(url), animationType: 'pop-in', animationDuration: 200 }) } Vue.prototype.showToast = function(title, complete) { uni.showToast({ icon: 'none', title: title }) if (complete) setTimeout(complete, 2000) } Vue.prototype.getSystemInfo = function(self,callback) { uni.getSystemInfo({ success(res) { const os = res.system.toLowerCase() self.$config.os = os if (os.includes('windows') || os.includes('mac')) { if (callback) { callback('pc') } } else { if (callback) { callback('mobile') } } } }) } 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', mask: true } if (!options.title) { options.title = '加载中' } uni.showLoading(options) } Vue.prototype.handleImageError = function(callback) { callback('https://onlinecatelogue.productronicachina.com.cn/assets/image/normal-logo.jpg') } Vue.prototype.hideLoading = function() { uni.hideLoading() } // 所在页面需放置元素 // Vue.prototype.startLoading = function (status) { return Toast.loading({ message: '加载中...', forbidClick: true, }); if (status) { } else { } } 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' } 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