jinx 3 месяцев назад
Родитель
Сommit
2e41ef654d
8 измененных файлов с 265 добавлено и 9 удалено
  1. 2 1
      index.html
  2. 24 0
      package-lock.json
  3. 1 0
      package.json
  4. BIN
      public/static/images/icon/icon.ico
  5. 6 3
      src/App.vue
  6. 6 5
      src/main.js
  7. 225 0
      src/wechat-share.js
  8. 1 0
      vite.config.js

+ 2 - 1
index.html

@@ -2,8 +2,9 @@
 <html lang="zh-CN">
   <head>
     <meta charset="UTF-8" />
+    <link rel="shortcut icon" href=/static/images/icon/icon.ico>
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>高考主题宣传策划H5</title>
+    <title>高考云打卡“考神”魁星</title>
   </head>
   <body>
     <div id="app"></div>

+ 24 - 0
package-lock.json

@@ -8,6 +8,7 @@
       "name": "ntbwy",
       "version": "0.0.0",
       "dependencies": {
+        "jsonp": "^0.2.1",
         "sass": "^1.100.0",
         "vue": "^3.5.13"
       },
@@ -236,6 +237,15 @@
       "version": "3.2.3",
       "license": "MIT"
     },
+    "node_modules/debug": {
+      "version": "2.6.9",
+      "resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
+      "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+      "license": "MIT",
+      "dependencies": {
+        "ms": "2.0.0"
+      }
+    },
     "node_modules/detect-libc": {
       "version": "2.1.2",
       "license": "Apache-2.0",
@@ -317,6 +327,14 @@
         "node": ">=0.10.0"
       }
     },
+    "node_modules/jsonp": {
+      "version": "0.2.1",
+      "resolved": "https://registry.npmmirror.com/jsonp/-/jsonp-0.2.1.tgz",
+      "integrity": "sha512-pfog5gdDxPdV4eP7Kg87M8/bHgshlZ5pybl+yKxAnCZ5O7lCIn7Ixydj03wOlnDQesky2BPyA91SQ+5Y/mNwzw==",
+      "dependencies": {
+        "debug": "^2.1.3"
+      }
+    },
     "node_modules/magic-string": {
       "version": "0.30.21",
       "license": "MIT",
@@ -324,6 +342,12 @@
         "@jridgewell/sourcemap-codec": "^1.5.5"
       }
     },
