Commit 72c9f770 authored by huangjie's avatar huangjie

*

parent 304f1c84
/*
*
* 1、url地址,如企业详情:https://pre-plug.jiansheku.com/enterprise?ak=aec7b3ff2y2q8x6t49a7e2c463ce21912&uid=a704fb35bca54707b9b5f8c9bba57815(ak:平台唯一标识;uid:用户标识)
* 1、url地址,如正式环境企业详情:https://plug.jiansheku.com/enterprise/56546856314e567a69?ak=bc8e534da5ea40639b2f084919280a82&initTime=1694507179060&uid=4a3b4bfdfbca4bff9d9bd7c8fd42f533(ak:接口获得的accesToken;initTime:获得accesToken时的时间戳;uid:用户标识)
*
* */
const steerScroll = function(iframeId, navigation, state, parentId) { // state:监听or移除监听;navigation:页面排除iframe后剩下高度;iframeId: iframe的id
const steerScroll = function(iframeId, navigation, footHeight, state, parentId, _this) { // iframeId: iframe的id;navigation:页面排除iframe后剩下的顶部高度;footHeight: 页面排除iframe后剩下的底部高度;state:监听or移除监听;parentId: 父级id[不带默认就是铺满整个页面]];_this:指向当前实例(可忽略)
let dom = window
if (parentId) { // 默认页面可以滚动
dom = document.getElementById(parentId)
......@@ -22,7 +22,12 @@ const steerScroll = function(iframeId, navigation, state, parentId) { // state:
// 动态设置iFrame高度
if (data.height) {
document.getElementById(iframeId).style.height = data.height + 'px'
scrolling(iframeId, navigation, parentId) // 初始加载获取滚动条距离顶部高度
scrolling(iframeId, navigation, footHeight, parentId) // 初始加载获取滚动条距离顶部高度
}
// 插件当前路由
if (_this && data.currentPath) {
_this.currentRoute = data
_this.searchFlag = data.currentName.includes('search-') ? true : false
}
// 点击企业详情页 栏目名动态设置滚动高度
if (data.scrollHeight) {
......@@ -48,23 +53,35 @@ const steerScroll = function(iframeId, navigation, state, parentId) { // state:
}
})
dom.addEventListener('scroll', (event) => {
scrolling(iframeId, navigation, parentId)
scrolling(iframeId, navigation, footHeight, parentId)
})
} else {
dom.removeEventListener('scroll', (event) => {
scrolling(iframeId, navigation, parentId)
scrolling(iframeId, navigation, footHeight, parentId)
})
}
}
const scrolling = function(iframeId, navigation, parentId) {
const scrolling = function(iframeId, navigation, footHeight, parentId) {
// 滚动条距文档顶部的距离
let scrollTop = parentId ? document.getElementById(parentId).scrollTop : window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
// 将滚动距离传入子组件
const ifa = document.getElementById(iframeId)
scrollTop = scrollTop + navigation.totalHeight
const bodyHeight = document.body.clientHeight - navigation.totalHeight
ifa.contentWindow.postMessage({ 'scrollTop': scrollTop, 'navHeight': navigation.totalHeight, 'bodyHeight': bodyHeight }, '*')
let rippleHeight = 0 //插件筛选条件浮动层距离底部距离
let scrollGap = parentId ? document.getElementById(parentId).scrollTop : window.scrollTop || document.body.scrollTop || document.documentElement.scrollTop
let scrollHeight = parentId ? document.getElementById(parentId).offsetHeight : window.scrollHeight || document.body.scrollHeight || document.documentElement.scrollHeight
let domHeight = parentId ? document.getElementById(parentId).clientHeight : window.clientHeight || document.body.clientHeight || document.documentElement.clientHeight
if(parentId){ //网页内部嵌套时
rippleHeight = scrollHeight-scrollGap-domHeight
}else{ //
if(scrollHeight-scrollGap-domHeight <= footHeight){
rippleHeight = 0
}else{
rippleHeight = scrollHeight-scrollGap-domHeight - footHeight
}
}
ifa.contentWindow.postMessage({ 'scrollTop': scrollTop, 'navHeight': navigation.totalHeight, 'rippleHeight': rippleHeight }, '*')
}
export {
......
......@@ -5,8 +5,10 @@
</template>
<script>
import { steerScroll } from '@/assets/js/jskplug'
export default {
import { steerScroll } from '@/assets/js/jskplug'
import { dskAccessToken } from '@/api/common'
export default {
name: 'Company',
components: {
......@@ -18,29 +20,17 @@ export default {
iframeHight: window.innerHeight, // iframe高度-当前页控制
navigation: {isFixed: true, fixedHeight: 56, totalHeight: 68}, // iframe之外页面顶部对象,ifFixed:是否浮动;fixedHeight:浮动对象高度;totalHeight:顶部整体高度
src: '', //iframe嵌套页面地址
domain: 'https://pre-plug.jiansheku.com',
domain: 'https://plug.jiansheku.com', // 插件地址
// domain: 'http://192.168.60.19:3400',
// domain: 'http://192.168.60.30:3300',
ak: 'aec7b3ff2y2q8x6t49a7e2c463ce21912' // 需要携带的sdkId
ak: 'aec7b3ff2y2q8x6t49a7e2c463ce21912', // 需要携带的sdkId
uid: this.$store.state.user.userId, // 需要携带的uid
timelongs:7200,//刷新token时间
tokentimer:null,
}
},
created() {
if (this.$route.params.id) { // 获取companyId
this.loading = true
if(this.$route.name=='Company'){ //企业详情
if(this.$route.query.html){
if(this.$route.query.type){
this.src = `${this.domain}/enterprise/${this.$route.params.id}/${this.$route.query.html}?flag=true&type=${this.$route.query.type}&ak=${this.ak}`
}else{
this.src = `${this.domain}/enterprise/${this.$route.params.id}/${this.$route.query.html}?ak=${this.ak}`
}
}else{
this.src = `${this.domain}/enterprise/${this.$route.params.id}?ak=${this.ak}`
}
}
if(this.$route.name=='Personnel'){ //人员详情
this.src = `${this.domain}/personnel/${this.$route.params.id}.html?ak=${this.ak}`
}
}
this.gettokens()
},
mounted() {
this.iframeLoading() // 判断iframe页面是否加载完成-当前页控制
......@@ -49,8 +39,53 @@ export default {
beforeDestroy() {
clearInterval(this.iframeTimer) // -当前页控制
steerScroll('companyIframe', this.navigation) // 销毁滚动
clearInterval(this.tokentimer)
},
methods: {
gettokens(){
dskAccessToken().then(res=>{
if(res.code == 200){
this.timelongs = res.data.expire
this.ak = res.data.accessToken
if (this.$route.params.id) { // 获取companyId
this.loading = true
if(this.$route.name=='Company'){ //企业详情
if(this.$route.query.html){
if(this.$route.query.type){
this.src = `${this.domain}/enterprise/${this.$route.params.id}/${this.$route.query.html}?flag=true&type=${this.$route.query.type}&ak=${this.ak}&initTime=${new Date().getTime()}&uid=${this.ak}`
}else{
this.src = `${this.domain}/enterprise/${this.$route.params.id}/${this.$route.query.html}?ak=${this.ak}&initTime=${new Date().getTime()}&uid=${this.ak}`
}
}else{
this.src = `${this.domain}/enterprise/${this.$route.params.id}?ak=${this.ak}&initTime=${new Date().getTime()}&uid=${this.ak}`
}
}
if(this.$route.name=='Personnel'){ //人员详情
this.src = `${this.domain}/personnel/${this.$route.params.id}.html?ak=${this.ak}&initTime=${new Date().getTime()}&uid=${this.ak}`
}
}
this.refreshtoken()
}else{
clearTimeout(this.tokentimer)
}
})
},
refreshtoken(){
this.tokentimer = setTimeout(()=>{
dskAccessToken().then(res => {
if (res.code == 200) {
this.timelongs = res.data.expire
this.ak = res.data.accessToken
let ifam = document.getElementById('companyIframe') //iframe的id
let akObj = res.data.expire //accessToken接口的返回值
let initTime = new Date().getTime() //accessToken接口返回后的当前时间戳
ifam.contentWindow.postMessage({ 'accessToken': akObj.accessToken, 'initTime': initTime }, '*')
}else{
clearTimeout(this.tokentimer)
}
})
}, this.timelongs*1000)
},
//判断iframe页面是否加载完成-当前页控制
iframeLoading() {
let iframeHeight = document.getElementById("companyIframe").clientHeight, number = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment