Files
PartsInquiry/frontend/main.js
2025-09-21 16:01:59 +08:00

67 lines
1.9 KiB
JavaScript
Raw 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 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