Dining_Hall/pages/yjCanteen.vue

122 lines
3.4 KiB
Vue
Raw Normal View History

2025-06-10 10:54:00 +08:00
<template>
<view>
2025-07-11 14:41:52 +08:00
<web-view id="webviewId" :update-title="false" :webview-styles="webviewStyles" @message="getMessage"
:src="webViewSrc" style="height: 100%;" ref="webView"></web-view>
2025-06-10 10:54:00 +08:00
</view>
</template>
<script>
import {
getToken
} from '@/utils/auth';
2025-07-11 14:41:52 +08:00
import Cookies from "js-cookie";
2025-06-10 10:54:00 +08:00
// import '@/utils/webview.js'
let wv // 计划创建的webview
export default {
data() {
return {
webViewHeight: 0,
webviewStyles: {
top: "30px",
},
phoneNumber: uni.getStorageSync('mobile'),
token: getToken(),
webView: null
};
},
computed: {
webViewSrc() {
2025-06-11 13:08:35 +08:00
// return `/SDT_ZHST_APP?token=${this.token}`;//本地
//return `../../static/yjCanteen/SDT_ZHST_APP?token=${uni.getStorageSync('token')}`;//本地
// return `/canteen/SDT_ZHST_APP?token=${uni.getStorageSync('token')}`;//本地
2025-07-11 14:41:52 +08:00
const token = uni.getStorageSync('token');
const mobile = uni.getStorageSync('mobile');
const origin = location.origin;
console.log(origin)
2025-07-22 13:14:39 +08:00
return `${origin}/SDT_ZHST_APP/index.html?token=${token}`;
2025-06-10 10:54:00 +08:00
}
},
onReady() {
// #ifdef APP-PLUS
const currentWebview = this.$scope.$getAppWebview() // 获取当前页面的webview对象
2025-07-11 14:41:52 +08:00
setTimeout(() => {
2025-06-10 10:54:00 +08:00
this.webView = currentWebview.children()[0]
this.webView.setStyle({
scalable: true
})
}, 1000); // 如果是页面初始化调用时,需要延时一下
// #endif
window.addEventListener("message", this.getMessage);
2025-07-11 14:41:52 +08:00
// 解决 iOS 下键盘收起页面不回弹
//window.addEventListener('focusout', () => {
// if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
// // 触发一次滚动,让页面回弹
// window.scrollTo(0, 0);
// uni.$u.toast('userAgent')
// }
//});
2025-06-10 10:54:00 +08:00
},
methods: {
getMessage(event) { //在H5端使用通信返回App端
console.log(event, '0000000000000000000000000')
if (event.data.data.arg.action == 'stage_navigateBack') {
uni.reLaunch({
url: '/pages/system'
});
2025-07-11 14:41:52 +08:00
} else if (event.data.data.arg.action == 'logOut') {
2025-06-12 17:33:26 +08:00
// uni.reLaunch({
// url: '/pages/login'
// });
this.$store.dispatch('LogOut').then(() => {
uni.removeStorageSync('token')
Cookies.remove('token')
2025-07-11 14:41:52 +08:00
uni.reLaunch({
url: '/pages/login'
})
2025-06-12 17:33:26 +08:00
})
2025-07-11 14:41:52 +08:00
} else if (event.data.data.arg.action == 'sbdCanteen') { // 跳转到sbd食堂s
2025-06-11 13:08:35 +08:00
// uni.reLaunch({
// url: '/pages/index' // 测试
// });
2025-07-11 14:41:52 +08:00
this.$router.push({
path: '/pages/index'
})
2025-06-10 10:54:00 +08:00
}
2025-07-22 13:14:39 +08:00
// else if (event.data.data.arg.action == 'keyboard-blur') { // 跳转到sbd食堂
// console.log('触发一次滚动,让页面回弹')
// 等键盘真正收起后,再触发回滚
// setTimeout(() => {
// if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
// // 触发一次滚动,让页面回弹
// // window.scrollTo(0, 0);
// console.log('触发一次滚动让页面回弹2')
// uni.pageScrollTo({
// scrollTop: 0,
// duration: 100
// });
//
// // 强制刷新 DOM
// //document.body.style.display = 'none';
// //setTimeout(() => {
// // console.log('强制刷新 DOM')
// // document.body.style.display = '';
// //}, 50);
// }
// }, 100);
// }
2025-06-10 10:54:00 +08:00
}
},
mounted() {
window.onQrScanSuccess = (result) => {
return onQrScanSuccess(result);
}
2025-07-11 14:41:52 +08:00
}
2025-06-10 10:54:00 +08:00
};
</script>
<style lang="scss" scoped>
page {
background: #fff;
}
2025-07-11 14:41:52 +08:00
</style>