PUGE 4 anni fa
parent
commit
78cf5d793c
6 ha cambiato i file con 286 aggiunte e 17 eliminazioni
  1. 0 5
      config.json
  2. 221 0
      index.html
  3. 46 7
      main.js
  4. 9 1
      package.json
  5. 6 0
      resources/config.json
  6. 4 4
      yarn.lock

+ 0 - 5
config.json

@@ -1,5 +0,0 @@
-{
-    "width": 1200,
-    "height": 800,
-    "url": "https://github.com/electron-userland/electron-builder"
-}

+ 221 - 0
index.html

@@ -0,0 +1,221 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+  <meta http-equiv="Content-Language" content="utf-8" />
+  <title></title>
+  <meta content="all" name="robots" />
+  <meta name="description" content="" />
+  <meta name="keywords" content="" />
+  <meta name="filetype" content="1" />
+  <meta name="publishedtype" content="1" />
+  <meta name="pagetype" content="2" />
+  <meta name="catalogs" content="" />
+  <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
+  <!--优先使用 IE 最新版本和 Chrome-->
+  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
+  <!--360 使用Google Chrome Frame-->
+  <meta name="renderer" content="webkit">
+  <script src="static/libs/jquery-1.11.1.min.js" type="text/javascript"></script>
+  <link href="static/libs/swiper.min.css" rel="stylesheet">
+  <link href="static/css/default.css" rel="stylesheet">
+  <script src="static/libs/swiper.min.js"></script>
+  <link rel="stylesheet" href="./static/css/main.css" charset="utf-8">
+  <style>
+
+.slide2 .img3{top:50%;transform: translate(-50%,-50%);}
+.img3-1{width: 58.33333vw;}
+.sxdeg{position: absolute;
+    color: #fff;
+    right: 6.9vw;
+    font-size: 22px;
+    top: 48%;}
+.zydeg{ position: absolute;   color: #fff;
+    font-size: 22px;
+    left: 50%;
+    bottom: 5vw;
+    transform: translateX(-50%);}
+  .slide2 .img4{z-index: 1}
+  </style>
+</head>
+<body>
+  <div class="swiper-container swiper1">
+    <div class="swiper-wrapper">
+      <div class="swiper-slide slide1 swiper-no-swiping">
+        <div class="d1">
+          <img class="img1" src="static/images/text.png" alt="">
+        </div>
+        <div class="d2">
+          <img class="yuan" src="static/images/tip1.png" alt="">
+          <img class="yuan2" src="static/images/tip3.png" alt="">
+          <img class="img2" src="static/images/tip2.png" alt="">
+        </div>
+        <div class="d3">
+          <img class="yx" src="static/images/yx.png" alt="">
+        </div>
+      </div>
+      <div class="swiper-slide slide2 swiper-no-swiping">
+        <div class="img3">
+          <img class="img3-1"  src="static/images/yuan.png" alt="">
+          <p class="sxdeg">0</p>
+          <p class="zydeg">0</p>
+        </div>
+        
+        <img class="img4" src="static/images/text2.png" alt="">
+        <img class="img5" src="static/images/text3.png" alt="">
+        <!-- 3D区域 -->
+        <div class="box ox" template="home" id="o-home"></div>
+        <ul class="nav">
+          <li class="active"><img src="static/images/1.png" alt=""></li>
+          <li class="show"><img src="static/images/2.png" alt=""></li>
+          <li><img src="static/images/3.png" alt=""></li>
+        </ul>
+      </div>
+    </div>
+  </div>
+<script>
+  $(document).ready(function () {
+ 
+    $(".nav li").click(function(){
+      var index = $(this).index()
+      if(index==2){
+        $(".slide2").fadeOut()
+      }
+    })
+    $(".show").click(function(){
+      if($(this).hasClass("active")){
+        $(".img5").fadeOut()
+        $(".show").removeClass("active")
+      }else{
+        $(".img5").fadeIn()
+        $(".show").addClass("active")
+      }
+    })
+    $(".d2").click(function(){
+      $(".slide2").fadeIn()
+    })
+    window.owo.script.home.created()
+  })
+</script>
+<script>
+    "use strict";
+
+    window.owo = {
+      // 页面数据和方法
+      script: {
+        "home": {
+          "data": {
+            "controls": null,
+            "camera": null,
+            "scene": null,
+            "renderer": null,
+            "light": null,
+            "clock": null,
+            "type": "rotate",
+            "model": null,
+            "Material_58": null,
+            "Material_59": null,
+            "window_box_1": null,
+            "window_box_2": null,
+            "arrow_box": null,
+            "waitTime": 0,
+            "sxdeg": null,
+            "zydeg": null
+          },
+          "init": function init() {
+            var _this = this;
+            THREE.Loader.Handlers.add( /\.tga$/i, new THREE.TGALoader() );
+            // 创建摄像机
+            this.data.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 200000);
+            this.data.camera.position.set(0, 0, 700);
+            this.data.controls = new THREE.OrbitControls(this.data.camera);
+            // 禁止左右拖拽
+            this.data.controls.enablePan = false
+            this.data.controls.target.set(0, 0, 0);
+            this.data.controls.maxDistance = 2500
+            this.data.controls.minDistance = 300
+            this.data.controls.screenSpacePanning = false
+            this.data.controls.update();
+            this.data.scene = new THREE.Scene();
+            // this.data.scene.background = new THREE.Color(0xa0a0a0);
+            this.data.light = new THREE.HemisphereLight(0xffffff, 0x444444);
+            this.data.light.position.set(0, 200, 0);
+            this.data.scene.add(this.data.light);
+            this.data.light = new THREE.DirectionalLight(0xffffff);
+            this.data.light.position.set(0, 200, 100);
+            this.data.light.castShadow = true;
+            this.data.light.shadow.camera.top = 180;
+            this.data.light.shadow.camera.bottom = -100;
+            this.data.light.shadow.camera.left = -120;
+            this.data.light.shadow.camera.right = 120;
+            this.data.scene.add(this.data.light); // this.data.scene.add( new THREE.CameraHelper( this.data.light.shadow.camera ) );
+            // 网格线
+            // var grid = new THREE.GridHelper( 2000, 20, 0x000000, 0x000000 );
+            // grid.material.opacity = 0.2;
+            // grid.material.transparent = true;
+            // this.data.scene.add( grid );
+            // model
+
+            var loader = new THREE.FBXLoader();
+            loader.load('./resource/yuyin.FBX', function(object) {
+              object.traverse(function(child) {
+                // console.log(child.name)
+                if (child.isMesh) {
+                  child.castShadow = true;
+                  child.receiveShadow = true;
+                }
+              });
+              object.position.y = -100
+              object.scale.set(100,100,100)
+              _this.data.scene.add(object);
+            });
+            this.data.renderer = new THREE.WebGLRenderer({
+              antialias: true,
+              alpha:true
+            });
+            this.data.renderer.setClearColor(0xEEEEEE, 0.0);
+            this.data.renderer.setPixelRatio(window.devicePixelRatio);
+            this.data.renderer.setSize(window.innerWidth, window.innerHeight);
+            this.data.renderer.shadowMap.enabled = true;
+            document.querySelector('#o-home').appendChild(this.data.renderer.domElement); // window.addEventListener( 'resize', this.onWindowResize, false );
+            var gridHelper = new THREE.GridHelper( 1000, 30, 0x2C2C2C, 0x888888 );
+            // _this.data.scene.add(gridHelper);
+            this.data.sxdeg = document.querySelector('.sxdeg')
+            this.data.zydeg = document.querySelector('.zydeg')
+          },
+          "animate": function animate() {
+            var _this2 = this;
+
+            var delta = this.data.clock.getDelta();
+
+            this.data.renderer.render(this.data.scene, this.data.camera);
+            this.data.sxdeg.innerText = parseInt(- owo.script.home.data.camera.rotation.x * 180) + '°'
+            this.data.zydeg.innerText = parseInt(- owo.script.home.data.camera.rotation.z * 180) + '°'
+            setTimeout(function() {
+              _this2.animate();
+            }, 25);
+          },
+          "onWindowResize": function onWindowResize() {
+            this.data.camera.aspect = window.innerWidth / window.innerHeight;
+            this.data.camera.updateProjectionMatrix();
+            this.data.renderer.setSize(window.innerWidth, window.innerHeight);
+          },
+          "created": function created() {
+            console.log(this);
+            this.data.clock = new THREE.Clock();
+            this.init();
+            this.animate();
+          }
+        }
+      }
+    };
+  </script>
+  <script src="./static/js/three.js.js" type="text/javascript" charset="UTF-8"></script>
+  <script src="https://ithanmang.gitee.io/threejs/home/libs/examples/js/loaders/TGALoader.js"></script>
+  <script src="./static/js/FBXLoader.js" type="text/javascript" charset="UTF-8"></script>
+  <script src="./static/js/OrbitControls.js" type="text/javascript" charset="UTF-8"></script>
+  <script src="./static/js/inflate.min.js" type="text/javascript" charset="UTF-8"></script>
+</body>
+
+</html>

