瀏覽代碼

feat: 首页

xiansin 2 年之前
父節點
當前提交
92f7961fe6

+ 9 - 9
mini/api/episode.js

xqd
@@ -1,25 +1,25 @@
 const request = uni.$u.http
 
-export function tabBar() {
+export function recommend() {
   return request.get(
-    'setting/navBar'
+    'episode/recommend'
   )
 }
 
-export async function navBar() {
+export async function news() {
   return request.get(
-    'setting/navBar'
+    'episode/news'
   )
 }
 
-export async function banner() {
+export async function rank() {
   return request.get(
-    'setting/banner'
+    'episode/rank'
   )
 }
 
 export default {
-  tabBar,
-  navBar,
-  banner
+  recommend,
+  news,
+  rank
 }

+ 3 - 2
mini/components/Episode/index.vue

xqd xqd xqd
@@ -4,7 +4,7 @@
       <view v-if="rank" class="rank" :class="{first: rank === 1}">
         <text>1</text>
       </view>
-      <image src="@/static/image/default-movie.png" mode="aspectFill" :style="[imageStyle]" />
+      <image :src="episode.cover_img" mode="aspectFill" :style="[imageStyle]" />
       <view v-if="recent" class="special">最近播放 </view>
       <view v-if="guess" class="special guess">猜你喜欢 </view>
     </view>
@@ -17,7 +17,7 @@
     />
     <view class="status-box dir-left-nowrap">
       <u-text
-        :text="episode.status"
+        :text="episode.status_text"
         :lines="1"
         size="24rpx"
         :custom-style="{flex: 'unset'}"
@@ -27,6 +27,7 @@
         :text="`共${episode.total}集`"
         :lines="1"
         size="24rpx"
+        margin="0 0 0 10rpx"
         :color="$colors.infoColor"
       />
     </view>

+ 62 - 17
mini/pages/index/components/EpisodeBox.vue

xqd xqd xqd xqd
@@ -2,22 +2,33 @@
   <view class="episode-box">
     <view class="header-box main-between cross-center">
       <text class="title">{{ title }}</text>
-      <view class="refresh main-left cross-center">
+      <view class="refresh main-left cross-center" @click="handleRefresh">
         <text>换一批</text>
         <view class="icon">
           <u-icon name="reload" size="32rpx" bold />
         </view>
       </view>
     </view>
-    <view class="container dir-left-wrap">
-      <episode
-        v-for="(episode,index) in episodes"
-        :key="index"
-        :episode="episode"
-        :custom-style="{
-          marginRight: ((index+1) % 3 !== 0 ? '20rpx' :''),
-        }"
-      />
+    <view
+      class="container dir-left-wrap"
+      :class="{
+        loading: loading,
+        'main-center':loading,
+        'cross-center': loading
+      }"
+    >
+      <u-loading-icon :show="loading" vertical />
+      <template v-if="episodes.length && !loading">
+        <episode
+          v-for="(episode,index) in episodes"
+          :key="index"
+          :episode="episode"
+          :guess="episode.guess"
+          :custom-style="{
+            marginRight: ((index+1) % 3 !== 0 ? '20rpx' :''),
+          }"
+        />
+      </template>
     </view>
   </view>
 </template>
@@ -25,6 +36,7 @@
 <script>
 import UIcon from '../../../uni_modules/uview-ui/components/u-icon/u-icon'
 import Episode from '../../../components/Episode/index'
+import { recommend } from '../../../api/episode'
 export default {
   name: 'EpisodeBox',
   components: { Episode, UIcon },
@@ -32,20 +44,50 @@ export default {
     title: {
       type: String,
       required: true
+    },
+    type: {
+      type: String,
+      required: true
     }
   },
   data() {
     return {
-      episodes: [
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 }
-      ]
+      loading: false,
+      episodes: []
     }
   },
   computed: {},
-  methods: {}
+  created() {
+    this.handleRefresh()
+  },
+  methods: {
+    getRecommend() {
+      this.loading = true
+      this.$api.episode.recommend().then(res => {
+        this.loading = false
+        this.episodes = res.data
+      })
+    },
+    getNews() {
+      this.loading = true
+      this.$api.episode.news().then(res => {
+        this.loading = false
+        this.episodes = res.data
+      })
+    },
+    getRank() {
+      this.loading = true
+      this.$api.episode.rank().then(res => {
+        this.loading = false
+        this.episodes = res.data
+      })
+    },
+    handleRefresh() {
+      this.type === 'recommend' && this.getRecommend()
+      this.type === 'news' && this.getNews()
+      this.type === 'rank' && this.getRank()
+    }
+  }
 }
 </script>
 
@@ -68,6 +110,9 @@ export default {
       }
       .container{
         margin-top: 30rpx;
+        min-height: 458rpx;
+        &.loading{
+        }
       }
     }
 </style>

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

