129 lines
3.9 KiB
JavaScript
129 lines
3.9 KiB
JavaScript
import { isInSSRComponentSetup, injectHook, getCurrentInstance, ref, openBlock, createElementBlock, createElementVNode, unref } from "vue";
|
|
const ON_SHOW = "onShow";
|
|
const ON_HIDE = "onHide";
|
|
function formatAppLog(type, filename, ...args) {
|
|
if (uni.__log__) {
|
|
uni.__log__(type, filename, ...args);
|
|
} else {
|
|
console[type].apply(console, [...args, filename]);
|
|
}
|
|
}
|
|
const createHook = (lifecycle) => (hook, target = getCurrentInstance()) => {
|
|
!isInSSRComponentSetup && injectHook(lifecycle, hook, target);
|
|
};
|
|
const onShow = /* @__PURE__ */ createHook(ON_SHOW);
|
|
const onHide = /* @__PURE__ */ createHook(ON_HIDE);
|
|
const env = "dev";
|
|
const configs = {
|
|
dev: {
|
|
apiBaseUrl: "https://warehouse.szjixun.cn/oa_backend",
|
|
h5Url: "http://192.168.0.191:8080/#/"
|
|
},
|
|
test: {
|
|
apiBaseUrl: "https://warehouse.szjixun.cn/oa_backend",
|
|
h5Url: "http://114.218.158.24:9051/#/"
|
|
},
|
|
prod: {
|
|
apiBaseUrl: "https://oa- a.szjixun.cn/#/",
|
|
h5Url: "https://oa-a.szjixun.cn/#/"
|
|
}
|
|
};
|
|
const config = configs[env];
|
|
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];
|
|
};
|
|
uni;
|
|
const _sfc_main = {
|
|
__name: "index",
|
|
setup(__props) {
|
|
const webViewRef = ref(null);
|
|
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);
|
|
});
|
|
const webLoad = (e) => {
|
|
const m = receiveWebView(e);
|
|
switch (m.action) {
|
|
case "load-complete": {
|
|
const systemInfo = uni.getSystemInfoSync();
|
|
uni.getLocation({
|
|
type: "gcj02",
|
|
geocode: false,
|
|
isHighAccuracy: false,
|
|
success: async (res) => {
|
|
sendWebWiew(webViewRef.value, {
|
|
...res,
|
|
systemInfo,
|
|
webViewRef: webViewRef.value,
|
|
"latitude": 31.386561,
|
|
"longitude": 120.660274
|
|
});
|
|
},
|
|
fail: (e2) => {
|
|
formatAppLog("log", "at pages/index/index.nvue:89", e2);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
return (_ctx, _cache) => {
|
|
return openBlock(), createElementBlock("scroll-view", {
|
|
scrollY: true,
|
|
showScrollbar: true,
|
|
enableBackToTop: true,
|
|
bubble: "true",
|
|
style: { flexDirection: "column" }
|
|
}, [
|
|
createElementVNode("u-web-view", {
|
|
class: "webview",
|
|
"on:onPostMessage": webLoad,
|
|
style: { "flex": "1" },
|
|
ref_key: "webViewRef",
|
|
ref: webViewRef,
|
|
src: unref(config).h5Url
|
|
}, null, 40, ["src"])
|
|
]);
|
|
};
|
|
}
|
|
};
|
|
export {
|
|
_sfc_main as default
|
|
};
|