+ 46 - 7
main.js

@@ -3,25 +3,58 @@ const {app, BrowserWindow} = require('electron')
 const path = require('path')
 const fs = require('fs')
 // 读取配置文件
-const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8'))
+const config = JSON.parse(fs.readFileSync('./resources/config.json', 'utf-8'))
 
 function createWindow () {
   // Create the browser window.
   let webConfig = {
     width: config.width,
     height: config.height,
-    webPreferences: {}
-  }
-  if (config.preload) {
-    webConfig.webPreferences.preload = config.preload
+    webPreferences: {
+      webSecurity: false,
+    },
+    // 无边框
+    // frame: false,
+    // 全屏
+    // fullscreen: true
   }
+  // if (config.preload) {
+  //   console.log(config.preload)
+  //   webConfig.webPreferences.preload = config.preload
+  // }
   const mainWindow = new BrowserWindow(webConfig)
 
   // and load the index.html of the app.
-  // mainWindow.loadFile('index.html')
+  // mainWindow.loadFile('./resources/01.html')
+  mainWindow.webContents.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1'
+  // mainWindow.webContents.openDevTools()
   mainWindow.loadURL(config.url)
+  mainWindow.webContents.on("dom-ready", function() {
+    mainWindow.webContents.executeJavaScript(`
+    function loadScript(url, callback) {
+      var script = document.createElement("script")
+      script.type = "text/javascript";
+      if (script.readyState) { //IE
+          script.onreadystatechange = function () {
+              if (script.readyState == "loaded" || script.readyState == "complete") {
+                  script.onreadystatechange = null;
+                  if (callback) callback();
+              }
+          };
+      } else { //Others
+          script.onload = function () {
+              if (callback) callback();
+          };
+      }
+      script.src = url;
+      var head = document.head || document.getElementsByTagName('head')[0];
+      head.appendChild(script);
+    }
+    loadScript('${config.preload}')
+    `);
+  });
   // Open the DevTools.
-  // mainWindow.webContents.openDevTools()
+  
 }
 
 // This method will be called when Electron has finished
