You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
4.1 KiB
160 lines
4.1 KiB
<template>
|
|
<web-view :src="url"></web-view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
url: '',
|
|
saveUrl: '',
|
|
}
|
|
},
|
|
onLoad(option) {
|
|
// if (option.url) {
|
|
// try {
|
|
// this.url = decodeURIComponent(option.url);
|
|
// } catch (error) {
|
|
// console.error('URL解码出错:', error);
|
|
// this.url = uni.getStorageSync('webUrl');
|
|
// }
|
|
// } else {
|
|
// this.url = uni.getStorageSync('webUrl');
|
|
// }
|
|
// return;
|
|
|
|
let url = ''
|
|
let that = this
|
|
if (option.url) {
|
|
url = decodeURIComponent(option.url)
|
|
}else{
|
|
url = decodeURIComponent(uni.getStorageSync('webUrl'))
|
|
}
|
|
|
|
if (url.toLowerCase().indexOf('m.cloud.sz-trip.com')>=0) {
|
|
this.handleJDSZ(url)
|
|
setTimeout(()=>{
|
|
that.saveUrl = url
|
|
},500)
|
|
} else {
|
|
this.url = url
|
|
this.saveUrl = url
|
|
}
|
|
|
|
console.log(this.url, 'onload')
|
|
// 传入需要跳转的链接 使用web-view标签进行跳转
|
|
},
|
|
onShow() {
|
|
console.log(this.url, this.saveUrl, 'onshow')
|
|
if (!this.url && this.saveUrl) {
|
|
let param = this.getUrlParam(this.saveUrl)
|
|
console.log(param)
|
|
this.checkIsLoginJdsz().then(res => {
|
|
if(res) {
|
|
param.token = res
|
|
param.platform = 'changshu'
|
|
let baseUrl = param.tempUrl
|
|
let queryString = Object.entries(param).filter(v=>v[0]!='tempUrl')
|
|
.map(([key, value]) => `${(key)}=${(value)}`)
|
|
.join('&');
|
|
|
|
let location = uni.getStorageSync('location')
|
|
if (location) {
|
|
queryString+=`&lon=${location.lon}&lat=${location.lat}`
|
|
let fullUrl = `${baseUrl}?${queryString}`;
|
|
console.log(fullUrl);
|
|
this.url = fullUrl
|
|
} else {
|
|
uni.getLocation({
|
|
success: data => {
|
|
uni.setStorageSync('location', {
|
|
lat: data.latitude,
|
|
lon: data.longitude
|
|
});
|
|
queryString+=`&lon=${data.longitude}&lat=${data.latitude}`
|
|
let fullUrl = `${baseUrl}?${queryString}`;
|
|
console.log(fullUrl);
|
|
this.url = fullUrl
|
|
|
|
},
|
|
fail: res=> {
|
|
let fullUrl = `${baseUrl}?${queryString}`;
|
|
console.log(fullUrl, '获取定位失败', res);
|
|
this.url = fullUrl
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
}
|
|
})
|
|
}
|
|
},
|
|
methods: {
|
|
handleJDSZ (url) {
|
|
let param = this.getUrlParam(url)
|
|
console.log(param)
|
|
this.checkIsLoginJdsz().then(res => {
|
|
|
|
if(res) {
|
|
param.token = res
|
|
param.platform = 'changshu'
|
|
let baseUrl = param.tempUrl
|
|
let queryString = Object.entries(param).filter(v=>v[0]!='tempUrl')
|
|
.map(([key, value]) => `${(key)}=${(value)}`)
|
|
.join('&');
|
|
|
|
let location = uni.getStorageSync('location')
|
|
if (location) {
|
|
queryString+=`&lon=${location.lon}&lat=${location.lat}`
|
|
let fullUrl = `${baseUrl}?${queryString}`;
|
|
console.log(fullUrl);
|
|
this.url = fullUrl
|
|
} else {
|
|
uni.getLocation({
|
|
success: data => {
|
|
uni.setStorageSync('location', {
|
|
lat: data.latitude,
|
|
lon: data.longitude
|
|
});
|
|
queryString+=`&lon=${data.longitude}&lat=${data.latitude}`
|
|
let fullUrl = `${baseUrl}?${queryString}`;
|
|
console.log(fullUrl);
|
|
this.url = fullUrl
|
|
|
|
},
|
|
fail: res=> {
|
|
let fullUrl = `${baseUrl}?${queryString}`;
|
|
console.log(fullUrl, '获取定位失败', res);
|
|
this.url = fullUrl
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
}).finally(()=>{
|
|
this.saveUrl = url
|
|
})
|
|
|
|
},
|
|
getUrlParam(url) {
|
|
var theParam = {tempUrl: url};
|
|
let searchStartIndex = url.indexOf("?")
|
|
if (searchStartIndex>=0) {
|
|
theParam.tempUrl = url.substring(0,searchStartIndex);
|
|
var strs = url.substring(searchStartIndex+1);
|
|
strs = strs.split("&"); //将获取到的字符串从&分割,输出参数数组,即输出[参数1=xx,参数2=xx,参数3=xx,...]的数组形式
|
|
for(var i = 0; i < strs.length; i ++) { //遍历参数数组
|
|
theParam[strs[i].split("=")[0]]=decodeURIComponent(strs[i].split("=")[1]);
|
|
}
|
|
}
|
|
return theParam; //返回参数值
|
|
}
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|
|
|