|
|
@@ -8,7 +8,7 @@
|
|
|
class="w-full h-full"
|
|
|
virtual
|
|
|
direction="vertical"
|
|
|
- :initialSlide="0"
|
|
|
+ :initialSlide="initialSlide"
|
|
|
:slides-per-view="1"
|
|
|
:space-between="0"
|
|
|
:pagination="true"
|
|
|
@@ -35,11 +35,13 @@
|
|
|
:episode="item"
|
|
|
:episodes="episodes"
|
|
|
:saved="saved"
|
|
|
+ :ref="(el) => (playViews[item.id] = el)"
|
|
|
@save="save"
|
|
|
@choose-episode="onChooseEpisode"
|
|
|
@ended="next"
|
|
|
@pay="showPayModal = true"
|
|
|
@share="showShareModal = true"
|
|
|
+ @progress="saveHistory"
|
|
|
/>
|
|
|
</swiper-slide>
|
|
|
</VueSwiper>
|
|
|
@@ -165,10 +167,10 @@ import {
|
|
|
} from "swiper/modules";
|
|
|
import PlayView from "@/components/PlayView.vue";
|
|
|
import { nextTick, onMounted, reactive, ref } from "vue";
|
|
|
-import { useElementBounding } from "@vueuse/core";
|
|
|
+import { useElementBounding, useLocalStorage } from "@vueuse/core";
|
|
|
import { useRoute } from "vue-router";
|
|
|
import http from "@/plugins/http";
|
|
|
-import { close, chevronBack } from "ionicons/icons";
|
|
|
+import { close, chevronBack, key } from "ionicons/icons";
|
|
|
import toast from "@/plugins/toast";
|
|
|
import { useUserStore } from "@/store/user";
|
|
|
import { storeToRefs } from "pinia";
|
|
|
@@ -179,7 +181,7 @@ const { user } = storeToRefs(useUserStore());
|
|
|
const el = ref<HTMLElement | null>(null);
|
|
|
const { x, y, top, right, bottom, left, width, height } =
|
|
|
useElementBounding(el);
|
|
|
-
|
|
|
+const initialSlide = ref(0);
|
|
|
const swiper = ref<Swiper | null>(null);
|
|
|
const onSwiper = (sw: Swiper) => {
|
|
|
window.swiper = swiper.value = sw;
|
|
|
@@ -188,10 +190,11 @@ const activeSlide = ref(0);
|
|
|
|
|
|
const route = useRoute();
|
|
|
const router = useIonRouter();
|
|
|
-const seriesId = route.params.id;
|
|
|
+const seriesId = route.params.id as string;
|
|
|
const series = ref<any>(null);
|
|
|
const episodes = ref<any[]>([]);
|
|
|
-
|
|
|
+const historyStore = useLocalStorage<any>("playHistories", {});
|
|
|
+const playViews = ref<{ [key: string | number]: any }>({});
|
|
|
onMounted(() => {
|
|
|
http.get(`/series/${seriesId}`).then((res) => {
|
|
|
series.value = res;
|
|
|
@@ -201,8 +204,29 @@ onMounted(() => {
|
|
|
pageSize: 1000,
|
|
|
}).then((res) => {
|
|
|
episodes.value = res.data;
|
|
|
+ const history = historyStore.value[seriesId];
|
|
|
+ if (history) {
|
|
|
+ console.log("found history", historyStore.value[seriesId]);
|
|
|
+ const index = episodes.value.findIndex(
|
|
|
+ (e) => e.id === history.episodeId
|
|
|
+ );
|
|
|
+ if (index !== -1) {
|
|
|
+ initialSlide.value = index;
|
|
|
+ }
|
|
|
+ }
|
|
|
nextTick(() => {
|
|
|
swiper.value?.update();
|
|
|
+ if (initialSlide.value > 0) {
|
|
|
+ console.log("slide to", initialSlide.value);
|
|
|
+ swiper.value?.slideTo(initialSlide.value, 0);
|
|
|
+ }
|
|
|
+ if (history) {
|
|
|
+ const playView =
|
|
|
+ playViews.value[episodes.value[initialSlide.value].id];
|
|
|
+ if (playView) {
|
|
|
+ playView.seek(history.duration);
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
@@ -297,6 +321,18 @@ function onClickPay() {
|
|
|
}
|
|
|
|
|
|
const showShareModal = ref(false);
|
|
|
+
|
|
|
+function saveHistory(e: {
|
|
|
+ seriesId: number;
|
|
|
+ episodeId: number;
|
|
|
+ duration: number;
|
|
|
+}) {
|
|
|
+ http.post("/playHistories", e);
|
|
|
+ historyStore.value[e.seriesId + ""] = {
|
|
|
+ episodeId: e.episodeId,
|
|
|
+ duration: e.duration,
|
|
|
+ };
|
|
|
+}
|
|
|
</script>
|
|
|
<style lang="less" scoped>
|
|
|
.pay-modal {
|