@@ -37,6 +70,12 @@ app.whenReady().then(() => {
   })
 })
 
+app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
+  //允许私有证书
+  event.preventDefault()
+  callback(true)
+});
+
 // Quit when all windows are closed, except on macOS. There, it's common
 // for applications and their menu bar to stay active until the user quits
 // explicitly with Cmd + Q.

+ 9 - 1
package.json

@@ -8,6 +8,14 @@
     "pack": "electron-builder --dir",
     "dist": "electron-builder"
   },
+  "build": {
+    "extraResources": [
+      {
+        "from": "./config.json",
+        "to": "./config.json"
+      }
+    ]
+  },
   "repository": "https://github.com/electron/electron-quick-start",
   "keywords": [
     "Electron",
@@ -19,7 +27,7 @@
   "author": "GitHub",
   "license": "CC0-1.0",
   "devDependencies": {
-    "electron": "^13.1.4",
+    "electron": "^14.0.0",
     "electron-builder": "^22.11.7"
   }
 }

+ 6 - 0
resources/config.json

@@ -0,0 +1,6 @@
+{
+    "width": 376,
+    "height": 667,
+    "preload": "https://cunchu.site/work/script/chxy.js",
+    "url": "http://lib-seat.chu.edu.cn/ClientWeb/m/ic2/Default.aspx"
+}

+ 4 - 4
yarn.lock

@@ -696,10 +696,10 @@ electron-publish@22.11.7:
     lazy-val "^1.0.5"
     mime "^2.5.2"
 
-electron@^13.1.4:
-  version "13.1.5"
-  resolved "https://registry.yarnpkg.com/electron/-/electron-13.1.5.tgz#faa6127ac3428ec12c14779a6fe0a89b150ce614"
-  integrity sha512-ZoMCcPQNs/zO/Zdb5hq5H+rwRaKrdI3/sfXEwBVMx7f5jwa9jPQB3dZ2+7t59uD9VcFAWsH/pozr8nPPlv0tyw==
+electron@^14.0.0:
+  version "14.0.0"
+  resolved "https://registry.yarnpkg.com/electron/-/electron-14.0.0.tgz#a096484bfbf71d87fc0fa85a943a7869d6b9bf94"
+  integrity sha512-O6EI7L1BPIrTpEIFefjjmdbmSn9LtE4mmrv4dfpV4Mqaa8uKuNYQogwZPEvSwaBexb69eb1LQ25n+f+kBcjiRQ==
   dependencies:
     "@electron/get" "^1.0.1"
     "@types/node" "^14.6.2"