提交 3fb43ac1 编写于 作者: tao.wu's avatar tao.wu

优化头部组件入参以及事件

上级 62688c07
...@@ -18,17 +18,30 @@ ...@@ -18,17 +18,30 @@
export default { export default {
name: 'h5header', name: 'h5header',
props: { props: {
scrollVal: { scrollVal: { // 实际滚动的距离
type: Number, type: Number,
default: 0 default: 25
}, },
title: { title: { // 头部 title
type: String, type: String,
default: '云鹊医-赋能基层医生' default: '云鹊医-赋能基层医生'
}, },
shareObj: { shareObj: { // 分享的参数
type: Object, type: Object,
default: {} default: {
shareUrl:'',
title1:'',
title2:'',
shareImageUrl:'',
}
},
baseShowHeight: { // 需要进行滚动交互的阈值
type: Number,
default: 25,
} ,
setedScroll: { // 如果外部组件设置了onscroll监听,则要设置为true,否则会被头部组件的onsrcoll覆盖!!!
type: Boolean,
default: false
} }
}, },
data(){ data(){
...@@ -36,40 +49,68 @@ ...@@ -36,40 +49,68 @@
leftIcon: leftimg1, leftIcon: leftimg1,
rightIcon: rightimg1, rightIcon: rightimg1,
isScroll: false, isScroll: false,
statusBarHeight: 40, // 给一个默认值,20 * 2 statusBarHeight: 20, // 给一个默认值,20 * 2
titleHeight: 44 // title高度默认是44px titleHeight: 44 // title高度默认是44px
} }
}, },
mounted(){ mounted(){
this.$rocNative.getStatusBarHeight().then(res=>{ this.setHeaderHeight();
const dpr = window.devicePixelRatio; if(!this.setedScroll){
if(this.$rocNative.isIOS){ this.scrollHandleOwn();
this.statusBarHeight = res.statusBarHeight * dpr; }
this.titleHeight = this.titleHeight * dpr;
}else{
this.statusBarHeight = res.statusBarHeight / dpr;
}
})
}, },
watch: { watch: {
scrollVal(val){ scrollVal(val){
if (val > 25) { this.setScrollHandle(val);
this.isScroll = true;
this.leftIcon = leftimg2;
this.rightIcon = rightimg2;
} else {
this.isScroll = false;
this.leftIcon = leftimg1;
this.rightIcon = rightimg1;
}
} }
}, },
methods: { methods: {
// 从APP获取电池栏高度并设置高度
setHeaderHeight(){
this.statusBarHeight = 20 * window.devicePixelRatio; // 给一个默认值,20 * 2
this.titleHeight = 44 * window.devicePixelRatio; // title高度默认是44px
this.$rocNative.getStatusBarHeight().then(res=>{
const dpr = window.devicePixelRatio;
if(this.$rocNative.isIOS){
this.statusBarHeight = res.statusBarHeight * dpr;
this.titleHeight = this.titleHeight * dpr;
}else{
this.statusBarHeight = res.statusBarHeight / dpr;
}
})
},
goBack(){ goBack(){
this.$rocNative.goBack(); this.$rocNative.goBack();
}, },
goShare(){ goShare(){
this.$rocNative.shareWechat(this.shareObj); this.$rocNative.shareWechat(this.shareObj);
},
// 默认滚动事件
scrollHandleOwn(){
let bodyScrollTop = 0, documentScrollTop = 0;
window.onscroll = () => {
if(document.body){
bodyScrollTop = document.body.scrollTop;
}
if(document.documentElement){
documentScrollTop = document.documentElement.scrollTop;
}
const heightVal = imgHeight1 + imgHeight2 + imgHeight3;
const scrollVal = bodyScrollTop || documentScrollTop;
this.setScrollHandle(scrollVal);
}
},
// 交互事件
setScrollHandle(instval){
if (instval >= this.baseShowHeight) {
this.isScroll = true;
this.leftIcon = leftimg2;
this.rightIcon = rightimg2;
} else {
this.isScroll = false;
this.leftIcon = leftimg1;
this.rightIcon = rightimg1;
}
} }
} }
} }
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
<h5header v-if="!isWeb" <h5header v-if="!isWeb"
:scrollVal="scrollVal" :scrollVal="scrollVal"
title="云鹊奖" title="云鹊奖"
:baseShowHeight="25"
:shareObj="shareObj" :shareObj="shareObj"
:setedScroll="true"
/> />
<div id="imgHeight1"> <div id="imgHeight1">
<img src="../assets/img/img1.png" /> <img src="../assets/img/img1.png" />
...@@ -79,18 +81,6 @@ export default { ...@@ -79,18 +81,6 @@ export default {
}, },
components: { components: {
h5header h5header
},
asyncData(params){
return {
shareObj: {
shareUrl: 'http://' + params.req.host + params.req.originalUrl,
title1: '年终活动-标题',
title2: '年终活动-文字描述',
shareImageUrl: 'https://test-file.yunqueyi.com/png/2019/11/18/1574046505000_48x48.png'
}
}
}, },
data() { data() {
return { return {
...@@ -100,20 +90,26 @@ export default { ...@@ -100,20 +90,26 @@ export default {
hospitalIdCnt: '', hospitalIdCnt: '',
scrollVal: 0, scrollVal: 0,
isWeb: false, isWeb: false,
shareObj: {}
} }
}, },
created(){ created(){
// window.__refresh = function() {
// window.reolad();
// };
getCnt().then(res=>{ getCnt().then(res=>{
if(res.code=='000000'){ if(res.code=='000000'){
this.doctorIdCnt = res.data.doctorIdCnt; this.doctorIdCnt = res.data.doctorIdCnt;
this.hospitalIdCnt = res.data.hospitalIdCnt; this.hospitalIdCnt = res.data.hospitalIdCnt;
}else{
this.$toast(res.message)
} }
}); });
}, },
mounted() { mounted() {
this.shareObj = {
shareUrl: window.location.href,
title1: '年终活动-标题',
title2: '年终活动-文字描述',
shareImageUrl: 'https://test-file.yunqueyi.com/png/2019/11/18/1574046505000_48x48.png'
}
this.isWeb = this.$rocNative.isWeb; this.isWeb = this.$rocNative.isWeb;
this.$rocNative.getToken().then(res => { this.$rocNative.getToken().then(res => {
const { userToken } = res; const { userToken } = res;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册