Browse Source

视频播放调试

master
xuhuajiao 3 weeks ago
parent
commit
1a4f990bda
  1. 10
      src/api/library.js
  2. 9
      src/main.js
  3. 24
      src/views/map/index.vue
  4. 5
      src/views/mixins/index.js
  5. 5
      src/views/pageFive/index.vue
  6. 113
      src/views/pageFour/index.vue
  7. 13
      src/views/pageOne/index.vue
  8. 21
      src/views/pageThree/index.vue

10
src/api/library.js

@ -154,6 +154,15 @@ export function FetchTotalResource(params) {
})
}
// page4 获取视频
export function FetchVideo(params) {
return request({
url: '/api/fileRelevant/getVideo' + '?' + qs.stringify(params, { indices: false }),
method: 'get',
urlType: 'local'
})
}
// 获取当日每小时借还信息
export function FetchTodayJH(params) {
return request({
@ -189,6 +198,7 @@ export default {
FetchNoticeList,
FetchSync36,
FetchTotalResource,
FetchVideo,
FetchTodayJH,
FetchWeekJH
}

9
src/main.js

@ -71,26 +71,21 @@ const app = new Vue({
// 处理路由参数并挂载应用
router.onReady(() => {
try {
// 获取路由参数(query或params)
const route = router.currentRoute
const libcode = route.query.libcode || route.params.libcode
// 更新Vuex状态
if (libcode) {
store.commit('SET_LIBCODE', libcode)
} else {
// 使用默认值(可选)
store.commit('SET_LIBCODE', '1501')
store.commit('SET_LIBCODE', '1201')
}
} catch (error) {
console.error('处理路由参数时出错:', error)
} finally {
// 确保应用最终会挂载
app.$mount('#app')
}
})
// 路由切换时更新libcode
router.beforeEach((to, from, next) => {
try {
const newLibcode = to.query.libcode || to.params.libcode
@ -100,5 +95,5 @@ router.beforeEach((to, from, next) => {
} catch (error) {
console.error('路由切换时更新libcode出错:', error)
}
next() // 必须调用next(),否则路由会被阻塞
next()
})

24
src/views/map/index.vue

@ -133,19 +133,25 @@ export default {
return this.$refs.mySwiper.swiper
}
},
watch: {
baseSetting: {
handler(result) {
if (!result) return
this.activatedBaseSetting = result
if (result.open_lib_appId && result.open_lib_secret && result.open_lib_http) {
this.getLibBookTotal(this.activatedBaseSetting)
this.getReadRanking(this.activatedBaseSetting)
this.getLendingTotal(this.activatedBaseSetting)
}
},
immediate: true
}
},
beforeDestroy() {
this.destroy()
},
created() {
this.$watch('baseSetting', (newVal, oldVal) => {
console.log('baseSetting 变化:', newVal)
if (newVal && Object.keys(newVal).length > 0) {
this.activatedBaseSetting = newVal
this.getLibBookTotal(this.activatedBaseSetting)
this.getReadRanking(this.activatedBaseSetting)
this.getLendingTotal(this.activatedBaseSetting)
}
}, { immediate: true })
},
activated() {
// this.getLibBookTotal(this.activatedBaseSetting)

5
src/views/mixins/index.js

@ -20,7 +20,8 @@ export const pageCrud = {
orderIds: [],
updateTime: '',
oldUpdateTime: JSON.parse(localStorage.getItem('updateTime')) || '',
welcomeData: []
welcomeData: [],
videoData: []
}
},
computed: {
@ -65,7 +66,6 @@ export const pageCrud = {
},
// 组件挂载时的共用方法
mounted() {
// this.useLibcode()
},
// 组件共用方法
methods: {
@ -80,6 +80,7 @@ export const pageCrud = {
const result = res.data.settings
this.baseSetting = res.data.settings
this.welcomeData = res.data.screenWelcomePromotions
this.videoData = res.data.screenPromotionVideos
// this.wecharQrCodeSrc = linkSrc + '/downloadFile' + result.wecharQrCode
this.wecharQrCodeSrc = result.wechar_qr_code.context
localStorage.setItem('wecharQrCodeSrc', this.wecharQrCodeSrc)

5
src/views/pageFive/index.vue

@ -55,15 +55,12 @@ export default {
},
baseSetting: {
handler(newVal) {
// baseSettingwelcome_play
if (newVal && newVal.welcome_play) {
// 1000
const seconds = parseInt(newVal.welcome_play.context, 10)
// 1-60使
if (!isNaN(seconds) && seconds > 0 && seconds <= 60) {
this.carouselInterval = seconds * 1000
} else {
this.carouselInterval = 5000 // 使5
this.carouselInterval = 5000
}
console.log('this.carouselInterval', this.carouselInterval)
}

113
src/views/pageFour/index.vue

@ -88,7 +88,7 @@
</template>
<script>
import { FetchInitScreenData, FetchTotalResource, FetchNoticeList, FetchSync36 } from '@/api/library'
import { FetchInitScreenData, FetchVideo, FetchNoticeList, FetchSync36 } from '@/api/library'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import { pageCrud } from '../mixins/index.js'
@ -123,33 +123,50 @@ export default {
},
on: {
slideChange: function() {
// index
_self.noticeIndex = this.activeIndex
// console.log('index' + _self.noticeIndex)
}
}
},
activatedBaseSetting: {}
activatedBaseSetting: {},
activatedVideo: []
}
},
computed: {
},
watch: {
videoData: {
handler(newVal) {
if (newVal && newVal.length !== 0) {
this.activatedVideo = newVal
this.getVideoResource()
} else {
this.activatedVideo = []
}
},
immediate: true
},
baseSetting: {
handler(result) {
if (!result) return
this.activatedBaseSetting = result
this.wecharQrCodeSrc = result.wechar_qr_code?.context || ''
if (result.open_lib_appId && result.open_lib_secret && result.open_lib_http) {
this.getBookRanking(this.activatedBaseSetting)
}
},
immediate: true
}
},
beforeDestroy() {
this.destroy()
},
created() {
// this.getVideoResource()
this.getNotice()
this.$watch('baseSetting', (newVal, oldVal) => {
console.log('pageFour:', newVal)
if (newVal && Object.keys(newVal).length > 0) {
this.activatedBaseSetting = newVal
this.getBookRanking(this.activatedBaseSetting)
}
}, { immediate: true })
},
activated() {
this.getVideoResource()
// this.getVideoResource()
this.load()
if (this.rankingData.length !== 0) {
this.currentHover = -1
@ -236,39 +253,63 @@ export default {
}
})
},
//
getVideoResource() {
FetchTotalResource().then(res => {
const result = JSON.parse(res.data)
const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
this.slideData = result.map((item, index) => {
if (item.filePath) {
item.cover = linkSrc + '/downloadFile' + item.filePath
} else {
item.cover = null
console.log('activatedVideo中的视频数据:', this.activatedVideo)
const videoIds = this.activatedVideo.map(item => item.videoImg)
if (videoIds.length === 0) {
this.slideData = []
console.log('没有需要请求的视频id')
return
}
const params = {
'videoIds': videoIds
}
FetchVideo(params).then(res => {
const videoUrls = res
console.log('获取到的视频URL列表:', videoUrls)
this.slideData = this.activatedVideo.map((videoInfo, index) => {
return {
...videoInfo,
cover: videoUrls[index] || null
}
return item
})
console.log('this.slideData', this.slideData)
//
}).filter(item => item.cover)
console.log('生成的视频播放数据:', this.slideData)
if (localStorage.getItem('videoIndex')) {
this.videoIndex = parseInt(localStorage.getItem('videoIndex'))
if (this.videoIndex >= this.slideData.length) {
this.videoIndex = 0
}
this.$nextTick(() => {
this.$refs.carousel.setActiveItem(this.videoIndex)
const videos = this.$refs.videos
const nextVideo = videos[this.videoIndex]
videos.forEach((video) => {
video.pause()
video.currentTime = 0
})
setTimeout(() => {
nextVideo.currentTime = localStorage.getItem('videoCurrentTime') ? localStorage.getItem('videoCurrentTime') : 0
nextVideo.play()
}, 2000)
if (videos && videos[this.videoIndex]) {
const targetVideo = videos[this.videoIndex]
videos.forEach(video => {
video.pause()
video.currentTime = 0
})
setTimeout(() => {
const savedTime = localStorage.getItem('videoCurrentTime')
if (savedTime) {
targetVideo.currentTime = parseFloat(savedTime)
}
targetVideo.play().catch(err => {
console.error('视频自动播放失败:', err)
})
}, 1000)
}
})
}
}).catch(error => {
console.error('Error', error)
console.error('获取视频URL失败:', error)
this.slideData = []
})
},
playVideo() {

13
src/views/pageOne/index.vue

@ -236,14 +236,13 @@ export default {
}
},
async created() {
if (localStorage.getItem('yesterdayCountCache')) {
localStorage.removeItem('yesterdayCountCache')
}
if (localStorage.getItem('lastMonthCountCache')) {
localStorage.removeItem('lastMonthCountCache')
}
// if (localStorage.getItem('yesterdayCountCache')) {
// localStorage.removeItem('yesterdayCountCache')
// }
// if (localStorage.getItem('lastMonthCountCache')) {
// localStorage.removeItem('lastMonthCountCache')
// }
// this.getInitData()
this.getNewBook()
},
beforeDestroy() {

21
src/views/pageThree/index.vue

@ -176,6 +176,18 @@ export default {
return this.$refs.swiperThumbs.swiper
}
},
watch: {
baseSetting: {
handler(result) {
if (!result) return
this.activatedBaseSetting = result
if (result.open_lib_appId && result.open_lib_secret && result.open_lib_http) {
this.getLendingTotal(this.activatedBaseSetting)
}
},
immediate: true
}
},
beforeDestroy() {
clearInterval(this.rankInterval)
this.rankInterval = null
@ -183,13 +195,6 @@ export default {
created() {
this.getWeekJH()
this.getTodayJH()
this.$watch('baseSetting', (newVal, oldVal) => {
console.log('pageThree:', newVal)
if (newVal && Object.keys(newVal).length > 0) {
this.activatedBaseSetting = newVal
this.getLendingTotal(this.activatedBaseSetting)
}
}, { immediate: true })
},
activated() {
// this.getLendingTotal(this.activatedBaseSetting)
@ -208,8 +213,6 @@ export default {
this.isKeep = false
},
mounted() {
// this.getLendingTotal()
// this.getTodayJH()
},
methods: {
paddingNum(num, length) {

Loading…
Cancel
Save