<template>
|
<view>
|
<web-view :webview-styles="webviewStyles" :src="webviewUrl" @message='received'></web-view>
|
</view>
|
</template>
|
|
<script>
|
var wv
|
export default {
|
data() {
|
return {
|
webviewUrl: '',
|
webviewStyles: {
|
progress: {
|
color: '#EE1B14'
|
}
|
},
|
}
|
},
|
onLoad(options) {
|
if(!this.hasLogin){
|
uni.reLaunch({
|
url:"/pages/login/wxlogin"
|
})
|
}
|
else{
|
const value = uni.getStorageSync('userInfo');
|
console.log(value);
|
if(options.t_url)
|
{
|
this.webviewUrl = encodeURI(decodeURIComponent(options.t_url)+"?token="+value.token+"&userid="+value.id);
|
}
|
}
|
|
},
|
onReady() {
|
this.clearMuiBack();
|
},
|
methods: {
|
received(e) {
|
console.log(e);
|
var res=e.detail.data[0];
|
if(res.action=='target_tb')
|
{
|
this.getTbsrc(res.data.goodsId);
|
}
|
},
|
//跳转淘宝
|
getTbsrc(goodsid) {
|
var that = this;
|
this.$u.api.getPrivilegeLink({
|
goodsId: goodsid,
|
type: 0
|
}).then(e => {
|
console.log(e);
|
if (e.code != 0) return that.$alert(e.msg)
|
var res = e.data.info;
|
var tburl = res.shortUrl
|
// #ifdef APP-PLUS
|
if (plus.runtime.isApplicationExist({
|
pname: 'com.taobao.taobao',
|
action: 'taobao://'
|
})) {
|
const plug = uni.requireNativePlugin('xiguazhu-baichuan')
|
plug.detailPage({
|
url: tburl,
|
"openType": 0
|
}, result => {
|
// console.log(result);
|
});
|
} else {
|
uni.navigateTo({
|
url: '../webView/webView?url=' + tburl
|
})
|
}
|
// #endif
|
}).catch(function(err) {})
|
},
|
// 关闭mui返回
|
clearMuiBack() {
|
// #ifdef APP-PLUS
|
var currentWebview = this.$scope.$getAppWebview().children()[0];
|
//监听注入的js
|
currentWebview.addEventListener("loaded", function() {
|
currentWebview.evalJS("mui.init({keyEventBind: {backbutton: false }});");
|
});
|
// #endif
|
},
|
|
},
|
onNavigationBarButtonTap(e) {
|
// #ifdef APP-PLUS
|
const currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
|
var wv = currentWebview.children()[0]
|
wv.reload();
|
// #endif
|
console.log(JSON.stringify(e))
|
},
|
}
|
</script>
|
|
<style>
|
|
</style>
|