67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
import App from './App'
|
||
|
||
// #ifndef VUE3
|
||
import Vue from 'vue'
|
||
import './uni.promisify.adaptor'
|
||
Vue.config.productionTip = false
|
||
App.mpType = 'app'
|
||
const app = new Vue({
|
||
...App
|
||
})
|
||
app.$mount()
|
||
// #endif
|
||
|
||
// #ifdef VUE3
|
||
import { createSSRApp } from 'vue'
|
||
export function createApp() {
|
||
const app = createSSRApp(App)
|
||
return {
|
||
app
|
||
}
|
||
}
|
||
// #endif
|
||
|
||
// 规范化 WebSocket 关闭码(仅微信小程序)
|
||
// #ifdef MP-WEIXIN
|
||
if (typeof uni !== 'undefined' && typeof uni.connectSocket === 'function') {
|
||
const _connectSocket = uni.connectSocket
|
||
uni.connectSocket = function(options) {
|
||
const task = _connectSocket.call(this, options)
|
||
if (task && typeof task.close === 'function') {
|
||
const _close = task.close
|
||
task.close = function(params = {}) {
|
||
if (params && typeof params === 'object') {
|
||
const codeNum = Number(params.code)
|
||
const isValid = codeNum === 1000 || (codeNum >= 3000 && codeNum <= 4999)
|
||
if (!isValid) {
|
||
params.code = 1000
|
||
if (!params.reason) params.reason = 'normalized from invalid close code'
|
||
}
|
||
}
|
||
return _close.call(this, params)
|
||
}
|
||
}
|
||
return task
|
||
}
|
||
}
|
||
// #endif
|
||
|
||
// 全局安全返回:首屏无法后退时自动回到首页 tab(微信小程序)
|
||
// #ifdef MP-WEIXIN
|
||
if (typeof uni !== 'undefined' && typeof uni.navigateBack === 'function') {
|
||
const _navigateBack = uni.navigateBack
|
||
uni.navigateBack = function(params = {}) {
|
||
try {
|
||
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : []
|
||
const maxDelta = pages.length > 0 ? (pages.length - 1) : 0
|
||
const d = Number(params.delta || 1)
|
||
if (maxDelta >= 1 && d <= maxDelta) {
|
||
return _navigateBack.call(this, params)
|
||
}
|
||
return uni.switchTab({ url: '/pages/index/index' })
|
||
} catch (e) {
|
||
return uni.switchTab({ url: '/pages/index/index' })
|
||
}
|
||
}
|
||
}
|
||
// #endif
|