xqd
@@ -28,9 +28,9 @@
     <!--栏目分类-->
     <nav-bar />
     <!--分类-->
-    <episode-box title="短剧推荐" />
-    <episode-box title="最新热剧" />
-    <episode-box title="排行榜" />
+    <episode-box title="短剧推荐" type="recommend" />
+    <episode-box title="最新热剧" type="news" />
+    <episode-box title="排行榜" type="rank" />
     <!--tab bar-->
     <tab-bar />
   </view>

+ 0 - 1
mini/pages/my/index.vue

xqd
@@ -56,7 +56,6 @@
         </view>
         <u-icon name="arrow-right" :color="$colors.infoColor" bold />
       </button>
-      <vedio se />
     </view>
     <!--tab bar-->
     <tab-bar />

+ 47 - 3
server/app/Http/Controllers/V1/EpisodeController.php

xqd xqd xqd
@@ -17,15 +17,28 @@ class EpisodeController extends Controller
     public function recommend()
     {
         // 七天内看的随机一条
-        $history = UserWatchRecord::with(['episode'])
+        $history = UserWatchRecord::with(['episode.lists'])
             ->inRandomOrder()
             ->where('user_id', \user()->id)
             ->where('created_at','>=', Carbon::now()->subDays(7)->toDateTime())
             ->first();
         $limit = 3 - collect($history)->count();
-        $episode = Episode::where('is_opend', 1)->limit($limit)->get()->toArray();
-        dd($episode);
+        $episodes = Episode::withCount(['lists'])
+            ->where('is_opend', 1)
+            ->where('platform', \user()->info->platform)
+            ->limit($limit)
+            ->get();
 
+        $lists = [];
+        /* @var Episode $episode*/
+        foreach ($episodes as $episode){
+            $episode->status_text = $episode->status;
+            $episode->total = $episode->lists_count;
+            $episode->guess = true;
+            $lists[] = $episode;
+        }
+
+        return $this->success($lists);
     }
 
 
@@ -34,7 +47,23 @@ class EpisodeController extends Controller
      */
     public function news()
     {
+        $episodes = Episode::withCount(['lists'])
+            ->where('is_opend', 1)
+            ->where('platform', \user()->info->platform)
+            ->inRandomOrder()
+            ->orderByDesc('id')
+            ->limit(3)
+            ->get();
 
+        $lists = [];
+        /* @var Episode $episode*/
+        foreach ($episodes as $episode){
+            $episode->status_text = $episode->status;
+            $episode->total = $episode->lists_count;
+            $lists[] = $episode;
+        }
+
+        return $this->success($lists);
     }
 
 
@@ -43,6 +72,21 @@ class EpisodeController extends Controller
      */
     public function rank()
     {
+        $episodes = Episode::withCount(['userEpisodesRecords','lists'])
+            ->where('is_opend', 1)
+            ->where('platform', \user()->info->platform)
+            ->orderByDesc('user_episodes_records_count')
+            ->limit(3)
+            ->get();
+
+        $lists = [];
+        /* @var Episode $episode*/
+        foreach ($episodes as $episode){
+            $episode->status_text = $episode->status;
+            $episode->total = $episode->lists_count;
+            $lists[] = $episode;
+        }
 
+        return $this->success($lists);
     }
 }

+ 8 - 1
server/app/Models/Episode.php

xqd xqd xqd
@@ -26,6 +26,7 @@ use Illuminate\Database\Eloquent\Model;
  * @property \Illuminate\Support\Carbon|null $created_at
  * @property-read \App\Models\EpisodesCategory|null $category
  * @property-read \App\Models\EpisodesList|null $lists
+ *@property-read int|null $lists_count
  * @method static \Illuminate\Database\Eloquent\Builder|Episode newModelQuery()
  * @method static \Illuminate\Database\Eloquent\Builder|Episode newQuery()
  * @method static \Illuminate\Database\Query\Builder|Episode onlyTrashed()
@@ -51,6 +52,7 @@ use Illuminate\Database\Eloquent\Model;
  * @property-read int|null $user_episodes_records_count
  * @method static \Illuminate\Database\Eloquent\Builder|Episode wherePlatform($value)
  * @property-write mixed $status_text
+ * @property-write mixed $total
  */
 class Episode extends Model
 {
@@ -73,8 +75,13 @@ class Episode extends Model
         $this->attributes['status_text'] = $config[$value]??'未知';
     }
 
+    public function setTotalAttribute($value)
+    {
+        $this->attributes['total'] = $value;
+    }
+
     public function userEpisodesRecords()
     {
-        return $this->hasMany(UserEpisodesRecord::class,'episodes_id','id');
+        return $this->belongsTo(UserEpisodesRecord::class,'id','episodes_id');
     }
 }