Dining_Hall/pages/yjCanteen.vue

122 lines
3.4 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<web-view id="webviewId" :update-title="false" :webview-styles="webviewStyles" @message="getMessage"
:src="webViewSrc" style="height: 100%;" ref="webView"></web-view>
</view>
</template>
<script>
import {
getToken
} from '@/utils/auth';
import Cookies from "js-cookie";
// 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() {
// 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')}`;//本地
const token = uni.getStorageSync('token');
const mobile = uni.getStorageSync('mobile');
const origin = location.origin;
console.log(origin)
return `${origin}/SDT_ZHST_APP/index.html?token=${token}`;
}
},
onReady() {
// #ifdef APP-PLUS
const currentWebview = this.$scope.$getAppWebview() // 获取当前页面的webview对象
setTimeout(() => {
this.webView = currentWebview.children()[0]
this.webView.setStyle({
scalable: true
})
}, 1000); // 如果是页面初始化调用时,需要延时一下
// #endif
window.addEventListener("message", this.getMessage);
// 解决 iOS 下键盘收起页面不回弹
//window.addEventListener('focusout', () => {
// if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
// // 触发一次滚动,让页面回弹
// window.scrollTo(0, 0);
// uni.$u.toast('userAgent')
// }
//});
},
methods: {
getMessage(event) { //在H5端使用通信返回App端
console.log(event, '0000000000000000000000000')
if (event.data.data.arg.action == 'stage_navigateBack') {
uni.reLaunch({
url: '/pages/system'
});
} else if (event.data.data.arg.action == 'logOut') {
// uni.reLaunch({
// url: '/pages/login'
// });
this.$store.dispatch('LogOut').then(() => {
uni.removeStorageSync('token')
Cookies.remove('token')
uni.reLaunch({
url: '/pages/login'
})
})
} else if (event.data.data.arg.action == 'sbdCanteen') { // 跳转到sbd食堂s
// uni.reLaunch({
// url: '/pages/index' // 测试
// });
this.$router.push({
path: '/pages/index'
})
}
// 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);
// }
}
},
mounted() {
window.onQrScanSuccess = (result) => {
return onQrScanSuccess(result);
}
}
};
</script>
<style lang="scss" scoped>
page {
background: #fff;
}
</style>