addnetconfirm

This commit is contained in:
scout 2024-10-28 15:31:46 +08:00
parent a7bc5506de
commit 951aabfe55
3 changed files with 137 additions and 96 deletions

38
App.vue
View File

@ -1,22 +1,58 @@
<script> <script>
export default { export default {
data() {
return {
//
lastNetworkStatus: null
}
},
methods: { methods: {
// APP
isFirstOpen(){
let isFirstOpen = uni.getStorageSync('isFirstOpen')
if (!isFirstOpen) {
uni.setStorageSync('isFirstOpen', true)
return true
}
return false
},
networkStatusChange(res) { networkStatusChange(res) {
if (res.isConnected) { if (res.isConnected) {
//
if (this.isFirstOpen()) {
uni.redirectTo({ uni.redirectTo({
url: '/pages/index/index' url: '/pages/index/index'
}) })
}
//
if (this.lastNetworkStatus === false) {
uni.showModal({
title: "提示",
content: "当前设备网络发生更改,是否刷新页面?",
success: function (res) {
if (res.confirm) {
uni.redirectTo({
url: '/pages/index/index'
})
} else if (res.cancel) {
}
},
});
}
} else { } else {
uni.redirectTo({ uni.redirectTo({
url: '/pages/networko/index' url: '/pages/networko/index'
}) })
} }
this.lastNetworkStatus = res.isConnected
} }
}, },
onLaunch: function () { onLaunch: function () {
}, },
onShow: function () { onShow: function () {
uni.onNetworkStatusChange(this.networkStatusChange);
uni.getNetworkType({ uni.getNetworkType({
success: (res) => { success: (res) => {
if (res.networkType === 'none') { if (res.networkType === 'none') {
@ -27,7 +63,7 @@
} }
} }
}) })
uni.onNetworkStatusChange(this.networkStatusChange);
}, },
onHide: function () { onHide: function () {
uni.offNetworkStatusChange(this.networkStatusChange) uni.offNetworkStatusChange(this.networkStatusChange)

View File

@ -2,7 +2,7 @@ const env = 'prod';
const configs = { const configs = {
LocalTest: { LocalTest: {
apiBaseUrl: 'https://warehouse.szjixun.cn/oa_backend', apiBaseUrl: 'https://warehouse.szjixun.cn/oa_backend',
h5Url:'http://192.168.88.29:8080/#/' h5Url:'http://192.168.88.30:8080/#/'
}, },
dev: { dev: {
apiBaseUrl: 'https://warehouse.szjixun.cn/oa_backend', apiBaseUrl: 'https://warehouse.szjixun.cn/oa_backend',

View File

@ -4,16 +4,23 @@
</template> </template>
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import {onExit } from "@dcloudio/uni-app"; import { onExit, onShow, onLoad } from "@dcloudio/uni-app";
import config from "../../config" import config from "../../config"
const wv = plus.webview.create(config.h5Url,"custom-webview") onShow(() => {
const { statusBarHeight } = uni.getSystemInfoSync()
const wv1 = plus.webview.getWebviewById("custom-webview");
let wv = null;
if (wv1) {
wv = wv1;
} else {
wv = plus.webview.create(config.h5Url, "custom-webview", {
top: statusBarHeight,
bottom: 0,
});
}
const currentPages = getCurrentPages() const currentPages = getCurrentPages()
const currentWebview = currentPages[currentPages.length - 1].$getAppWebview() const currentWebview = currentPages[currentPages.length - 1].$getAppWebview()
currentWebview.append(wv) currentWebview.append(wv)
const {statusBarHeight} = uni.getSystemInfoSync()
wv.setStyle({
top: statusBarHeight,
bottom: 0,
}) })
import { Communication } from '../../utils/communication.js'; import { Communication } from '../../utils/communication.js';
const commun = new Communication() const commun = new Communication()
@ -96,6 +103,4 @@ const webLoad = (e) => {
}; };
</script> </script>
<style> <style></style>
</style>