gemercheung 1 سال پیش
والد
کامیت
b4d3572412
11فایلهای تغییر یافته به همراه1127 افزوده شده و 1068 حذف شده
  1. 2 0
      .env.development
  2. 1 0
      .env.production
  3. 2 1
      index.html
  4. 977 964
      src/assets/style/index.css
  5. 2 2
      src/assets/style/section1.css
  6. 14 4
      src/pages/section3.vue
  7. 1 1
      src/pages/section4.vue
  8. 1 1
      src/pages/section5.vue
  9. 77 48
      src/utils/canvasPlayer.js
  10. 3 3
      src/utils/loadImg.js
  11. 47 44
      vite.config.js

+ 2 - 0
.env.development

@@ -0,0 +1,2 @@
+
+VITE_PUBLIC_DIR="/"

+ 1 - 0
.env.production

@@ -0,0 +1 @@
+VITE_PUBLIC_DIR="./"

+ 2 - 1
index.html

@@ -5,7 +5,8 @@
     <link rel="icon" type="image/svg+xml" href="/vite.svg" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <title>玉润中华--南京博物院特展</title>
-
+    <script src="https://4dkk.4dage.com/v4-test/www/viewer/static/lib/vconsole.js"></script>
+  
   </head>
   <body>
     <div id="app"></div>

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 977 - 964
src/assets/style/index.css


+ 2 - 2
src/assets/style/section1.css

@@ -29,7 +29,7 @@
     height: 6.375rem;
     margin-bottom: 1.5rem;
     display: block;
