Pārlūkot izejas kodu

feat: 优化剧集相关

xiansin 2 gadi atpakaļ
vecāks
revīzija
3bb28ae8d5

+ 6 - 0
mini/api/episode.js

xqd
@@ -30,6 +30,12 @@ export function trace() {
   )
 }
 
+export function shared(id) {
+  return request.post(
+    `episode/shared/${id}`
+  )
+}
+
 export default {
   recommend,
   news,

+ 60 - 10
mini/pages/episode/play.vue

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -38,7 +38,7 @@
         </view>
       </view>
       <!--视频播放-->
-      <view class="video-box main-center cross-center">
+      <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" />
@@ -58,6 +58,7 @@
           style="width: 100%;height: 100%;"
           :poster="episode.cover_img"
           :src="src"
+          @binderror="binderror"
           @timeupdate="timeupdate"
         />
       </view>
@@ -92,11 +93,12 @@
               v-for="(item, index) in episodes[episodesIndex].lists"
               :key="index"
               class="episode-item"
-              @click="activeIndex = item.index"
+              @click="handleSelectEpisode(item.index)"
             >
               <image :src="episode.cover_img" />
               <text>第{{ item.sort }}集</text>
-              <view class="lock main-center cross-center">
+              <view v-if="activeIndex === item.index" class="playing" />
+              <view v-if="!item.is_free" class="lock main-center cross-center">
                 <u-icon name="lock-fill" :color="$colors.defaultColor" size="46rpx" />
               </view>
             </view>
@@ -173,7 +175,6 @@ export default {
   },
   watch: {
     'toast.show'(val) {
-      console.log('-->data1', val)
       if (val) {
         setTimeout(() => {
           this.toast.show = false
@@ -191,6 +192,18 @@ export default {
     handlePlay() {
       this.isPlaying = true
       this.videoContext.play()
+      this.watched(this.id, this.listId)
+    },
+    handleSelectEpisode(index) {
+      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)
     },
     handlePause() {
       if (!this.isPlaying) return
@@ -202,16 +215,17 @@ export default {
       this.$api.episode.detail(this.id).then(res => {
         this.loading = false
         this.episode = res.data
+        console.log('-->data', this.listId)
         if (this.listId) {
           this.episode.lists.forEach((obj, index) => {
-            if (parseInt(this.listId) === obj.id) {
+            if (parseInt(this.listId) === parseInt(obj.id)) {
               this.activeIndex = index
+              console.log('-->data', this.activeIndex)
             }
           })
         } else {
           this.listId = this.episode.lists[0].id
         }
-        this.watched(this.id, this.listId)
       })
     },
     checkCollect() {
@@ -254,15 +268,41 @@ export default {
       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
+      })
     }
   },
   onLoad(options) {
     this.videoContext = uni.createVideoContext('video', this)
     this.id = options.id
-    this.listId = options?.list_Id
+    this.listId = options?.list_id
     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() {
+
+        }
+      }
+    }
+    return options
   }
 }
 </script>
@@ -366,7 +406,7 @@ export default {
         font-size: 26rpx;
         color: $info-color;
         border-radius: 20rpx;
-        z-index: 100;
+        z-index: 999;
         transition: .3s;
         &.episode{
           bottom: 700rpx;
@@ -436,6 +476,16 @@ export default {
               &: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;
@@ -448,7 +498,7 @@ export default {
                 color: $default-color;
                 padding: 20rpx 0;
                 text-align: center;
-                background: rgba(0,0,0,.5);
+                background: rgba(0,0,0,.3);
                 z-index: 1;
               }
               .lock{
@@ -457,7 +507,7 @@ export default {
                 left: 0;
                 bottom: 0;
                 right: 0;
-                background: rgba(0,0,0,.7);
+                background: rgba(0,0,0,.5);
                 z-index: 2;
               }
             }

+ 2 - 1
mini/pages/index/components/Recent.vue

xqd xqd
@@ -4,7 +4,7 @@
       <u-icon name="close-circle" :color="$colors.primaryColor" size="54rpx" />
     </view>
     <view class="cover-image">
-      <image src="@/static/image/default-movie.png" mode="aspectFill" />
+      <image :src="recent.detail.episode.cover_img" mode="aspectFill" />
     </view>
     <view class="info">
       <text class="name">{{ recent.detail.episode.name }}</text>
@@ -32,6 +32,7 @@ export default {
   },
   methods: {
     handlePlay(item) {
+      this.show = false
       this.$u.route({
         url: '/pages/episode/play',
         params: {

+ 5 - 3
mini/pages/my/index.vue

xqd xqd xqd
@@ -27,7 +27,7 @@
         <text>历史观看记录</text>
         <u-icon name="arrow-right" :color="$colors.infoColor" bold />
       </view>
-      <view class="content main-between cross-center">
+      <view class="content dir-left-nowrap cross-center">
         <view
           v-for="(item,index) in history"
           :key="index"
@@ -108,6 +108,8 @@ export default {
           this.$api.user.update(params).then(res => {
             this.$hideLoading()
             this.$store.dispatch('user/info', res.data)
+          }).catch(err => {
+            this.$hideLoading()
           })
         }
       })
@@ -194,14 +196,14 @@ export default {
       .content{
         margin-top: 20rpx;
         .episode{
-          flex: 1;
+          width: calc(100%/4);
           margin-left: 20rpx;
           &:first-child{
             margin-left: 0;
           }
           .cover-image{
             image{
-              width: calc(100%/4);
+              width: 100%;
               height: 200rpx;
             }
           }

BIN
mini/static/image/playing.png


+ 1 - 0
server/app/Admin/Actions/Grid/BatchEditEpisode.php

xqd
@@ -20,6 +20,7 @@ class BatchEditEpisode extends BatchAction
 
 
 
+
     public function render()
     {
         $form = BatchEditEpisodeForm::make();

+ 3 - 1
server/app/Admin/Controllers/Episode/EpisodeController.php

xqd xqd
@@ -41,7 +41,7 @@ class EpisodeController extends AdminController
             $grid->actions(function (Grid\Displayers\Actions $actions) {
                 $id = $actions->getKey();
                 // append一个操作
-                $actions->append('<a href="/admin/episodes/'.$id.'/lists"><i class="fa fa-upload"></i> 上传剧集</a>');
+                $actions->append('<a href="/admin/episodes/'.$id.'/lists"><i class="fa fa-upload"></i> 剧集管理</a>');
             });
 
             $grid->filter(function (Grid\Filter $filter) {
@@ -58,6 +58,8 @@ class EpisodeController extends AdminController
                 $filter->between('created_at','添加时间')->datetime()->width(4);
 
             });
+
+            $grid->disableViewButton();
         });
     }
 

+ 12 - 5
server/app/Admin/Controllers/Episode/EpisodesListController.php

xqd xqd
@@ -46,13 +46,20 @@ class EpisodesListController extends AdminController
             ->body($this->form());
     }
 
+
+    public function update($episodeId, $id = 0)
+    {
+        $this->episode = Episode::find($episodeId);
+        return $this->form()->update($id);
+    }
+
     public function store($episodeId = 0)
     {
         $this->episode = Episode::find($episodeId);
         return $this->form()->store();
     }
 
-    public function edit($id, Content $content, $episodeId = 0)
+    public function edit($episodeId, Content $content, $id = 0)
     {
         return $this->content($content,$episodeId)
             ->body($this->form()->edit($id));
@@ -66,19 +73,19 @@ class EpisodesListController extends AdminController
     protected function grid()
     {
         return Grid::make(EpisodesList::with(['episode'])->where('episodes_id', $this->episode->id), function (Grid $grid) {
-            $grid->column('id')->sortable();
-            $grid->column('episode.name','剧集名称');
+            //$grid->column('id');
             $grid->column('sort')->display(function (){
                 return '第'.$this->sort.'集';
             })->editable();
+            $grid->column('episode.name','剧集名称');
             $grid->column('is_free')
                 ->using(config('global.episode_free'))
                 ->label(['success', 'primary'])->sortable();
             $grid->column('sale_price')->editable();
             $grid->column('url')->display(function (){
-                return '<video src="'.$this->url.'" width="200" controls></vedio>';
+                return '<a href="'.$this->url.'">视频链接</a>';
             });
-
+            $grid->hideColumns(['id']);
             $grid->batchActions([new BatchEditEpisode()]);
             $grid->disableViewButton();
         });

+ 1 - 0
server/app/Admin/Controllers/UserController.php

xqd
@@ -53,6 +53,7 @@ class UserController extends AdminController
             $grid->disableCreateButton();
             $grid->disableDeleteButton();
             $grid->disableRowSelector();
+            $grid->disableViewButton();
         });
     }
 

+ 12 - 1
server/app/Http/Controllers/V1/EpisodeController.php

xqd
@@ -158,11 +158,22 @@ class EpisodeController extends Controller
     public function detail($id)
     {
         $episodes = Episode::withCount(['userWatchRecord','userCollect','userFavorite','lists'])
-            ->with(['category:id,name','lists:id,episodes_id,sort,url'])
+            ->with(['category:id,name','lists:id,episodes_id,sort,url,is_free,sale_price'])
             ->where('is_opend', 1)
             ->where('id', $id)
             ->where('platform', \user()->info->platform)
             ->first();
         return $this->success($episodes);
     }
+
+    public function shared($id)
+    {
+        $res = Episode::find($id);
+        if(!$res){
+            return $this->success();
+        }
+        $res->share_count =  $res->share_count + 1;
+        $res->save();
+        return $this->success();
+    }
 }

+ 2 - 1
server/app/Http/Controllers/V1/User/WatchRecordsController.php

xqd
@@ -27,7 +27,8 @@ class WatchRecordsController extends Controller
     {
         $info = UserWatchRecord::filterUser()
             ->with(['detail.episode'])
-            ->orderByDesc('id')->first();
+            ->orderByDesc('updated_at')
+            ->first();
         $count = $info->detail->episode->withCount('lists')->first()->toArray();
         $info->detail->episode->total = $count['lists_count'];
         $info->detail->episode->status_text = $info->detail->episode->status;

+ 4 - 0
server/app/Models/Episode.php

xqd
@@ -67,6 +67,10 @@ class Episode extends Model
         'updated_at','deleted_at'
     ];
 
+    protected $casts = [
+        'share_count' => 'integer'
+    ];
+
     public function category()
     {
         return $this->belongsTo(EpisodesCategory::class,'category_id','id');

+ 4 - 0
server/app/Models/EpisodesList.php

xqd
@@ -43,6 +43,10 @@ class EpisodesList extends Model
         'updated_at','deleted_at'
     ];
 
+    protected $casts = [
+        'sale_price' => 'integer'
+    ];
+
     public function episode()
     {
         return $this->belongsTo(Episode::class,'episodes_id','id');

+ 1 - 1
server/resources/lang/zh/episode.php

xqd
@@ -2,7 +2,7 @@
 return [
     'labels'  => [
         'episodes' => '剧集',
-        'lists' => '列表',
+        'index' => '列表',
         'Episode' => '剧集',
         'episode' => '剧集',
     ],