优化
This commit is contained in:
parent
a2a53cd829
commit
1967f1931b
@ -282,8 +282,13 @@ export default {
|
|||||||
this.commentVisible = false
|
this.commentVisible = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
click({id, type}) {
|
click({baseIndex, navIndex, itemIndex, type}) {
|
||||||
if (this.item.id === id) {
|
// console.log(baseIndex, navIndex, itemIndex, this.position)
|
||||||
|
if (
|
||||||
|
this.position.baseIndex === baseIndex &&
|
||||||
|
this.position.navIndex === navIndex &&
|
||||||
|
this.position.itemIndex === itemIndex
|
||||||
|
) {
|
||||||
if (type === EVENT_KEY.ITEM_TOGGLE) {
|
if (type === EVENT_KEY.ITEM_TOGGLE) {
|
||||||
if (this.status === SlideItemPlayStatus.Play) {
|
if (this.status === SlideItemPlayStatus.Play) {
|
||||||
this.pause()
|
this.pause()
|
||||||
|
|||||||
@ -44,7 +44,7 @@ const props = defineProps({
|
|||||||
const emit = defineEmits(['update:index', 'loadMore'])
|
const emit = defineEmits(['update:index', 'loadMore'])
|
||||||
|
|
||||||
const appInsMap = new Map()
|
const appInsMap = new Map()
|
||||||
const itemClassName = 'slide-item2'
|
const itemClassName = 'slide-item'
|
||||||
const wrapperEl = ref(null)
|
const wrapperEl = ref(null)
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
name: props.name,
|
name: props.name,
|
||||||
@ -91,14 +91,16 @@ watch(
|
|||||||
watch(
|
watch(
|
||||||
() => props.index,
|
() => props.index,
|
||||||
(newVal, oldVal) => {
|
(newVal, oldVal) => {
|
||||||
// console.log('watch-index', newVal, oldVal, props.list[newVal].id)
|
// console.log('watch-index', newVal, oldVal,props.list, props.list[newVal].id)
|
||||||
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
|
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
|
||||||
id: props.list[newVal].id,
|
...props.position,
|
||||||
|
itemIndex: newVal,
|
||||||
type: EVENT_KEY.ITEM_PLAY
|
type: EVENT_KEY.ITEM_PLAY
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
|
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
|
||||||
id: props.list[oldVal].id,
|
...props.position,
|
||||||
|
itemIndex: oldVal,
|
||||||
type: EVENT_KEY.ITEM_STOP
|
type: EVENT_KEY.ITEM_STOP
|
||||||
})
|
})
|
||||||
}, 200)
|
}, 200)
|
||||||
@ -110,7 +112,6 @@ onMounted(() => {
|
|||||||
insertContent()
|
insertContent()
|
||||||
})
|
})
|
||||||
|
|
||||||
//默认使用this.list,刷新时,考虑到vue可能更新外面的videos到this.list数据没有那么快,因为我要立即刷新
|
|
||||||
function insertContent(list = props.list) {
|
function insertContent(list = props.list) {
|
||||||
$(wrapperEl.value).empty()
|
$(wrapperEl.value).empty()
|
||||||
let half = (props.virtualTotal - 1) / 2
|
let half = (props.virtualTotal - 1) / 2
|
||||||
@ -155,7 +156,7 @@ function dislike(item) {
|
|||||||
defineExpose({dislike})
|
defineExpose({dislike})
|
||||||
|
|
||||||
function getInsEl(item, index, play = false) {
|
function getInsEl(item, index, play = false) {
|
||||||
console.log('index', index, play)
|
// console.log('index', index, play)
|
||||||
let slideVNode = props.render(item, index, play, props.position)
|
let slideVNode = props.render(item, index, play, props.position)
|
||||||
const app = createApp({
|
const app = createApp({
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@ -44,7 +44,6 @@ export function slideTouchMove(e, el, state, judgeValue, canNextCb, nextCb, type
|
|||||||
|
|
||||||
let canSlideRes = canSlide(state, judgeValue, type)
|
let canSlideRes = canSlide(state, judgeValue, type)
|
||||||
|
|
||||||
//当
|
|
||||||
if (canSlideRes && state.localIndex === 0 && !isNext && type === SlideType.VERTICAL) {
|
if (canSlideRes && state.localIndex === 0 && !isNext && type === SlideType.VERTICAL) {
|
||||||
bus.emit(state.name + '-moveY', state.move.y)
|
bus.emit(state.name + '-moveY', state.move.y)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,19 +5,17 @@
|
|||||||
<IndicatorHome
|
<IndicatorHome
|
||||||
:isLight="state.subTypeVisible"
|
:isLight="state.subTypeVisible"
|
||||||
v-if="!state.fullScreen"
|
v-if="!state.fullScreen"
|
||||||
:loading="state.loading"
|
:loading="loading"
|
||||||
name="main"
|
name="main"
|
||||||
v-model:index="state.navIndex"
|
v-model:index="state.navIndex"
|
||||||
/>
|
/>
|
||||||
|
<div class="slide-content">
|
||||||
<div class="slide-content"
|
|
||||||
>
|
|
||||||
<SlideHorizontal class="first-horizontal-item"
|
<SlideHorizontal class="first-horizontal-item"
|
||||||
name="main"
|
name="main"
|
||||||
id="home-index"
|
id="home-index"
|
||||||
:change-active-index-use-anim="false"
|
:change-active-index-use-anim="false"
|
||||||
v-model:index="state.navIndex">
|
v-model:index="state.navIndex">
|
||||||
<SlideItem id="slide1">
|
<SlideItem id="slide0">
|
||||||
<div class="sub-type"
|
<div class="sub-type"
|
||||||
:class="state.subTypeIsTop?'top':''"
|
:class="state.subTypeIsTop?'top':''"
|
||||||
ref="subTypeRef">
|
ref="subTypeRef">
|
||||||
@ -62,23 +60,23 @@
|
|||||||
v-if="state.subType===-1 && !state.subTypeVisible"
|
v-if="state.subType===-1 && !state.subTypeVisible"
|
||||||
@click="showSubType">附近吃喝玩乐
|
@click="showSubType">附近吃喝玩乐
|
||||||
</div>
|
</div>
|
||||||
|
<Loading v-if="state.slide0.loading && state.slide0.list.length === 0"/>
|
||||||
<SlideVerticalInfinite
|
<SlideVerticalInfinite
|
||||||
@touchstart="pageClick"
|
@touchstart="pageClick"
|
||||||
v-love="'home-index'"
|
v-love="'slide0-infinite'"
|
||||||
:style="{background: 'black',marginTop:state.subTypeVisible?state.subTypeHeight:0}"
|
:style="{background: 'black',marginTop:state.subTypeVisible?state.subTypeHeight:0}"
|
||||||
name="main"
|
name="main"
|
||||||
id="slide1-infinite"
|
id="slide0-infinite"
|
||||||
v-model:index="state.itemIndex"
|
v-model:index="state.slide0.index"
|
||||||
:render="render"
|
:render="render"
|
||||||
:list="state.recommendList"
|
:list="state.slide0.list"
|
||||||
:position="{
|
:position="{
|
||||||
baseIndex:0,
|
baseIndex:0,
|
||||||
navIndex:5,
|
navIndex:0,
|
||||||
}"
|
}"
|
||||||
@loadMore="loadMore"
|
@loadMore="loadSlide1More"
|
||||||
@refresh="() => getData(true)"
|
@refresh="() => getSlide0Data(true)"
|
||||||
>
|
/>
|
||||||
</SlideVerticalInfinite>
|
|
||||||
</SlideItem>
|
</SlideItem>
|
||||||
<SlideItem>
|
<SlideItem>
|
||||||
<Community/>
|
<Community/>
|
||||||
@ -90,19 +88,20 @@
|
|||||||
<Shop/>
|
<Shop/>
|
||||||
</SlideItem>
|
</SlideItem>
|
||||||
<SlideItem>
|
<SlideItem>
|
||||||
|
<Loading style="position: absolute" v-if="state.slide4.loading && state.slide4.list.length === 0"/>
|
||||||
<SlideVerticalInfinite
|
<SlideVerticalInfinite
|
||||||
ref="recommendListRef"
|
ref="recommendListRef"
|
||||||
:style="{background: 'black'}"
|
:style="{background: 'black'}"
|
||||||
name="main"
|
name="main"
|
||||||
v-model:index="state.itemIndex"
|
v-model:index="state.slide4.index"
|
||||||
:render="render"
|
:render="render"
|
||||||
:list="state.recommendList"
|
:list="state.slide4.list"
|
||||||
:position="{
|
:position="{
|
||||||
baseIndex:0,
|
baseIndex:0,
|
||||||
navIndex:5,
|
navIndex:4,
|
||||||
}"
|
}"
|
||||||
@loadMore="loadMore"
|
@loadMore="loadSlide4More"
|
||||||
@refresh="() => getData(true)"
|
@refresh="() => getSlide4Data(true)"
|
||||||
>
|
>
|
||||||
</SlideVerticalInfinite>
|
</SlideVerticalInfinite>
|
||||||
</SlideItem>
|
</SlideItem>
|
||||||
@ -187,7 +186,7 @@ import BVideo from "../../components/slide/BVideo.vue";
|
|||||||
import Comment from "../../components/Comment.vue";
|
import Comment from "../../components/Comment.vue";
|
||||||
import Share from "../../components/Share.vue";
|
import Share from "../../components/Share.vue";
|
||||||
import IndicatorHome from "./components/IndicatorHome.vue";
|
import IndicatorHome from "./components/IndicatorHome.vue";
|
||||||
import {computed, onMounted, onUnmounted, reactive, ref} from "vue";
|
import {computed, onMounted, onUnmounted, reactive, ref, watch} from "vue";
|
||||||
import bus, {EVENT_KEY} from "../../utils/bus";
|
import bus, {EVENT_KEY} from "../../utils/bus";
|
||||||
import {useNav} from "@/utils/hooks/useNav";
|
import {useNav} from "@/utils/hooks/useNav";
|
||||||
import Utils from "@/utils";
|
import Utils from "@/utils";
|
||||||
@ -205,6 +204,7 @@ import ShareToFriend from "@/pages/home/components/ShareToFriend.vue";
|
|||||||
import UserPanel from "@/components/UserPanel.vue";
|
import UserPanel from "@/components/UserPanel.vue";
|
||||||
import Community from "@/pages/home/components/Community.vue";
|
import Community from "@/pages/home/components/Community.vue";
|
||||||
import Shop from "@/pages/home/components/Shop.vue";
|
import Shop from "@/pages/home/components/Shop.vue";
|
||||||
|
import Loading from "@/components/Loading.vue";
|
||||||
|
|
||||||
const nav = useNav()
|
const nav = useNav()
|
||||||
|
|
||||||
@ -221,9 +221,49 @@ const subTypeRef = ref(null)
|
|||||||
const recommendListRef = ref(null)
|
const recommendListRef = ref(null)
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
baseIndex: 0,
|
baseIndex: 0,
|
||||||
navIndex: 4,
|
navIndex: 0,
|
||||||
itemIndex: 0,
|
|
||||||
test: '',
|
test: '',
|
||||||
|
slide0: {
|
||||||
|
loading: false,
|
||||||
|
index: 0,
|
||||||
|
list: [],
|
||||||
|
totalSize: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
pageNo: 0,
|
||||||
|
},
|
||||||
|
slide1: {
|
||||||
|
loading: false,
|
||||||
|
index: 0,
|
||||||
|
list: [],
|
||||||
|
totalSize: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
pageNo: 0,
|
||||||
|
},
|
||||||
|
slide2: {
|
||||||
|
loading: false,
|
||||||
|
index: 0,
|
||||||
|
list: [],
|
||||||
|
totalSize: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
pageNo: 0,
|
||||||
|
},
|
||||||
|
slide3: {
|
||||||
|
loading: false,
|
||||||
|
index: 0,
|
||||||
|
list: [],
|
||||||
|
totalSize: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
pageNo: 0,
|
||||||
|
},
|
||||||
|
slide4: {
|
||||||
|
loading: false,
|
||||||
|
index: 0,
|
||||||
|
list: [],
|
||||||
|
totalSize: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
pageNo: 0,
|
||||||
|
},
|
||||||
|
slideOneList: [],
|
||||||
recommendList: [
|
recommendList: [
|
||||||
// {
|
// {
|
||||||
// type: 'img',
|
// type: 'img',
|
||||||
@ -240,7 +280,6 @@ const state = reactive({
|
|||||||
],
|
],
|
||||||
isSharing: false,
|
isSharing: false,
|
||||||
canMove: true,
|
canMove: true,
|
||||||
loading: false,
|
|
||||||
|
|
||||||
shareType: -1,
|
shareType: -1,
|
||||||
|
|
||||||
@ -262,36 +301,90 @@ const state = reactive({
|
|||||||
subTypeHeight: '0',
|
subTypeHeight: '0',
|
||||||
//用于改变zindex的层级到上层,反正比slide高就行。不然摸不到subType.
|
//用于改变zindex的层级到上层,反正比slide高就行。不然摸不到subType.
|
||||||
subTypeIsTop: false,
|
subTypeIsTop: false,
|
||||||
totalSize: 0,
|
|
||||||
pageSize: 10,
|
|
||||||
pageNo: 0,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getData(refresh = false) {
|
const loading = computed(() => {
|
||||||
// if (process.env.NODE_ENV !== 'development') {
|
return state[`slide${state.navIndex}`].loading
|
||||||
// state.totalSize = 11
|
})
|
||||||
// return state.recommendVideos = resource.videos
|
|
||||||
// }
|
watch(
|
||||||
if (state.loading) return
|
() => state.navIndex,
|
||||||
state.loading = true
|
(newVal, oldValue) => {
|
||||||
let res = await api.videos.recommended({pageNo: refresh ? 0 : state.pageNo, pageSize: state.pageSize})
|
if (newVal === 0 && state.slide0.list.length === 0) {
|
||||||
console.log('loadMore-', 'refresh', refresh, res)
|
return getSlide0Data()
|
||||||
state.loading = false
|
}
|
||||||
if (res.code === 200) {
|
if (newVal === 4 && state.slide4.list.length === 0) {
|
||||||
state.totalSize = res.data.total
|
return getSlide4Data()
|
||||||
if (refresh) {
|
}
|
||||||
state.recommendList = []
|
if (newVal === 2) return
|
||||||
}
|
if ([0, 2, 4].includes(newVal)) {
|
||||||
state.recommendList = state.recommendList.concat(res.data.list)
|
let playItemIndex = state[`slide${newVal}`].index
|
||||||
} else {
|
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
|
||||||
state.pageNo--
|
baseIndex: state.baseIndex,
|
||||||
|
navIndex: newVal,
|
||||||
|
itemIndex: playItemIndex,
|
||||||
|
type: EVENT_KEY.ITEM_TOGGLE
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if ([0, 2, 4].includes(oldValue)) {
|
||||||
|
let stopItemIndex = state[`slide${oldValue}`].index
|
||||||
|
setTimeout(() => {
|
||||||
|
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
|
||||||
|
baseIndex: state.baseIndex,
|
||||||
|
navIndex: oldValue,
|
||||||
|
itemIndex: stopItemIndex,
|
||||||
|
type: EVENT_KEY.ITEM_STOP
|
||||||
|
})
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
function loadSlide1More() {
|
||||||
|
if (!state.loading) {
|
||||||
|
state.slide0.pageNo++
|
||||||
|
getSlide0Data()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMore() {
|
async function getSlide0Data(refresh = false) {
|
||||||
|
if (state.slide0.loading) return
|
||||||
|
state.slide0.loading = true
|
||||||
|
let res = await api.videos.recommended({pageNo: refresh ? 0 : state.slide0.pageNo, pageSize: state.slide0.pageSize})
|
||||||
|
console.log('getSlide0Data-', 'refresh', refresh, res)
|
||||||
|
state.slide0.loading = false
|
||||||
|
if (res.code === 200) {
|
||||||
|
state.slide0.totalSize = res.data.total
|
||||||
|
if (refresh) {
|
||||||
|
state.slide0.list = []
|
||||||
|
}
|
||||||
|
state.slide0.list = state.slide0.list.concat(res.data.list)
|
||||||
|
} else {
|
||||||
|
state.slide0.pageNo--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getSlide4Data(refresh = false) {
|
||||||
|
if (state.slide4.loading) return
|
||||||
|
state.slide4.loading = true
|
||||||
|
let res = await api.videos.recommended({pageNo: refresh ? 0 : state.slide4.pageNo, pageSize: state.slide4.pageSize})
|
||||||
|
console.log('getSlide4Data-', 'refresh', refresh, res)
|
||||||
|
state.slide4.loading = false
|
||||||
|
if (res.code === 200) {
|
||||||
|
state.slide4.totalSize = res.data.total
|
||||||
|
if (refresh) {
|
||||||
|
state.slide4.list = []
|
||||||
|
}
|
||||||
|
state.slide4.list = state.slide4.list.concat(res.data.list)
|
||||||
|
} else {
|
||||||
|
state.slide4.pageNo--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadSlide4More() {
|
||||||
if (!state.loading) {
|
if (!state.loading) {
|
||||||
state.pageNo++
|
state.pageNo++
|
||||||
getData()
|
getSlide4Data()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,13 +423,22 @@ function end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getData()
|
// getData()
|
||||||
|
getSlide0Data()
|
||||||
bus.on(EVENT_KEY.SINGLE_CLICK, () => {
|
bus.on(EVENT_KEY.SINGLE_CLICK, () => {
|
||||||
let id = ''
|
let itemIndex = -1
|
||||||
if (state.navIndex === 4) {
|
if (state.navIndex === 4) {
|
||||||
id = state.recommendList[state.itemIndex].id
|
itemIndex = state.slide4.index
|
||||||
}
|
}
|
||||||
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {id, type: EVENT_KEY.ITEM_TOGGLE})
|
if (state.navIndex === 0) {
|
||||||
|
itemIndex = state.slide0.index
|
||||||
|
}
|
||||||
|
bus.emit(EVENT_KEY.SINGLE_CLICK_BROADCAST, {
|
||||||
|
baseIndex: state.baseIndex,
|
||||||
|
navIndex: state.navIndex,
|
||||||
|
itemIndex,
|
||||||
|
type: EVENT_KEY.ITEM_TOGGLE
|
||||||
|
})
|
||||||
})
|
})
|
||||||
bus.on('update:item', val => {
|
bus.on('update:item', val => {
|
||||||
const {baseIndex, navIndex, itemIndex} = val.position
|
const {baseIndex, navIndex, itemIndex} = val.position
|
||||||
@ -422,7 +524,7 @@ function render(item, itemIndex, play, position) {
|
|||||||
height: calc(100vh - @footer-height) !important;
|
height: calc(100vh - @footer-height) !important;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
#slide1 {
|
#slide0 {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
.sub-type {
|
.sub-type {
|
||||||
@ -487,7 +589,7 @@ function render(item, itemIndex, play, position) {
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
#slide1-infinite {
|
#slide0-infinite {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
transition: height, margin-top .3s;
|
transition: height, margin-top .3s;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user