app/pages/tabbar/vlog/index_old.nvue

772 lines
18 KiB
Plaintext
Raw Normal View History

2025-04-25 18:10:54 +08:00
<template>
<view
class="page"
:id="pageId"
>
<swiper
ref="swiper1"
id="tab-bar-view"
style="my-swiper"
:style="{ height: screenHeight + 'px' }"
:current="curIndex"
@change="changeTopTab"
@transition="onswiperscroll"
@animationfinish="animationfinish"
@onAnimationEnd="animationfinish"
>
<swiper-item>
<video-local
ref="videoLocal"
:pid="1"
:parentId="pageId"
:screenHeight="screenHeight"
:progressFlag="isDraw_lo"
:playStatus="playLocalStatus"
:videoList="videoList"
:refreshList="refreshList"
:pagingList="pagingList"
@showLoading="showLoading"
@hideLoading="hideLoading"
@displayVideoPaging="displayVideoPaging"
></video-local>
</swiper-item>
<swiper-item>
<view
v-if="myUserInfo == null"
ref="videoFollowComp"
class="my-follow"
:style="{ height: screenHeight + 'px' }"
>
<text class="warn-info">请登录后查看!</text>
</view>
<video-follow-comp
ref="videoFollowComp"
:pid="2"
:parentId="pageId"
:screenHeight="screenHeight"
:progressFlag="isDraw_gz"
:playFollowStatus="playFollowStatus"
:videoList="videoList"
:refreshList="refreshList"
:pagingList="pagingList"
@showLoading="showLoading"
@hideLoading="hideLoading"
@letFollowVideoPause="letFollowVideoPause"
@displayVideoPaging="displayVideoPaging"
></video-follow-comp>
</swiper-item>
<swiper-item>
<!--
<video-comp
ref="videoComp"
:pid="3"
:parentId="pageId"
:screenHeight="screenHeight"
:progressFlag="isDraw_tj"
:playStatus="playStatus"
:videoList="videoList"
:refreshList="refreshList"
:pagingList="pagingList"
@showLoading="showLoading"
@hideLoading="hideLoading"
@displayVideoPaging="displayVideoPaging"
></video-comp>
-->
<video-comp></video-comp>
</swiper-item>
</swiper>
<view
class="header"
id="head"
:style="{ marginTop: statusBarHeight + 'px' }"
v-if="!isLoading"
>
<text class="header-left"></text>
<view class="header-center">
<scroll-view
ref="tabbar1"
id="tab-bar"
class="tab-bar"
:scroll="false"
:scroll-x="true"
:show-scrollbar="false"
:scroll-into-view="scrollInto"
>
<view style="flex-direction: column; flex: 1">
<view style="flex-direction: row; flex: 1; justify-content: space-around">
<view
class="uni-tab-item"
v-for="(tab, index) in tabList"
:key="tab.id"
:id="tab.id"
:ref="'tabitem' + index"
:data-id="index"
:data-current="index"
@click="ontabtap"
>
<text
class="uni-tab-item-title scroll-view-animation"
:class="tabIndex == index ? 'uni-tab-item-title-active' : ''"
>
{{ tab.name }}
</text>
</view>
</view>
<view class="scroll-view-indicator">
<view
ref="underline"
class="scroll-view-underline"
:class="isTap ? 'scroll-view-animation' : ''"
:style="{ left: indicatorLineLeft + 'px', width: indicatorLineWidth + 'px' }"
></view>
</view>
</view>
</scroll-view>
</view>
<image
class="header-right-search normal-img"
src="/static/images/icon-search.png"
@click="goSearch"
/>
</view>
<view
class="header"
:style="{ marginTop: statusBarHeight + 'px' }"
v-if="isLoading"
>
<text class="header-left"></text>
<view class="header-center">
<view class="header-item">
<text class="header-refresh-title">下拉刷新视频</text>
</view>
</view>
<image
class="header-right-search normal-img"
src="/static/images/loading.gif"
/>
</view>
</view>
</template>
<script>
let animation = weex.requireModule('animation');
let dom = weex.requireModule('dom');
let system = uni.getSystemInfoSync();
console.log(system);
// 缓存每页最多
const MAX_CACHE_DATA = 100;
// 缓存页签数量
const MAX_CACHE_PAGE = 3;
const TAB_PRELOAD_OFFSET = 1;
import storage from '@/utils/storage.js'; //缓存
import { vlogList } from '@/api/vlog';
import { isStrEmpty } from '@/utils/tools.js';
// import videoComp from '@/components/vlog/videoComp';
import videoComp from '@/components/vlog/tuijian.nvue';
import videoLocal from '@/components/vlog/videoLocal';
import videoFollowComp from '@/components/vlog/videoFollowComp';
import config from '@/config/config';
export default {
components: {
videoLocal,
videoComp,
videoFollowComp
},
data() {
return {
isTap: false,
isLoading: false,
statusBarHeight: system.statusBarHeight,
screenHeight: system.screenHeight,
curIndex: 2,
cityCode: '',
playStatus: false, // 推荐
playFollowStatus: false, // 关注
playLocalStatus: false, // 同城
videoList: [], // 首页一开始查询所得的默认视频列表
refreshList: [], // 下拉刷新后获得的新的列表
pagingList: [], // 分页list
refresh: 0, // 从me页面传来的refresh用于退出登录后重新刷新当前页的视频
/////////////////
pageList: ['videoLocal', 'videoFollowComp', 'videoComp'],
tabList: [
{
id: 'tab' + 0,
name: '同城',
pageid: 1
},
{
id: 'tab' + 1,
name: '关注',
pageid: 2
},
{
id: 'tab' + 2,
name: '推荐',
pageid: 3
}
], //tabs内容,'fujin','videoFollowComp','videoComp'
indicatorLineLeft: 0,
indicatorLineWidth: 0,
cacheTab: [],
scrollInto: '',
pageId: 'page',
tabIndex: 2,
isDraw_lo: false,
isDraw_tj: false,
isDraw_gz: false
};
},
created() {},
onReady() {
this._lastTabIndex = 0;
this.swiperWidth = 0;
this.tabbarWidth = 0;
this.tabListSize = {};
this._touchTabIndex = 0;
this._headHeight = 100;
var timer = setTimeout(() => {
this.selectorQuery();
clearTimeout(timer);
}, 300);
},
onTabItemTap: function (e) {
// console.log(e);
// let tabIndex = e.index;
// this.playStatus = tabIndex === 0 ? true : false;
// 切换视频要做暂停或播放的判断
let me = this;
let curIndex = me.curIndex;
if (curIndex == 0) {
me.playLocalStatus = true;
me.playFollowStatus = false;
me.playStatus = false;
} else if (curIndex == 1) {
me.playLocalStatus = false;
me.playFollowStatus = true;
me.playStatus = false;
} else if (curIndex == 2) {
me.playLocalStatus = false;
me.playFollowStatus = false;
me.playStatus = true;
}
},
onShow() {
this.getLocation();
let me = this;
me.myUserInfo = storage.getVlogUserInfo();
if (uni.getStorageSync('refreshVlogIndex') == '1') {
storage.setRefreshVlogIndex('0'); //不需要刷新
this.$refs.videoComp.displayVideoPaging(1, true);
this.$refs.videoFollowComp.displayVideoPaging(1, true);
this.$refs.videoLocal.displayVideoPaging(1, true);
}
// 如果当前没有list, 则relaunch
if (this.$refs.videoComp != undefined) {
let playerList = this.$refs.videoComp.playerList;
if (playerList != undefined && playerList.length == 0) {
this.$refs.videoComp.displayVideoPaging(1, true);
}
}
if (me.curIndex == 0) {
me.playLocalStatus = true;
}
if (me.curIndex == 1) {
me.playFollowStatus = true;
}
if (me.curIndex == 2) {
me.playStatus = true;
}
},
onHide() {
var me = this;
// 显示和隐藏需要判断根据不同tab做暂停或者隐藏
if (me.curIndex == 0) {
me.playLocalStatus = false;
me.isDraw_lo = false;
}
if (me.curIndex == 1) {
me.playFollowStatus = false;
me.isDraw_gz = false;
}
if (me.curIndex == 2) {
me.playStatus = false;
me.isDraw_tj = false;
}
},
// 当前页下拉刷新
// onPullDownRefresh() {
// var me = this;
// // 下拉刷新判断如果是不同tab那么组件中刷新的请求也不同
// if (me.curIndex == 0) {
// this.$refs.videoFollowComp.displayVideoPaging(1, true);
// } else if (me.curIndex == 1) {
// this.$refs.videoComp.displayVideoPaging(1, true);
// }
// },
methods: {
getLocation() {
uni.getLocation({
type: 'wg84',
success: (res) => {
console.log(res);
var latitude = res.latitude;
var longitude = res.longitude;
var location = latitude + ',' + longitude;
var key = config.aMapKey;
uni.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1/',
method: 'GET',
data: {
location,
key
},
success: (address) => {
console.log(address);
var ad_info = address.data.result.ad_info;
var cityCode = ad_info.adcode; // 城市编码cityCode
storage.setCityCode(cityCode);
this.cityCode = cityCode;
var address_name = ad_info.district || ad_info.city;
this.tabList.forEach((i, index) => {
if (index == 0) {
i.name = address_name;
// this.selectorQuery();
var timer = setTimeout(() => {
this.selectorQuery();
clearTimeout(timer);
}, 300);
}
});
}
});
},
fail: (err) => {
console.log(err);
uni.showToast({
icon: 'none',
title: '获取位置信息失败'
});
// uni.showModal({
// title:'提示',
// content:'获取位置信息失败',
// showCancel:false,
// success: (res) => {
// if(res.confirm){
// }
// }
// })
}
});
},
// 前往搜索页面
goSearch() {
uni.navigateTo({
url: '/pages/search/search'
});
},
// ----------头部区域点击tabs
ontabtap(e) {
console.log(e);
let index = e.target.dataset.current || e.currentTarget.dataset.current;
this.isTap = true;
var currentSize = this.tabListSize[index];
this.updateIndicator(currentSize.left, currentSize.width);
this._touchTabIndex = index;
this.switchTab(index);
},
//
selectorQuery() {
var dm = uni.createSelectorQuery().in(this);
dm.select('#head')
.boundingClientRect()
.exec((rect) => {
this._headHeight = rect[0].height;
});
// 查询 tabbar 宽度
dm.in(this)
.select('#tab-bar')
.boundingClientRect()
.exec((rect) => {
this.tabbarWidth = rect[0].width;
console.log(this.tabbarWidth);
});
// 查询 tabview 宽度
dm.in(this)
.select('#tab-bar-view')
.boundingClientRect()
.exec((rect) => {
this.swiperWidth = rect[0].width;
console.log(this.swiperWidth);
});
// 因 nvue 暂不支持 class 查询
// var queryTabSize = uni.createSelectorQuery().in(this);
var queryTabSize = dm;
for (var i = 0; i < this.tabList.length; i++) {
queryTabSize.select('#' + this.tabList[i].id).boundingClientRect();
}
queryTabSize.exec((rects) => {
rects.forEach((rect) => {
rect.left = rect.left - 40; //修正 left 值,减去 padding-left: 40px
this.tabListSize[rect.dataset.id] = rect;
});
console.log(this.tabListSize[this.tabIndex]);
this.updateIndicator(this.tabListSize[this.tabIndex].left, this.tabListSize[this.tabIndex].width);
this.switchTab(this.tabIndex);
});
},
onswiperscroll(e) {
this.isDraw_gz = false;
this.isDraw_lo = false;
this.isDraw_tj = false;
// if (this.playStatus == true) {
// this.playStatus = this._lastTabIndex == 2 ? false : true;
// }
// this.playFollowStatus = this._lastTabIndex == 1 ? false : true;
// this.playLocalStatus = this._lastTabIndex == 0 ? false : true;
var offsetX = e.detail.dx;
var preloadIndex = this._lastTabIndex;
if (offsetX > TAB_PRELOAD_OFFSET) {
preloadIndex++;
} else if (offsetX < -TAB_PRELOAD_OFFSET) {
preloadIndex--;
}
let prop = this.pageList[preloadIndex];
let obj = this.$refs[prop];
if (!obj) return;
// 点击切换
if (this.isTap) {
return;
}
// 切换失败
if (preloadIndex === this._lastTabIndex || preloadIndex < 0 || preloadIndex > this.pageList.length - 1) {
// 是否有视频数据
if (obj.playerList.length === 0) {
// this.loadTabData(preloadIndex);
this.isDraw_gz = false;
this.isDraw_lo = false;
this.isDraw_tj = false;
} else {
this.isDraw_gz = preloadIndex == 1 ? true : false;
this.isDraw_lo = preloadIndex == 0 ? true : false;
this.isDraw_tj = preloadIndex == 2 ? true : false;
}
return;
}
// console.log(this.tabListSize)
var percentage = Math.abs(this.swiperWidth / offsetX);
var currentSize = this.tabListSize[this._lastTabIndex];
var preloadSize = this.tabListSize[preloadIndex];
var lineL = currentSize.left + (preloadSize.left - currentSize.left) / percentage;
var lineW = currentSize.width + (preloadSize.width - currentSize.width) / percentage;
this.updateIndicator(lineL, lineW);
},
animationfinish(e) {
let index = e.detail.current;
console.log('当前索引' + index);
console.log('之前的索引' + this._lastTabIndex);
this._lastTabIndex = index;
if (this._touchTabIndex === index) {
this.isTap = false;
}
this.switchTab(index);
if (!this.tabListSize[index]) {
return;
} else {
// this.playStatus = index == 2 ? false : true;
// this.playFollowStatus = index == 1 ? true : false;
// this.playLocalStatus = index == 0 ? true : false;
this.isDraw_gz = index == 1 ? true : false;
this.isDraw_lo = index == 0 ? true : false;
this.isDraw_tj = index == 2 ? true : false;
this.updateIndicator(this.tabListSize[index].left, this.tabListSize[index].width);
}
},
updateIndicator(left, width) {
// console.log(left)
this.indicatorLineLeft = left;
this.indicatorLineWidth = width;
},
switchTab(index) {
if (this.tabIndex === index) {
return;
}
// console.dir(this.$refs)
let props = this.pageList[index];
console.log(props);
console.log(index);
let obj = this.$refs[props];
// if (obj.playerList.length === 0) {
// var info = storage.getVlogUserInfo() || null
// if(info!=null&&index==0){
// obj.displayVideoPaging(this.page + 1, true);
// }
// }
obj.setScrollRef(this._headHeight);
console.log(this.cacheTab);
// 缓存 tabId
if (obj.playerList.length > MAX_CACHE_DATA) {
let isExist = this.cacheTab.indexOf(this.tabIndex);
if (isExist < 0) {
this.cacheTab.push(this.tabIndex);
}
}
this.tabIndex = index;
this.curIndex = index;
this.scrollTabTo(index);
this.scrollInto = this.tabList[index].id;
// 释放 tabId
if (this.cacheTab.length > MAX_CACHE_PAGE) {
let cacheIndex = this.cacheTab[0];
this.clearTabData(cacheIndex);
this.cacheTab.splice(0, 1);
}
// const el = this.$refs['tabitem' + index][0];
// animation.transition(el, {
// duration: 3000, //ms
// timingFunction: 'ease',
// delay: 1000 //ms
// });
},
scrollTabTo(index) {
console.log(index);
const el = this.$refs['tabitem' + index][0];
let offset = 0;
// TODO fix ios offset
if (index > 0) {
offset = this.tabbarWidth / 2 - this.tabListSize[index].width / 2;
if (this.tabListSize[index].right < this.tabbarWidth / 2) {
offset = this.tabListSize[0].width;
}
}
dom.scrollToElement(el, {
offset: -offset
});
},
//----------------------------
// 左滑右滑选项卡改变选中状态
changeTopTab: function (e) {
var current = e.detail.current;
this.curIndex = current;
this.tabIndex = current;
let timer = setTimeout(() => {
this.playLocalStatus = this.curIndex === 0 ? true : false;
this.playFollowStatus = this.curIndex === 1 ? true : false;
this.playStatus = this.curIndex === 2 ? true : false;
clearTimeout(timer);
}, 10);
},
// 下拉刷新改变head的字样显示
showLoading() {
this.isLoading = true;
},
hideLoading() {
this.isLoading = false;
},
letFollowVideoPause() {
this.playFollowStatus = false;
}
}
};
</script>
<style scoped>
/* index start */
.page {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: #000000;
}
/* index end */
/* 顶部选项卡 start */
.header {
position: absolute;
left: 0;
right: 0;
flex-direction: row;
height: 100rpx;
line-height: 100rpx;
align-items: center;
padding-left: 40px;
padding-right: 40px;
}
.header-center {
flex: 1;
flex-direction: row;
align-items: center;
justify-content: center;
}
.header-left,
.header-right {
color: #999;
height: 100rpx;
line-height: 100rpx;
align-items: flex-start;
justify-content: flex-end;
font-family: iconfont;
}
.header-right-search {
height: 100rpx;
/* align-items: flex-start;
justify-content: flex-end; */
}
.header-item {
align-items: center;
margin-left: 6rpx;
margin-right: 6rpx;
}
.header-item-title {
width: 120rpx;
text-align: center;
height: 60rpx;
line-height: 60rpx;
color: #ffffff;
font-size: 16px;
font-weight: 600;
}
.header-refresh-title {
width: 300rpx;
text-align: center;
height: 60rpx;
line-height: 60rpx;
color: #ffffff;
font-size: 16px;
font-weight: 600;
}
.header-item-line {
height: 5rpx;
line-height: 8rpx;
width: 60rpx;
border-radius: 8rpx;
}
/* 顶部选项卡 end */
/* 选项卡轮播组件 start */
.my-swiper {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.near-by {
background-color: #000000;
align-items: center;
justify-content: center;
}
.my-follow {
background-color: #000000;
align-items: center;
justify-content: center;
}
/* 选项卡轮播组件 end */
.warn-info {
color: #ffffff;
font-size: 36rpx;
font-weight: 600;
}
.normal-img {
width: 50rpx;
height: 50rpx;
opacity: 0.8;
}
/* */
.tab-bar {
/* width: 750upx; */
flex: 1;
height: 84upx;
flex-direction: row;
lines: 1;
text-overflow: ellipsis;
justify-content: center;
align-items: center;
}
.uni-tab-item {
flex-wrap: nowrap;
/* padding-left: 25px; */
/* padding-right: 25px; */
}
.uni-tab-item-title {
color: #999;
font-size: 30upx;
height: 80upx;
line-height: 80upx;
flex-wrap: nowrap;
lines: 1;
text-overflow: ellipsis;
}
.uni-tab-item-title-active {
color: #ffffff;
}
.scroll-view-indicator {
position: relative;
height: 2px;
background-color: transparent;
}
.scroll-view-underline {
position: absolute;
top: 0;
bottom: 0;
width: 0;
/* background-color: #007AFF; */
background-color: #ffffff;
}
.scroll-view-animation {
transition-duration: 0.2s;
/* transition-property: transform; */
}
.tab-bar-line {
height: 1upx;
background-color: #cccccc;
}
</style>