index.vue 2.27 KB
<template>
	<view>
		<!-- <view class="status_bar">
		</view> -->
		<view class="web-cont">
			<web-view :src="src" @message="onPostMessage"></web-view>
		</view>
	</view>
</template>

<script>
	var wv; //计划创建的webview
	export default {
		data() {
			return {
				url: "http://www.hotent.org:8480/mobilevue",
				uri: "/home"
			}
		},
		computed: {
			src: function(val) {
				return this.url + this.uri + "?token=" + uni.getStorageSync('token')||"";
			}
		},
		onReady() {
			// #ifdef APP-PLUS
			let statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			var currentWebview = this.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
			setTimeout(function() {
				wv = currentWebview.children()[0]
				wv && wv.setStyle({
					top: statusBarHeight,
					bottom: 0
				})
			}, 1000); //如果是页面初始化调用时,需要延时一下
			// #endif
		},
		onLoad() {
			//监听推送的消息
			let __this = this;
			console.log("============token================" + uni.getStorageSync('token'))
			plus.push.addEventListener('receive', function(d) {
				__this.jump(d.content);
			});
		},
		methods: {
			onPostMessage(event) {
				let data = event.detail.data[0];
				let action = data.action;
				switch (action) {
					case "login":
						this.saveToken(data.token);
						break;
					case "logout":
						uni.setStorageSync("token", "");
						break;
					default:
						break;
				}
				console.log(JSON.stringify(data))
			},
			jump(params) {
				let paramsJson = JSON.parse(params || "{}");
				//审批的消息
				let taskId = paramsJson.taskId;
				if (paramsJson.templateType === 'bpmnapproval') {
					this.uri = "/task/" + taskId + "/0";
				}
			},
			saveToken(token) {
				uni.setStorageSync("token", token);
				console.log("============saveToken================" + uni.getStorageSync('token'))
			}
		}
	}
</script>

<style>
	/* .content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
} */
	/* .status_bar {
      height: var(--status-bar-height);
      width: 100%;
	  background-color: #007AFF;
  }
.web-cont {
	margin-top: var(--status-bar-height);
} */
</style>