优化细节问题

This commit is contained in:
Gao xiaosong
2021-04-18 15:28:14 +08:00
parent 829daf1f61
commit 7333043a4f
10 changed files with 863 additions and 904 deletions

85
main.js
View File

@ -14,7 +14,7 @@ Vue.component('cu-custom', cuCustom)
Vue.config.productionTip = false
Vue.config.devtools = process.env.NODE_ENV !== 'production'
Vue.prototype.$validator = function (rule) {
Vue.prototype.$validator = function(rule) {
return new schema(rule)
}
@ -27,23 +27,6 @@ const app = new Vue({
store,
})
Vue.mixin({
onLoad() {
const { $mp } = this.$root
this._route = parseRoute($mp)
},
onShow() {
_router.app = this
_router.currentRoute = this._route
},
// 这里为了解决 .vue文件中 template 无法获取 VUE.prototype 绑定的变量
computed: {
$VUE_APP_RESOURCES_URL() {
return VUE_APP_RESOURCES_URL;
}
}
})
Object.defineProperty(Vue.prototype, '$yrouter', {
get() {
return _router
@ -59,17 +42,16 @@ Object.defineProperty(Vue.prototype, '$yroute', {
Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
Vue.component('cu-custom', cuCustom)
let deviceType = ''
// #ifdef APP-PLUS
// App平台编译的代码
Vue.prototype.$deviceType = 'app'
store.commit('updateDevicetype', 'app')
deviceType = 'app'
Vue.prototype.$platform = uni.getSystemInfoSync().platform
// #endif
// #ifdef MP-WEIXIN
// 微信小程序编译的代码
Vue.prototype.$deviceType = 'routine'
store.commit('updateDevicetype', 'routine')
deviceType = 'routine'
// #endif
// !!! ps 不建议在 template 中使用 $deviceType 去判断当前环境,很有可能出现 $deviceType 为 undefined 导致判断出错的问题,可以在 script 模块中正常使用
@ -99,29 +81,42 @@ if (urlSpread) {
// #endif
async function init() {
// #ifdef H5
// H5编译的代码
// 判断是否是微信浏览器
if (isWeixin()) {
Vue.prototype.$deviceType = 'weixin'
store.commit('updateDevicetype', 'weixin')
let wechatInit = await wechat()
console.log(wechatInit)
if (wechatInit) {
await oAuth()
app.$mount()
}
} else {
Vue.prototype.$deviceType = 'weixinh5'
store.commit('updateDevicetype', 'weixinh5')
app.$mount()
// #ifdef H5
// H5编译的代码
// 判断是否是微信浏览器
if (isWeixin()) {
deviceType = 'weixin'
let wechatInit = await wechat()
if (wechatInit) {
await oAuth()
}
// #endif
// #ifndef H5
app.$mount()
// #endif
} else {
deviceType = 'weixinh5'
}
// #endif
init()
Vue.prototype.$deviceType = deviceType
Vue.mixin({
onLoad() {
const { $mp } = this.$root
this._route = parseRoute($mp)
},
onShow() {
_router.app = this
_router.currentRoute = this._route
},
// 这里为了解决 .vue文件中 template 无法获取 VUE.prototype 绑定的变量
computed: {
$VUE_APP_RESOURCES_URL() {
return VUE_APP_RESOURCES_URL
},
$deviceType() {
return deviceType
},
},
})
store.commit('updateDevicetype', deviceType)
app.$mount()