-    background: url(../img/webp/section1/logo.webp) no-repeat center/cover;
+    background: url(/img/section1/logo.webp) no-repeat center/cover;
   }
   .section1 .title1 {
     z-index: 1;
@@ -60,7 +60,7 @@
     left: 0;
     width: 100%;
     height: 100%;
-    background: url(../img/webp/section1/section1-title.webp) no-repeat center/contain;
+    background: url(#/img/section1/section1-title.webp) no-repeat center/contain;
   }
   .section1 .txt {
     text-align: center;

+ 14 - 4
src/pages/section3.vue

@@ -63,9 +63,10 @@ const setting = [
     className: ["canvas", ".scroll-container", ".section3 .fp-scrollable"],
     canvas: null,
     context: null,
-    imageUrl: "./img/canvas/pc1",
+    imageUrl: isMobile() ? "./img/canvas/pc1_mo" : "./img/canvas/pc1",
     dots: [],
-    total: isMobile() ? 977 : 331,
+    // total: isMobile() ? 900 : 300,
+        total: isMobile() ? 900 : 331,
     CA: [
       {
         name: "#videocont1-1",
@@ -153,11 +154,16 @@ const isShowCanvas = ref(false);
 
 const handler = ({ index: currentIndex, nextIndex }) => {
   const { index } = nextIndex;
+  const { index: pre } = currentIndex;
   if (index === 2) {
-    console.log("fullpage", props.fullpage.api);
+    // console.log("currentIndex", currentIndex);
     props.fullpage.api.setAllowScrolling(false);
     player.enableScroll(3);
-    player.autoPlay(0, 60);
+
+    if (pre === 1) {
+      player.autoPlay(0, 60);
+    }
+
     isShowCanvas.value = true;
   } else {
     player.unEnableScroll();
@@ -167,6 +173,10 @@ const handler = ({ index: currentIndex, nextIndex }) => {
 };
 const process = ref(0);
 onMounted(() => {
+  if (isMobile()) {
+    var vcon = new window.VConsole();
+  }
+
   emitter.on("onLeave", handler);
   player.init();
   player.on("loaded", () => {

+ 1 - 1
src/pages/section4.vue

@@ -30,7 +30,7 @@
 }
 .chapter {
   justify-content: flex-start;
-  background-image: url(/img/webp/chapterunit/chapter-bg.webp);
+  background-image: url(/img/chapterunit/chapter-bg.webp);
   .box {
     display: -webkit-box;
     display: -ms-flexbox;

+ 1 - 1
src/pages/section5.vue

@@ -30,7 +30,7 @@
 }
 
 .unit {
-  background-image: url(/img/webp/chapterunit/unit-bg.webp);
+  background-image: url(/img/chapterunit/unit-bg.webp);
 }
 .unit .box {
   padding-top: 15vh;

+ 77 - 48
src/utils/canvasPlayer.js

@@ -29,6 +29,11 @@ export class CanvasPlayer extends Mitt {
     this.frames = [];
     this.clips = [];
     this.canScroll = false;
+    this.isInit = [];
+    this.matchDis = 10;
+    this.mainScrolltimer = null;
+    this.mainScrollfinishTimer = null;
+    this.isScrollDoneTime = isMobile() ? 300 : 200;
     this.resize = this.resize.bind(this);
     this.watchScroll = this.watchScroll.bind(this);
   }
@@ -80,10 +85,7 @@ export class CanvasPlayer extends Mitt {
         for (let key = 0; key < item.total; key++) {
           const padLength = item.total.toString().length + 1;
           let imgIndex = String(key).padStart(padLength, "0");
-          isMobile();
-          let url = isMobile()
-            ? `${item.imageUrl}_mo/${imgIndex}.webp`
-            : `${item.imageUrl}/${imgIndex}.webp`;
+          let url = `${item.imageUrl}/${imgIndex}.webp`;
           const res = this.loadImage(url).then((image) => {
             if (image) {
               const frame = {
@@ -159,7 +161,6 @@ export class CanvasPlayer extends Mitt {
     // const frame = Math.round(clip.total * prcess);
   }
   toScroll(scrollY, na, event) {
-    let timer, completeTimer;
     const clip = Array.from(this.clips).find(
       (item) => item.id === this.currentType
     );
@@ -168,39 +169,52 @@ export class CanvasPlayer extends Mitt {
     // const startFrame = Math.floor(clip.total * prcess);
     const startFrame = this.getframeByHeight(scrollY);
 
-    if (timer) {
-      clearTimeout(timer);
-      timer = null;
+    if (this.mainScrolltimer) {
+      clearTimeout(this.mainScrolltimer);
+      this.mainScrolltimer = null;
+    }
+    if (this.mainScrollfinishTimer) {
+      clearTimeout(this.mainScrollfinishTimer);
+      this.mainScrollfinishTimer = null;
     }
-
     this.currentFrame = startFrame;
-    const matchDis = 10;
 
     const dynamicDistance = na
-      ? this.currentFrame + matchDis
-      : this.currentFrame - matchDis;
+      ? this.currentFrame + this.matchDis
+      : this.currentFrame - this.matchDis;
     //  少于frame
-
     let dis = clamp(dynamicDistance, 0, clip.total);
-    // console.log("startFrame", this.currentFrame, dis, this.movingFrame);
 
     if (this.scrollAni) {
-      // console.log("11", this.scrollAni.duration());
       this.scrollAni.kill();
       this.scrollAni = null;
-      if (Math.abs(this.movingFrame - this.currentFrame) > dis / 2) {
-        console.warn(
-          "持续少于5fame之内",
-          Math.abs(this.movingFrame - this.currentFrame)
-        );
-        na ? (dis += 6) : (dis -= 6);
+
+      // if (
+      //   Math.abs(Math.floor(this.movingFrame) - this.currentFrame) >
+      //   dis / 2
+      // ) {
+      //   console.warn(
+      //     "持续少于5fame之内",
+      //     Math.abs(this.movingFrame - this.currentFrame)
+      //   );
+      //   na ? (dis += 6) : (dis -= 6);
+      //   if (dis < 0) dis = 0;
+      // }
+    }
+
+    if (this.isRendering) {
+      const patch = Math.abs(dis - Math.floor(this.movingFrame));
+      if (patch < 5) {
+        console.warn("持续少于5fame之内", patch);
+        na ? (dis += 5) : (dis -= 5);
         if (dis < 0) dis = 0;
       }
     }
 
-    timer = setTimeout(() => {
+    // console.log("startFrame", dis, this.currentFrame, this.movingFrame);
+
+    this.mainScrolltimer = setTimeout(() => {
       this.scrollAni = gsap.timeline();
-      this.isRendering = true;
       this.scrollAni.to(this, {
         movingFrame: dis,
         // duration: 0.6,
@@ -208,14 +222,16 @@ export class CanvasPlayer extends Mitt {
         onUpdate: () => {
           this.isRendering = true;
           const mFrame = Math.floor(this.movingFrame);
+          // console.log("mFrame", mFrame);
           const prcess = mFrame / clip.total;
           this.reDraw(mFrame, this.currentType);
           this.noticeProcess();
         },
         onStart: () => {},
         onComplete: () => {
-          completeTimer = setTimeout(this.toRunPatch, 0);
-          this.scrollAni && this.scrollAni.pause();
+          this.mainScrollfinishTimer = setTimeout(this.toRunPatch, 0);
+          this.scrollAni && this.scrollAni.kill();
+          this.scrollAni = null;
         },
       });
     }, 40);
@@ -364,30 +380,43 @@ export class CanvasPlayer extends Mitt {
     }
   }
   initFirstFrame() {
-    if (this.currentType) {
-      const frameItem = this.frames.find(
-        (item) => item.id == this.currentType && item.index == 1
-      );
-      this.context.clearRect(0, 0, this.vw, this.vh);
-      this.context.drawImage(frameItem.image, 0, 0, this.vw, this.vh);
-      this.initClipScrollheight();
-      this.scrollAni = gsap.timeline();
-      let doneScroll = () => {
-        this.isRendering = false;
+    if (!this.isInit.includes(this.currentType)) {
+      if (this.currentType) {
+        this.isInit.push(this.currentType);
+        const frameItem = this.frames.find(
+          (item) => item.id == this.currentType && item.index == 1
+        );
+        this.context.clearRect(0, 0, this.vw, this.vh);
+        this.context.drawImage(frameItem.image, 0, 0, this.vw, this.vh);
+        this.initClipScrollheight();
+        this.scrollAni = gsap.timeline();
+        let doneScroll = () => {
+          this.isRendering = false;
 
-        if (this.currentFrame === 0 && this.movingFrame === 0) {
-          this.emit("scroll-prev");
-        }
-        if (
-          this.currentFrame === frameItem.total &&
-          this.movingFrame === frameItem.total
-        ) {
-          this.emit("scroll-next");
-        }
-        console.warn("scroll done", this.currentFrame, this.movingFrame);
-      };
-      this.toRunPatch = debounce(doneScroll, 400);
-      console.log("initFirstFrame");
+          if (this.currentFrame === 0 && this.movingFrame === 0) {
+            this.emit("scroll-prev");
+          }
+          if (
+            this.currentFrame === frameItem.total &&
+            this.movingFrame === frameItem.total &&
+            !isMobile()
+          ) {
+            this.emit("scroll-next");
+          }
+          //
+          if (
+            this.currentFrame === frameItem.total &&
+            frameItem.total - this.movingFrame <= this.matchDis &&
+            isMobile()
+          ) {
+            console.log("移动端下一叶");
+            this.emit("scroll-next");
+          }
+          console.warn("scroll done", this.currentFrame, this.movingFrame);
+        };
+        this.toRunPatch = debounce(doneScroll, this.isScrollDoneTime);
+        console.log("initFirstFrame");
+      }
     }
   }
   reDraw(frame, type) {

+ 3 - 3
src/utils/loadImg.js

@@ -1,6 +1,6 @@
 export default [
-    '/img/webp/chapterunit/chapter-bg.webp',
-    '/img/webp/chapterunit/unit-bg.webp',
+    '/img/chapterunit/chapter-bg.webp',
+    '/img/chapterunit/unit-bg.webp',
     '/img/webp/navicon-active.webp',
     '/img/webp/nav-bg.webp',
     '/img/webp/navicon.webp',
@@ -27,7 +27,7 @@ export default [
     '/img/section2/bg.webp',
     '/img/section2/line.webp',
     '/img/map/map-rnsys.webp',
-    '/img/webp/chapterunit/unit-bg.webp',
+    '/img/chapterunit/unit-bg.webp',
     '/img/map/map-k.webp',
     '/img/webp/jue-1.webp',
     '/img/map/map-yr.webp',

+ 47 - 44
vite.config.js

@@ -1,4 +1,4 @@
-import { defineConfig } from "vite";
+import { defineConfig, loadEnv } from "vite";
 import vue from "@vitejs/plugin-vue";
 import { ViteImageOptimizer } from "vite-plugin-image-optimizer";
 import inject from "@rollup/plugin-inject";
@@ -9,48 +9,51 @@ function pathResolve(dir) {
   return path.resolve(process.cwd(), ".", dir);
 }
 // https://vitejs.dev/config/
-export default defineConfig({
-  plugins: [
-    vue(),
-    commonjs(),
-    ViteImageOptimizer({
-      png: {
-        quality: 100,
-      },
-      jpg: {
-        quality: 100,
-      },
-      webp: {
-        quality: 30,
+export default ({ mode }) =>
+  defineConfig({
+    base: loadEnv(mode, process.cwd()).VITE_PUBLIC_DIR,
+    plugins: [
+      vue(),
+      commonjs(),
+      // ViteImageOptimizer({
+      //   png: {
+      //     quality: 100,
+      //   },
+      //   jpg: {
+      //     quality: 100,
+      //   },
+      //   webp: {
+      //     quality: 80,
+      //   },
+      // }),
+    ],
+    optimizeDeps: {
+      include: ["fullPage"],
+    },
+    // build: {
+    //   commonjsOptions: {
+    //     transformMixedEsModules: true,
+    //   },
+    // },
+    resolve: {
+      alias: {
+        "@": path.resolve(__dirname, "src"),
+        "##": path.resolve(__dirname, "src/assets"),
+        "#": path.resolve(__dirname, "public"),
+        fullPage: path.resolve(
+          __dirname,
+          "src/components/fullpage/extensions.js"
+        ),
       },
-    }),
-  ],
-  optimizeDeps: {
-    include: ["fullPage"],
-  },
-  // build: {
-  //   commonjsOptions: {
-  //     transformMixedEsModules: true,
-  //   },
-  // },
-  resolve: {
-    alias: {
-      "@": path.resolve(__dirname, "src"),
-      "##": path.resolve(__dirname, "src/assets"),
-      fullPage: path.resolve(
-        __dirname,
-        "src/components/fullpage/extensions.js"
-      ),
+      extensions: [
+        ".mjs",
+        ".js",
+        ".ts",
+        ".jsx",
+        ".tsx",
+        ".json",
+        ".vue",
+        ".webp",
+      ],
     },
-    extensions: [
-      ".mjs",
-      ".js",
-      ".ts",
-      ".jsx",
-      ".tsx",
-      ".json",
-      ".vue",
-      ".webp",
-    ],
-  },
-});
+  });