2024-06-03 09:11:28 +00:00
import { isInSSRComponentSetup , injectHook , getCurrentInstance , ref , openBlock , createElementBlock , createElementVNode , unref } from "vue" ;
const ON _SHOW = "onShow" ;
const ON _HIDE = "onHide" ;
2024-04-11 06:31:44 +00:00
function formatAppLog ( type , filename , ... args ) {
if ( uni . _ _log _ _ ) {
uni . _ _log _ _ ( type , filename , ... args ) ;
} else {
console [ type ] . apply ( console , [ ... args , filename ] ) ;
}
}
2024-06-03 09:11:28 +00:00
const createHook = ( lifecycle ) => ( hook , target = getCurrentInstance ( ) ) => {
! isInSSRComponentSetup && injectHook ( lifecycle , hook , target ) ;
} ;
const onShow = /* @__PURE__ */ createHook ( ON _SHOW ) ;
const onHide = /* @__PURE__ */ createHook ( ON _HIDE ) ;
2024-04-12 08:30:22 +00:00
const env = "dev" ;
const configs = {
dev : {
apiBaseUrl : "https://warehouse.szjixun.cn/oa_backend" ,
2024-06-03 09:11:28 +00:00
h5Url : "http://192.168.0.191:8080/#/"
2024-04-12 08:30:22 +00:00
} ,
test : {
apiBaseUrl : "https://warehouse.szjixun.cn/oa_backend" ,
2024-06-03 09:11:28 +00:00
h5Url : "http://114.218.158.24:9051/#/"
2024-04-12 08:30:22 +00:00
} ,
prod : {
2024-06-03 09:11:28 +00:00
apiBaseUrl : "https://oa- a.szjixun.cn/#/" ,
h5Url : "https://oa-a.szjixun.cn/#/"
2024-04-12 08:30:22 +00:00
}
} ;
const config = configs [ env ] ;
2024-04-11 06:31:44 +00:00
const sendWebWiew = ( refValue , paramValue , callName = "onReceive" ) => {
if ( ! refValue ) {
formatAppLog ( "error" , "at utils/communicate/index.js:3" , "evalJs: The reference to the webview is not provided or is null." ) ;
return ;
}
if ( typeof refValue . evalJs !== "function" ) {
formatAppLog ( "error" , "at utils/communicate/index.js:8" , "evalJs: The evalJs method is not available on the provided reference." ) ;
return ;
}
try {
const jsonString = JSON . stringify ( paramValue ) ;
const jsCode = ` window. ${ callName } ( ${ jsonString } ) ` ;
refValue . evalJs ( jsCode ) ;
} catch ( error ) {
formatAppLog ( "error" , "at utils/communicate/index.js:18" , "evalJs: An error occurred while trying to stringify the parameter value or while invoking evalJs." , error ) ;
}
} ;
const receiveWebView = ( e ) => {
return e . detail . data [ 0 ] ;
} ;
2024-06-03 09:11:28 +00:00
uni ;
2024-04-11 06:31:44 +00:00
const _sfc _main = {
_ _name : "index" ,
setup ( _ _props ) {
const webViewRef = ref ( null ) ;
2024-06-03 09:11:28 +00:00
uni . getSystemInfoSync ( ) ;
const networkStatusChange = ( res ) => {
if ( res . isConnected ) {
uni . redirectTo ( {
url : "/pages/index/index"
} ) ;
} else {
uni . showToast ( {
title : "网络无连接" ,
icon : "none"
} ) ;
}
} ;
const handleBackButton = ( ) => {
sendWebWiew ( webViewRef . value , { turnBack : 1 } ) ;
} ;
onShow ( ( ) => {
plus . key . addEventListener ( "backbutton" , handleBackButton , false ) ;
uni . onNetworkStatusChange ( networkStatusChange ) ;
} ) ;
onHide ( ( ) => {
plus . key . removeEventListener ( "backbutton" , handleBackButton , false ) ;
uni . offNetworkStatusChange ( networkStatusChange ) ;
} ) ;
2024-04-11 06:31:44 +00:00
const webLoad = ( e ) => {
const m = receiveWebView ( e ) ;
switch ( m . action ) {
case "load-complete" : {
2024-06-03 09:11:28 +00:00
const systemInfo = uni . getSystemInfoSync ( ) ;
2024-04-11 06:31:44 +00:00
uni . getLocation ( {
type : "gcj02" ,
geocode : false ,
isHighAccuracy : false ,
success : async ( res ) => {
2024-06-03 09:11:28 +00:00
sendWebWiew ( webViewRef . value , {
... res ,
systemInfo ,
webViewRef : webViewRef . value ,
"latitude" : 31.386561 ,
"longitude" : 120.660274
} ) ;
2024-04-11 06:31:44 +00:00
} ,
fail : ( e2 ) => {
2024-06-03 09:11:28 +00:00
formatAppLog ( "log" , "at pages/index/index.nvue:89" , e2 ) ;
2024-04-11 06:31:44 +00:00
}
} ) ;
}
}
} ;
return ( _ctx , _cache ) => {
return openBlock ( ) , createElementBlock ( "scroll-view" , {
scrollY : true ,
showScrollbar : true ,
enableBackToTop : true ,
bubble : "true" ,
style : { flexDirection : "column" }
} , [
2024-06-03 09:11:28 +00:00
createElementVNode ( "u-web-view" , {
class : "webview" ,
"on:onPostMessage" : webLoad ,
style : { "flex" : "1" } ,
ref _key : "webViewRef" ,
ref : webViewRef ,
src : unref ( config ) . h5Url
} , null , 40 , [ "src" ] )
2024-04-11 06:31:44 +00:00
] ) ;
} ;
}
} ;
export {
2024-06-03 09:11:28 +00:00
_sfc _main as default
2024-04-11 06:31:44 +00:00
} ;