Files
AI-guangzhou-uniapp/src/main.ts
2024-08-16 14:04:26 +08:00

71 lines
1.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Vue from 'vue'
import App from './App.vue'
import store from './store'
import { router, RouterMount } from './router'
import BaseMixin from '@/mixins/BaseMixin'
import NavBar from '@/components/navBar/index.vue'
import TabBar from '@/components/tabBar/index.vue'
import '@/static/style/public.scss'
Vue.use(router)
Vue.config.productionTip = false
Vue.use(BaseMixin)
Vue.component('nav-bar', NavBar)
Vue.component('tab-bar', TabBar)
Vue.prototype.$store = store
function isPromise(obj: any) {
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
}
uni.addInterceptor({
returnValue(res: any) {
if (!isPromise(res)) {
return res
}
return new Promise((resolve, reject) => {
res.then((res: [any, any]) => {
if (res[0]) {
reject(res[0])
} else {
resolve(res[1])
}
})
})
}
})
const app: any = new Vue({
store,
...App
})
// #ifdef H5
RouterMount(app, router, '#app')
// #endif
// #ifndef H5
app.$mount() // 为了兼容小程序及app端必须这样写才有效果
// #endif
// #ifdef APP-PLUS
plus.key.addEventListener(
'backbutton',
() => {
let pages = getCurrentPages()
if (pages.length === 1) {
// 首次按键,提示‘再按一次退出应用’
uni.showModal({
title: '提示',
content: '是否退出应用?',
cancelText: '取消',
confirmText: '确定',
success: function (res) {
if (res.confirm) {
// 退出当前应用改方法只在App中生效
plus.runtime.quit()
}
}
})
}
},
false
)
// #endif