@ -4,17 +4,14 @@
* user : sa0ChunLuyu
* date : 2024 年8月7日 20 : 05 : 05
* /
import {
ref
} from 'vue'
import {
$api ,
$response ,
$response ,
} from '@/api'
import {
onShow ,
on Hide ,
on Load, on Error
on Load ,
on Error
} from '@dcloudio/uni-app'
import {
@ -22,99 +19,201 @@
} from '@/store'
const $store = useStore ( )
/ / 初 始 化 错 误 上 报
try {
if ( typeof uni . $lu !== 'undefined' && uni . $lu . errorReport ) {
/ / 初 始 化 全 局 错 误 捕 获
uni . $lu . errorReport . initErrorHandler ( )
console . log ( '[错误上报] 已初始化' )
/ / 处 理 早 期 错 误 缓 冲 区 ( i n d e x . h t m l 中 捕 获 的 错 误 )
if ( typeof window . flushErrorBuffer === 'function' ) {
try {
var earlyErrors = window . flushErrorBuffer ( )
if ( earlyErrors && earlyErrors . length > 0 ) {
console . log ( '[错误上报] 早期错误数量:' , earlyErrors . length )
/ / 重 新 上 报 早 期 错 误
earlyErrors . forEach ( function ( err ) {
try {
uni . $lu . errorReport . reportError ( err , 'early-error' )
} catch ( e ) {
console . warn ( '[错误上报] 重新上报早期错误失败' , e )
}
} )
}
} catch ( e ) {
console . warn ( '[错误上报] 处理早期错误缓冲区失败' , e )
}
}
}
} catch ( e ) {
console . warn ( '[错误上报] 初始化失败' , e )
}
const setConfigStore = ( ) => {
let config = { }
try {
const config _str = uni . getStorageSync ( 'CONFIG_CONFIG' )
if ( config _str ) config = JSON . parse ( config _str )
} catch ( e ) {
uni . showToast ( {
icon : "none" ,
title : e . message || '解析配置失败'
} )
console . warn ( 'CONFIG_CONFIG 解析失败' , e )
console . warn ( 'CONFIG_CONFIG 解析失败' , e )
}
$store . config = config
if ( ! config . color ) {
document . body . classList . toggle ( 'grayscale' ) ;
try {
/ / 安 全 检 查 : 确 保 d o c u m e n t . b o d y 存 在
if ( document && document . body && ! config . color ) {
document . body . classList . toggle ( 'grayscale' ) ;
}
} catch ( e ) {
console . warn ( '设置样式失败' , e )
}
let openid _str = ''
try {
openid _str = uni . getStorageSync ( 'OPENID' )
} catch ( e ) {
console . warn ( '获取 OPENID 失败' , e )
}
let url = ''
try {
url = window . location . href
} catch ( e ) {
console . warn ( '获取 URL 失败' , e )
}
const openid _str = uni . getStorageSync ( 'OPENID' )
let url = window . location . href
if ( ! openid _str ) {
if ( url . indexOf ( '/pages/main/login/login' ) === - 1 ) {
if ( url && url . indexOf ( '/pages/main/login/login' ) === - 1 ) {
uni . redirectTo ( {
url : '/pages/main/login/login'
} )
}
}
const save _info _str = uni . getStorageSync ( 'SAVE_INFO' )
if ( ! ! save _info _str ) {
$store . save _info = JSON . parse ( save _info _str )
} else {
try {
const save _info _str = uni . getStorageSync ( 'SAVE_INFO' )
if ( ! ! save _info _str ) {
$store . save _info = JSON . parse ( save _info _str )
} else {
$store . resetSaveInfo ( )
}
} catch ( e ) {
console . warn ( '解析 SAVE_INFO 失败' , e )
$store . resetSaveInfo ( )
}
}
const getConfigConfig = async ( ) => {
const response = await $api ( 'ConfigConfig' )
$response ( response , ( ) => {
uni . setStorageSync ( 'CONFIG_CONFIG' , JSON . stringify ( response . data . config ) )
setConfigStore ( )
} )
try {
const response = await $api ( 'ConfigConfig' )
$response ( response , ( ) => {
try {
uni . setStorageSync ( 'CONFIG_CONFIG' , JSON . stringify ( response . data . config ) )
setConfigStore ( )
} catch ( e ) {
console . error ( '保存配置失败' , e )
}
} )
} catch ( e ) {
console . error ( '获取配置接口失败' , e )
}
}
const getConfigVersion = async ( ) => {
const response = await $api ( 'ConfigVersion' )
$response ( response , ( ) => {
const config _version = uni . getStorageSync ( 'CONFIG_VERSION' )
let get _config = false
if ( ! config _version ) {
get _config = true
} else {
if ( config _version !== response . data . version ) {
get _config = true
try {
const response = await $api ( 'ConfigVersion' )
$response ( response , ( ) => {
try {
const config _version = uni . getStorageSync ( 'CONFIG_VERSION' )
let get _config = false
if ( ! config _version ) {
get _config = true
} else {
if ( config _version !== response . data . version ) {
get _config = true
}
}
uni . setStorageSync ( 'CONFIG_VERSION' , response . data . version )
/ / i f ( ! ! g e t _ c o n f i g ) {
if ( true ) {
getConfigConfig ( )
} else {
setConfigStore ( )
}
} catch ( e ) {
console . error ( '处理版本配置失败' , e )
}
}
uni . setStorageSync ( 'CONFIG_VERSION' , response . data . version )
/ / i f ( ! ! g e t _ c o n f i g ) {
if ( true ) {
getConfigConfig ( )
} )
} catch ( e ) {
console . error ( '获取版本接口失败' , e )
}
}
const handleFontSize = ( ) => {
try {
/ / 设 置 网 页 字 体 为 默 认 大 小
WeixinJSBridge . invoke ( 'setFontSizeCallback' , {
'fontSize' : 0
} ) ;
/ / 重 写 设 置 网 页 字 体 大 小 的 事 件
WeixinJSBridge . on ( 'menu:setfont' , function ( ) {
WeixinJSBridge . invoke ( 'setFontSizeCallback' , {
'fontSize' : 0
} ) ;
} ) ;
} catch ( e ) {
console . warn ( '设置字体大小失败' , e )
}
}
onShow ( ( ) => {
try {
if ( typeof WeixinJSBridge == "object" && typeof WeixinJSBridge . invoke == "function" ) {
handleFontSize ( ) ;
} else {
setConfigStore ( )
try {
if ( document && document . addEventListener ) {
document . addEventListener ( "WeixinJSBridgeReady" , handleFontSize , false ) ;
} else if ( document && document . attachEvent ) {
document . attachEvent ( "WeixinJSBridgeReady" , handleFontSize ) ;
document . attachEvent ( "onWeixinJSBridgeReady" , handleFontSize ) ;
}
} catch ( e ) {
console . warn ( '监听 WeixinJSBridge 失败' , e )
}
}
} )
}
const handleFontSize = ( ) => {
/ / 设 置 网 页 字 体 为 默 认 大 小
WeixinJSBridge . invoke ( 'setFontSizeCallback' , {
'fontSize' : 0
} ) ;
/ / 重 写 设 置 网 页 字 体 大 小 的 事 件
WeixinJSBridge . on ( 'menu:setfont' , function ( ) {
WeixinJSBridge . invoke ( 'setFontSizeCallback' , {
'fontSize' : 0
} ) ;
} ) ;
}
onShow ( ( ) => {
if ( typeof WeixinJSBridge == "object" && typeof WeixinJSBridge . invoke == "function" ) {
handleFontSize ( ) ;
} else {
if ( document . addEventListener ) {
document . addEventListener ( "WeixinJSBridgeReady" , handleFontSize , false ) ;
} else if ( document . attachEvent ) {
document . attachEvent ( "WeixinJSBridgeReady" , handleFontSize ) ;
document . attachEvent ( "onWeixinJSBridgeReady" , handleFontSize ) ;
}
}
} catch ( e ) {
console . warn ( 'onShow 初始化失败' , e )
}
console . log ( ` \ n %c 鹿和 %c https://sa0.online/ \ n \ n ` , 'color: #ffffff; background: #fd6b60; padding:5px 0;' ,
'color: #fd6b60;background: #ffffff; padding:5px 0;' )
getConfigVersion ( )
try {
getConfigVersion ( )
} catch ( e ) {
console . error ( '获取配置版本失败' , e )
}
} )
onError ( ( err ) => {
console . error ( '[全局错误]' , err )
/ / i O S W e b V i e w 特 殊 处 理 : 强 制 清 理 可 能 阻 塞 的 l o a d i n g
const isIOS = /iPhone|iPad|iPod/ . test ( navigator . userAgent )
if ( isIOS ) {
try {
uni . hideLoading ( )
console . log ( '[iOS清理] 强制关闭loading' )
} catch ( e ) {
console . warn ( '[iOS清理loading失败]' , e )
}
}
/ / 上 报 错 误
try {
if ( typeof uni . $lu !== 'undefined' && uni . $lu . errorReport ) {
uni . $lu . errorReport . reportError ( err , 'uni-app-error' )
}
} catch ( e ) {
console . warn ( '[错误上报] 上报失败' , e )
}
} )
onLoad ( ( ) => {
} )
< / script >