增加返回功能

This commit is contained in:
zpc 2025-06-25 16:52:20 +08:00
parent 37830158a0
commit 64c265692b

View File

@ -7,64 +7,84 @@
</template>
<script setup>
import {
ref
} from 'vue'
import {
onLoad
} from '@dcloudio/uni-app'
import {
platform
} from '@/common/platform/PlatformFactory';
import {
getPlatformConfig
} from '@/common/server/config';
let webview = ref(null);
let webviewurl = ref("");
import {
ref
} from 'vue'
import {
onLoad,
onBackPress
} from '@dcloudio/uni-app'
import {
platform
} from '@/common/platform/PlatformFactory';
import {
getPlatformConfig
} from '@/common/server/config';
let webview = ref(null);
let webviewurl = ref("");
getPlatformConfig().then(res => {
webviewurl.value = res.userAgreement;
});
const windowInfo = uni.getWindowInfo();
console.log(windowInfo);
let statusBarHeight = windowInfo.statusBarHeight + "px";
// webview向外部发送消息
const handlePostMessage = async (data) => {
console.log("接收到消息:", data, data.detail.data);
if (data.detail.data && data.detail.data[0]) {
let detailData = data.detail.data[0];
if (detailData.action == "pay") {
const res = await platform.pay(detailData.data);
evalJs({
action: "pay",
data: res.isPay,
callback: detailData.callback
});
getPlatformConfig().then(res => {
webviewurl.value = res.userAgreement;
});
const windowInfo = uni.getWindowInfo();
console.log(windowInfo);
let statusBarHeight = windowInfo.statusBarHeight + "px";
const thisPage = ref(null);
// webview向外部发送消息
const handlePostMessage = async (data) => {
console.log("接收到消息:", data, data.detail.data);
if (data.detail.data && data.detail.data[0]) {
let detailData = data.detail.data[0];
if (detailData.action == "pay") {
const res = await platform.pay(detailData.data);
evalJs({
action: "pay",
data: res.isPay,
callback: detailData.callback
});
} else if (detailData.action == "load") {
console.log("页面加载成功");
} else if (detailData.action == "pageUrl") {
console.log("页面跳转", detailData.data);
thisPage.value = detailData.data;
}
}
}
}
// 调用 webview 内部逻辑
const evalJs = (data) => {
let json = JSON.stringify(data || {});
console.log("yds_postMessage", json);
webview.value.evalJS("window.yds_postMessage('" + json + "')");
}
// 调用 webview 内部逻辑
const evalJs = (data) => {
let json = JSON.stringify(data || {});
console.log("yds_postMessage", json);
webview.value.evalJS("window.yds_postMessage('" + json + "')");
}
// 在 setup 中添加
onBackPress(() => {
console.log("thisPage.value", thisPage.value);
if (thisPage.value != null) {
if (thisPage.value.isHome) {
return false;
}
}
console.log('返回按钮被点击');
webview.value.evalJS("window.yds_backPress()");
return true;
})
</script>
<style>
.container {
flex: 1;
flex-direction: column;
/* 竖向排列 */
}
.container {
flex: 1;
flex-direction: column;
/* 竖向排列 */
}
.navbar {
height: 40px;
/* 导航栏高度 */
background-color: #fff;
}
.navbar {
height: 40px;
/* 导航栏高度 */
background-color: #fff;
}
.webview {
flex: 1;
/* 自动占满剩余空间 */
}
.webview {
flex: 1;
/* 自动占满剩余空间 */
}
</style>