+    "node_modules/ms": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
+      "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
+      "license": "MIT"
+    },
     "node_modules/nanoid": {
       "version": "3.3.12",
       "funding": [

+ 1 - 0
package.json

@@ -9,6 +9,7 @@
     "preview": "vite preview"
   },
   "dependencies": {
+    "jsonp": "^0.2.1",
     "sass": "^1.100.0",
     "vue": "^3.5.13"
   },

BIN
public/static/images/icon/icon.ico


+ 6 - 3
src/App.vue

@@ -12,8 +12,6 @@
         playsinline=""
         webkit-playsinline=""
         autoplay="autoplay"
-        muted="muted"
-        loop="loop"
         preload="true"
       ></video>
     </div>
@@ -29,6 +27,8 @@
 import { computed, onBeforeUnmount, onMounted, ref, nextTick } from "vue";
 import pc from "./pc/index.vue";
 import mobile from "./mobile/index.vue";
+import { setShareData } from "./wechat-share";
+
 const isMobile =
   /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Mobile|Opera Mini/i.test(
     navigator.userAgent,
@@ -48,6 +48,9 @@ const play = () => {
       showJump.value = true;
     }, 3000);
     video.play();
+    video.addEventListener("ended", () => {
+      goModel();
+    });
   });
 };
 const goModel = () => {
@@ -72,7 +75,7 @@ onBeforeUnmount(() => {});
   video {
     width: 100%;
     height: 100%;
-    object-fit: contain;
+    object-fit: cover;
   }
   .jump {
     position: absolute;

+ 6 - 5
src/main.js

@@ -1,5 +1,6 @@
-import { createApp } from 'vue'
-import App from './App.vue'
-import './style.css'
-// 
-createApp(App).mount('#app')
+import { createApp } from "vue";
+import App from "./App.vue";
+import "./style.css";
+import { initWxShare } from "./wechat-share";
+initWxShare();
+createApp(App).mount("#app");

+ 225 - 0
src/wechat-share.js

@@ -0,0 +1,225 @@
+import jsonp from "jsonp";
+/**
+ * 微信 JS-SDK 分享配置
+ * 通过 JSONP 请求签名,配置朋友圈 / 好友分享
+ */
+
+// 正在加载中标记
+let loading = false;
+// wx.config 是否已完成
+let configured = false;
+// 等待队列
+let resolveQueue = [];
+
+// /**
+//  * JSONP 请求
+//  * @param {string} url - 接口地址
+//  * @param {object} params - 查询参数
+//  * @returns {Promise<any>}
+//  */
+// function jsonp(url, params = {}) {
+//   return new Promise((resolve, reject) => {
+//     const callbackName =
+//       "wx_jsonp_cb_" +
+//       Date.now() +
+//       "_" +
+//       Math.random().toString(36).slice(2, 8);
+//     params.jsonp = callbackName;
+
+//     const query = Object.keys(params)
+//       .map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`)
+//       .join("&");
+
+//     const sep = url.includes("?") ? "&" : "?";
+//     const src = url + sep + query;
+
+//     const script = document.createElement("script");
+//     script.src = src;
+
+//     // 超时保护
+//     const timer = setTimeout(() => {
+//       cleanup();
+//       reject(new Error("JSONP timeout"));
+//     }, 10000);
+
+//     function cleanup() {
+//       clearTimeout(timer);
+//       delete window[callbackName];
+//       if (script.parentNode) script.parentNode.removeChild(script);
+//     }
+
+//     window[callbackName] = (data) => {
+//       cleanup();
+//       resolve(data);
+//     };
+
+//     script.onerror = () => {
+//       cleanup();
+//       reject(new Error("JSONP error"));
+//     };
+
+//     document.head.appendChild(script);
+//   });
+// }
+
+/**
+ * 加载微信 JS-SDK 脚本
+ */
+function loadJSSDK() {
+  return new Promise((resolve, reject) => {
+    if (window.wx) {
+      resolve();
+      return;
+    }
+    const script = document.createElement("script");
+    script.src = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js";
+    script.onload = () => resolve();
+    script.onerror = () => reject(new Error("加载 jweixin SDK 失败"));
+    document.head.appendChild(script);
+  });
+}
+
+/**
+ * 初始化微信分享配置(签名 + wx.config)
+ * 仅移动端微信环境需要调用
+ * @returns {Promise<void>}
+ */
+export async function initWxShare() {
+  // 非微信浏览器直接返回
+  // if (!/MicroMessenger/i.test(navigator.userAgent)) return;
+  // 已经在加载中 / 已完成,返回 promise
+  if (loading || configured) {
+    return new Promise((resolve) => {
+      if (configured) {
+        resolve();
+      } else {
+        resolveQueue.push(resolve);
+      }
+    });
+  }
+
+  loading = true;
+
+  try {
+    await loadJSSDK();
+
+    const shareUrl = window.location.href.split("#")[0];
+    let name = "厦门四维时代微信公众号";
+    let uri = encodeURIComponent(location.href.split("#")[0]);
+    // const data = await jsonp(
+    //   "//www.4dage.com/wechat/jssdk/share?name=" + name + "&uri=" + uri,
+    //   {
+    //     param: "callback",
+    //   },
+    // );
+    jsonp(
+      "//www.4dage.com/wechat/jssdk/share?name=" + name + "&uri=" + uri,
+      {
+        param: "callback",
+      },
+      function (err, data) {
+        console.log(data);
+        const { appId, timestamp, nonceStr, signature } = data;
+
+        window.wx.config({
+          debug: false,
+          appId,
+          timestamp,
+          nonceStr,
+          signature,
+          jsApiList: [
+            "checkJsApi",
+            "onMenuShareTimeline",
+            "onMenuShareAppMessage",
+            "updateTimelineShareData",
+            "updateAppMessageShareData",
+            "onMenuShareQQ",
+            "onMenuShareWeibo",
+            "hideMenuItems",
+            "showMenuItems",
+            "hideAllNonBaseMenuItem",
+            "showAllNonBaseMenuItem",
+            "translateVoice",
+            "startRecord",
+            "stopRecord",
+            "onRecordEnd",
+            "playVoice",
+            "pauseVoice",
+            "stopVoice",
+            "uploadVoice",
+            "downloadVoice",
+            "chooseImage",
+            "previewImage",
+            "uploadImage",
+            "downloadImage",
+            "getNetworkType",
+            "openLocation",
+            "getLocation",
+            "hideOptionMenu",
+            "showOptionMenu",
+            "closeWindow",
+            "scanQRCode",
+            "chooseWXPay",
+            "openProductSpecificView",
+            "addCard",
+            "chooseCard",
+            "openCard",
+          ],
+        });
+
+        window.wx.ready(() => {
+          configured = true;
+          loading = false;
+          resolveQueue.forEach((fn) => fn());
+          resolveQueue = [];
+
+          setShareData({
+            title: '快来云打卡“考神”魁星,祝所有考生金榜题名',
+            desc: "",
+            imgUrl: `https://www.4dkankan.com/test/gzh/static/images/mobile/logo.png`,
+          });
+        });
+
+        window.wx.error(() => {
+          loading = false;
+          resolveQueue.forEach((fn) => fn());
+          resolveQueue = [];
+        });
+      },
+    );
+  } catch (e) {
+    console.warn("微信分享初始化失败:", e);
+    loading = false;
+    resolveQueue.forEach((fn) => fn());
+    resolveQueue = [];
+  }
+}
+
+/**
+ * 设置分享内容
+ * @param {object} options
+ * @param {string} options.title - 分享标题
+ * @param {string} options.desc - 分享描述(仅好友可见)
+ * @param {string} options.link - 分享链接(默认当前页)
+ * @param {string} options.imgUrl - 分享图标(200×200 以上)
+ */
+export function setShareData({ title, desc, link, imgUrl }) {
+  if (!window.wx) return;
+
+  const shareLink = link || window.location.href;
+  const shareImgUrl = imgUrl || "";
+  // 分享给朋友
+  window.wx.onMenuShareAppMessage({
+    title,
+    desc,
+    link: shareLink,
+    imgUrl: shareImgUrl,
+  });
+
+  // 分享到朋友圈
+  window.wx.onMenuShareTimeline({
+    title,
+    link: shareLink,
+    imgUrl: shareImgUrl,
+  });
+}

+ 1 - 0
vite.config.js

@@ -2,5 +2,6 @@ import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
 
 export default defineConfig({
+  base: './',
   plugins: [vue()],
 })