123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- <template>
- <view class="play-container">
- <u-loading-page
- :loading="loading"
- :bg-color="$colors.bgColor"
- :color="$colors.primaryColor"
- :loading-color="$colors.primaryColor"
- />
- <template v-if="!loading">
- <!--播放数据-->
- <view class="view-num main-left cross-center">
- <u-icon name="eye-fill" :color="isCollect?$colors.primaryColor:$colors.defaultColor" size="26rpx" />
- <text>{{ episode.user_watch_record_count }}</text>
- </view>
- <!--按钮-->
- <view class="status-bar dir-top-wrap main-center">
- <!--喜欢-->
- <view
- class="item fav dir-top-wrap main-center cross-center"
- :class="{active: isFav}"
- @click="handleFavorite"
- >
- <u-icon name="heart-fill" size="58rpx" :color="isFav?$colors.primaryColor:$colors.defaultColor" />
- <text>{{ episode.user_favorite_count }}</text>
- </view>
- <!--收藏-->
- <view
- class="item collect dir-top-wrap main-center cross-center"
- :class="{active: isCollect}"
- @click="handleCollect"
- >
- <u-icon name="star-fill" size="58rpx" :color="isCollect?$colors.primaryColor:$colors.defaultColor" />
- <text>{{ episode.user_collect_count }}</text>
- </view>
- <!--分享-->
- <view class="item share dir-top-wrap main-center cross-center">
- <button open-type="share" />
- <u-icon name="share-fill" size="58rpx" :color="$colors.defaultColor" />
- <text>{{ episode.sahre_count }}</text>
- </view>
- </view>
- <!--视频播放-->
- <view class="video-box main-center cross-center" :style="{zIndex: isPlaying?0:998}">
- <!-- 控制按钮 - 播放 -->
- <view v-if="!isPlaying" class="play-layer main-center cross-center" @tap="handlePlay">
- <u-icon name="play-right-fill" size="100rpx" :color="$colors.defaultColor" />
- </view>
- <!-- 控制按钮 - 暂停 -->
- <view v-if="isPlaying" class="pause-layer" @tap="handlePause" />
- <!--进度条-->
- <view v-if="isPlaying" class="progress-container">
- <view class="progress" :style="{width: progress+'%'}" />
- </view>
- <!--视频容器-->
- <video
- id="video"
- :show-play-btn="video.playBtn"
- :show-fullscreen-btn="video.fullscreenBtn"
- :controls="video.controls"
- object-fit="contain"
- style="width: 100%;height: 100%;"
- :poster="episode.cover_img"
- :src="src"
- @timeupdate="timeupdate"
- />
- </view>
- <!--底部-->
- <view class="footer" :class="{episode: footerShow}">
- <view class="bar main-between cross-center" @click="footerShow = !footerShow">
- <view class="icon" />
- <view class="name">
- <u-text :text="episode.name" :color="$colors.infoColor" :lines="1" />
- <!-- <u-text text="321313" :color="$colors.infoColor" :lines="1" />-->
- </view>
- <view class="arrow">
- <u-icon name="arrow-up" :color="$colors.infoColor" size="32rpx" />
- </view>
- </view>
- <view class="episode-container dir-top-wrap">
- <!--分集 横向滚动-->
- <scroll-view
- class="header-box dir-left-nowrap cross-center"
- scroll-x
- scroll-with-animation
- >
- <view
- v-for="(item,index) in episodes"
- :key="index"
- class="header-item"
- :class="{active: episodesIndex === index}"
- @click="episodesIndex=index"
- >{{ item.title }}</view>
- </scroll-view>
- <!--几集选择-->
- <view class="content dir-left-wrap main-left">
- <view
- v-for="(item, index) in episodes[episodesIndex].lists"
- :key="index"
- class="episode-item"
- @click="handleSelectEpisode(item.index)"
- >
- <image :src="episode.cover_img" />
- <text>第{{ item.sort }}集</text>
- <view v-if="activeIndex === item.index && isPlaying" class="playing" />
- <view v-if="!item.is_free && buyRecord.indexOf(item.id) === -1" class="lock main-center cross-center">
- <u-icon name="lock-fill" :color="$colors.defaultColor" size="46rpx" />
- </view>
- </view>
- </view>
- </view>
- </view>
- <!--toast-->
- <view
- v-if="toast.show"
- class="toast dir-top-wrap main-center cross-center"
- :class="toast.status"
- >
- <u-icon
- :name="toast.status === 'success' ? 'checkmark-circle' : 'close-circle'"
- :color="toast.status === 'success' ? $colors.primaryColor : $colors.defaultColor"
- size="80rpx"
- />
- <text>{{ toast.text }}</text>
- </view>
- <!--购买弹窗-->
- <u-modal
- :show="modal.show"
- :content="`确定购买【第${modal.item.sort}集】?`"
- show-cancel-button
- @confirm="handleBuy"
- @cancel="modal.show = false"
- />
- <!--充值-->
- <recharge
- :show.sync="rechargeShow"
- type="play"
- mode="bottom"
- :episode="episode"
- :list="modal.item"
- />
- </template>
- </view>
- </template>
- <script>
- import { mapState } from 'vuex'
- import Recharge from '../../components/Recharge/index'
- export default {
- name: 'Play',
- components: { Recharge },
- data() {
- return {
- id: null,
- listId: null,
- isPlaying: false,
- videoContext: null,
- progress: 0,
- episode: null,
- activeIndex: 0,
- loading: true,
- isCollect: false,
- isFav: false,
- video: {
- controls: false,
- fullscreenBtn: false,
- playBtn: false
- },
- toast: {
- status: 'success',
- text: '收藏成功',
- show: false
- },
- footerShow: false,
- episodesIndex: 0,
- buyRecord: [],
- modal: {
- show: false,
- item: {}
- },
- rechargeShow: false
- }
- },
- computed: {
- ...mapState({
- userInfo: seate => seate.user.info
- }),
- src() {
- if (!this.episode) return ''
- return this.episode.lists[this.activeIndex].url
- },
- episodes() {
- const list = []
- if (this.episode) {
- let temp = []
- this.episode.lists.forEach((obj, index) => {
- obj.index = index
- temp.push(obj)
- if (temp.length === 6 || index === (this.episode.lists.length - 1)) {
- const start = list.length ? (list.length * 6) + 1 : 1
- const end = (start - 1) + temp.length
- list.push({ title: `${start}集-${end}集`, lists: temp })
- temp = []
- }
- })
- }
- return list
- }
- },
- watch: {
- 'toast.show'(val) {
- if (val) {
- setTimeout(() => {
- this.toast.show = false
- }, 1000)
- }
- }
- },
- methods: {
- // 播放进度
- timeupdate({ detail }) {
- // currentTime, duration
- if (detail.duration) {
- this.progress = (detail.currentTime / detail.duration * 100).toFixed(2)
- }
- },
- // 播放
- handlePlay() {
- const item = this.episode.lists[this.activeIndex]
- this.modal.item = item
- // 检查是否购买
- if (!this.checkBeforePlay(item)) {
- // 余额是否购买
- if (!this.checkOverage(item)) {
- this.rechargeShow = true
- return
- }
- this.modal.show = true
- this.footerShow = true
- return
- }
- this.isPlaying = true
- this.videoContext.play()
- this.watched(this.id, this.listId)
- },
- // 暂停
- handlePause() {
- if (!this.isPlaying) return
- this.isPlaying = false
- this.videoContext.pause()
- },
- // 选择剧集
- handleSelectEpisode(index) {
- const item = this.episode.lists[index]
- this.modal.item = item
- // 检查是否购买
- if (!this.checkBeforePlay(item)) {
- // 余额是否购买
- if (!this.checkOverage(item)) {
- this.rechargeShow = true
- return
- }
- this.modal.show = true
- return
- }
- this.activeIndex = index
- this.footerShow = false
- this.$loading()
- setTimeout(() => {
- this.$hideLoading()
- this.isPlaying = true
- this.videoContext.play()
- this.watched(this.id, this.episode.lists[this.activeIndex].id)
- }, 1000)
- },
- // 获取剧集详情
- getEpisode() {
- this.loading = true
- this.$api.episode.detail(this.id).then(res => {
- this.loading = false
- this.episode = res.data
- if (this.listId) {
- this.episode.lists.forEach((obj, index) => {
- if (parseInt(this.listId) === parseInt(obj.id)) {
- this.activeIndex = index
- }
- })
- } else {
- this.listId = this.episode.lists[0].id
- }
- })
- },
- // 检查是否收藏当前剧集
- checkCollect() {
- this.$api.user.collect.check(this.id).then(res => {
- this.isCollect = res.data
- })
- },
- // 收藏相关 处理
- handleCollect() {
- const method = this.isCollect ? 'destroy' : 'add'
- const num = this.isCollect ? -1 : 1
- this.$api.user.collect[method](this.id).then(res => {
- if (res.data) {
- this.toast.show = true
- this.toast.status = this.isCollect ? 'cancel' : 'success'
- this.toast.text = this.isCollect ? '取消收藏' : '收藏成功'
- this.episode.user_collect_count += num
- this.isCollect = !this.isCollect
- }
- })
- },
- // 检查是否喜欢当前短剧
- checkFavorite() {
- this.$api.user.favorite.check(this.id).then(res => {
- this.isFav = res.data
- })
- },
- // 喜欢剧集 处理
- handleFavorite() {
- const method = this.isFav ? 'destroy' : 'add'
- const num = this.isFav ? -1 : 1
- this.$api.user.favorite[method](this.id).then(res => {
- if (res.data) {
- this.toast.show = true
- this.toast.status = this.isFav ? 'cancel' : 'success'
- this.toast.text = this.isFav ? '取消喜欢' : '喜欢成功'
- this.episode.user_favorite_count += num
- this.isFav = !this.isFav
- }
- })
- },
- // 观看记录
- watched(id, list_id) {
- this.$api.user.episode.watched(id, list_id).then(res => {
- })
- },
- // 分享
- shared(id, list_id) {
- this.$api.episode.shared(id, list_id).then(res => {
- this.episode.share_count += 1
- })
- },
- // 当前剧集购买记录
- async getBuyRecord() {
- await this.$api.user.episode.buyRecord(this.id).then(res => {
- this.buyRecord = res.data
- })
- },
- // 购买
- handleBuy() {
- this.$loading('购买中...')
- this.$api.user.episode.buyHandle(this.id, this.modal.item.id).then(res => {
- this.$hideLoading()
- if (typeof res.overage !== 'undefined') {
- this.rechargeShow = true
- } else {
- this.$u.toast('购买成功')
- this.modal.show = false
- this.getBuyRecord()
- this.$api.user.info().then(res => {
- this.$store.dispatch('user/info', res.data)
- })
- }
- }).catch(() => {
- this.$hideLoading()
- })
- },
- // 播放前检查是否购买/免费
- checkBeforePlay(item) {
- return item.is_free || (!item.is_free && this.buyRecord.indexOf(item.id) !== -1)
- },
- // 检查余额是否足够支付
- checkOverage(item) {
- return this.userInfo.info.integral >= item.sale_price
- }
- },
- async onLoad(options) {
- this.videoContext = uni.createVideoContext('video', this)
- this.id = options.id
- this.listId = options?.list_id
- await this.getBuyRecord()
- this.getEpisode()
- this.checkCollect()
- this.checkFavorite()
- },
- // 分享
- onShareAppMessage(res) {
- if (res.from === 'button') { // 来自页面内分享按钮
- console.log(res.target)
- }
- let options = {
- title: '',
- path: `/pages/episode/play?id=${this.id}`
- }
- if (this.episode) {
- options = {
- title: this.episode.name,
- path: `/pages/episode/play?id=${this.id}`,
- imageUrl: this.episode.cover_img,
- desc: this.episode.name,
- success: res => {
- this.shared(this.id, this.listId)
- }
- }
- }
- return options
- }
- }
- </script>
- <style lang="scss" scoped>
- .play-container {
- font-size: 28rpx;
- .video-box{
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .play-layer{
- position: fixed;
- top: 0;
- left: 0;
- bottom: 0;
- right: 0;
- background: transparent;
- z-index: 999;
- }
- .pause-layer{
- position: absolute;
- top: 0;
- left: 0;
- bottom: 0;
- right: 0;
- background: transparent;
- z-index: 99;
- }
- video{
- position: absolute;
- z-index: 98;
- }
- .progress-container{
- width: 93vw;
- background: #fff;
- height: 10rpx;
- position: fixed;
- z-index: 100;
- bottom: 160rpx;
- .progress{
- height: 10rpx;
- background: linear-gradient(270deg, #6EEBE8 0%, #FF74B9 100%);
- }
- }
- }
- .view-num{
- position: fixed;
- right: 20rpx;
- top: 40rpx;
- color: #fff;
- font-size: 26rpx;
- z-index: 100;
- text{
- margin-left: 10rpx;
- }
- }
- .status-bar{
- position: fixed;
- bottom: 300rpx;
- right: 40rpx;
- color: $default-color;
- z-index: 100;
- .item{
- margin-bottom: 40rpx;
- &.share{
- position: relative;
- button{
- position: absolute;
- background: transparent;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 1;
- &:after{
- content: unset;
- }
- }
- }
- &.active{
- color: $primary-color;
- }
- text{
- margin-top: 10rpx;
- }
- }
- }
- .footer{
- position: fixed;
- width: 95vw;
- height: 76rpx;
- background: rgba(24, 28, 47, 0.8);
- bottom: 50rpx;
- left: 50%;
- transform: translateX(-50%);
- font-size: 26rpx;
- color: $info-color;
- border-radius: 20rpx;
- z-index: 999;
- transition: .3s;
- &.episode{
- bottom: 700rpx;
- margin-top: -4rpx;
- border-bottom-left-radius: 0;
- border-bottom-right-radius: 0;
- .episode-container{
- display: flex;
- margin-top: -4rpx;
- border-bottom-left-radius: 20px;
- border-bottom-right-radius: 20px;
- }
- .bar{
- .arrow{
- transform: rotate(180deg);
- }
- }
- }
- .bar{
- padding: 0 20rpx;
- .icon{
- background: url("/static/image/video.png") no-repeat center;
- background-size: 70%;
- width: 80rpx;
- height: 80rpx;
- }
- .name{
- text-align: left;
- flex: 1;
- padding: 0 30rpx;
- }
- .arrow{
- transition: .3s;
- }
- }
- .episode-container{
- display: none;
- background: inherit;
- .header-box{
- white-space: nowrap;
- margin: 20rpx 0;
- .header-item{
- margin-right: 20rpx;
- border-radius: 20rpx;
- display: inline-block;
- width: 200rpx;
- border: 1rpx solid $default-color;
- text-align: center;
- padding: 10rpx 0;
- color: $default-color;
- &.active{
- border-color: $primary-color;
- color: $primary-color;
- }
- }
- }
- .content{
- margin-top: 20rpx;
- .episode-item{
- position: relative;
- width: calc((100% - #{40rpx}) / 3);
- margin-right: 20rpx;
- margin-bottom: 20rpx;
- overflow: hidden;
- border-radius: 18rpx;
- &:nth-child(3n){
- margin-right: 0;
- }
- .playing{
- position: absolute;
- top: 0;
- left: 0;
- bottom: 0;
- right: 0;
- background: rgba(0,0,0,.5) url("/static/image/playing.png") no-repeat center;
- background-size: 40rpx;
- z-index: 2;
- }
- image{
- width: 100%;
- height: 260rpx;
- }
- text{
- position: absolute;
- left: 0;
- bottom: 0;
- right: 0;
- color: $default-color;
- padding: 20rpx 0;
- text-align: center;
- background: rgba(0,0,0,.3);
- z-index: 1;
- }
- .lock{
- position: absolute;
- top: 0;
- left: 0;
- bottom: 0;
- right: 0;
- background: rgba(0,0,0,.5);
- z-index: 2;
- }
- }
- }
- }
- }
- .toast{
- position: fixed;
- width: 60vw;
- background: rgba(0,0,0,.5);
- height: 300rpx;
- top: 50%;
- left: 50%;
- transform: translate(-50%,-50%);
- border-radius: 20rpx;
- font-size: 36rpx;
- color: $default-color;
- &.success{
- color: $primary-color;
- }
- text{
- margin-top: 20rpx;
- }
- }
- }
- </style>
|