index.vue
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<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>