瀏覽代碼

改成新的Electron打包方式,隔离node和web

Michael Wang 3 年之前
父節點
當前提交
c3bd3deb4c
共有 68 個文件被更改,包括 188 次插入29 次删除
  1. 1 0
      package.json
  2. 0 0
      public/img/back.png
  3. 0 0
      public/img/bg.jpg
  4. 0 0
      public/img/close.png
  5. 0 0
      public/img/data_btn.png
  6. 0 0
      public/img/enter.png
  7. 0 0
      public/img/error.png
  8. 0 0
      public/img/error_small.png
  9. 0 0
      public/img/icon1.png
  10. 0 0
      public/img/icon2.png
  11. 0 0
      public/img/icon3.png
  12. 0 0
      public/img/id.png
  13. 0 0
      public/img/logo.png
  14. 0 0
      public/img/logo_blue.png
  15. 0 0
      public/img/pic_btn.png
  16. 0 0
      public/img/radio.png
  17. 0 0
      public/img/select.png
  18. 0 0
      public/img/success.png
  19. 0 0
      public/img/success_small.png
  20. 2 4
      public/index.html
  21. 0 0
      public/styles/style.css
  22. 0 4
      src/App.vue
  23. 4 3
      src/background.ts
  24. 11 2
      src/lib/api.ts
  25. 3 6
      src/lib/config.ts
  26. 2 4
      src/lib/env.ts
  27. 11 0
      src/preload.ts
  28. 5 6
      src/router/index.ts
  29. 52 0
      src/views/features/Home/Home.vue
  30. 二進制
      src/views/features/Home/img/back.png
  31. 二進制
      src/views/features/Home/img/bg.jpg
  32. 二進制
      src/views/features/Home/img/close.png
  33. 二進制
      src/views/features/Home/img/data_btn.png
  34. 二進制
      src/views/features/Home/img/enter.png
  35. 二進制
      src/views/features/Home/img/error.png
  36. 二進制
      src/views/features/Home/img/error_small.png
  37. 二進制
      src/views/features/Home/img/icon1.png
  38. 二進制
      src/views/features/Home/img/icon2.png
  39. 二進制
      src/views/features/Home/img/icon3.png
  40. 二進制
      src/views/features/Home/img/id.png
  41. 二進制
      src/views/features/Home/img/logo.png
  42. 二進制
      src/views/features/Home/img/logo_blue.png
  43. 二進制
      src/views/features/Home/img/pic_btn.png
  44. 二進制
      src/views/features/Home/img/radio.png
  45. 二進制
      src/views/features/Home/img/select.png
  46. 二進制
      src/views/features/Home/img/success.png
  47. 二進制
      src/views/features/Home/img/success_small.png
  48. 91 0
      src/views/features/Login/Login.vue
  49. 二進制
      src/views/features/Login/img/back.png
  50. 二進制
      src/views/features/Login/img/bg.jpg
  51. 二進制
      src/views/features/Login/img/close.png
  52. 二進制
      src/views/features/Login/img/data_btn.png
  53. 二進制
      src/views/features/Login/img/enter.png
  54. 二進制
      src/views/features/Login/img/error.png
  55. 二進制
      src/views/features/Login/img/error_small.png
  56. 二進制
      src/views/features/Login/img/icon1.png
  57. 二進制
      src/views/features/Login/img/icon2.png
  58. 二進制
      src/views/features/Login/img/icon3.png
  59. 二進制
      src/views/features/Login/img/id.png
  60. 二進制
      src/views/features/Login/img/logo.png
  61. 二進制
      src/views/features/Login/img/logo_blue.png
  62. 二進制
      src/views/features/Login/img/pic_btn.png
  63. 二進制
      src/views/features/Login/img/radio.png
  64. 二進制
      src/views/features/Login/img/select.png
  65. 二進制
      src/views/features/Login/img/success.png
  66. 二進制
      src/views/features/Login/img/success_small.png
  67. 1 0
      vue.config.js
  68. 5 0
      yarn.lock

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
     "request": "^2.88.0",
     "requestretry": "^3.1.0",
     "thinkjs-util": ">=0.0.1",
+    "vertx": "^0.0.1-security",
     "vue": "^3.0.0",
     "vue-router": "^4.0.0-0"
   },

+ 0 - 0
src/view/img/back.png → public/img/back.png


+ 0 - 0
src/view/img/bg.jpg → public/img/bg.jpg


+ 0 - 0
src/view/img/close.png → public/img/close.png


+ 0 - 0
src/view/img/data_btn.png → public/img/data_btn.png


+ 0 - 0
src/view/img/enter.png → public/img/enter.png


+ 0 - 0
src/view/img/error.png → public/img/error.png


+ 0 - 0
src/view/img/error_small.png → public/img/error_small.png


+ 0 - 0
src/view/img/icon1.png → public/img/icon1.png


+ 0 - 0
src/view/img/icon2.png → public/img/icon2.png


+ 0 - 0
src/view/img/icon3.png → public/img/icon3.png


+ 0 - 0
src/view/img/id.png → public/img/id.png


+ 0 - 0
src/view/img/logo.png → public/img/logo.png


+ 0 - 0
src/view/img/logo_blue.png → public/img/logo_blue.png


+ 0 - 0
src/view/img/pic_btn.png → public/img/pic_btn.png


+ 0 - 0
src/view/img/radio.png → public/img/radio.png


+ 0 - 0
src/view/img/select.png → public/img/select.png


+ 0 - 0
src/view/img/success.png → public/img/success.png


+ 0 - 0
src/view/img/success_small.png → public/img/success_small.png


+ 2 - 4
public/index.html

@@ -5,12 +5,10 @@
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
-    <title><%= htmlWebpackPlugin.options.title %></title>
+    <title>云阅卷本地代理工具</title>
+    <link rel="stylesheet" href="/styles/style.css">
   </head>
   <body>
-    <noscript>
-      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
-    </noscript>
     <div id="app"></div>
     <!-- built files will be auto injected -->
   </body>

+ 0 - 0
src/view/css/style.css → public/styles/style.css


+ 0 - 4
src/App.vue

@@ -1,8 +1,4 @@
 <template>
-  <div id="nav">
-    <router-link to="/">Home</router-link> |
-    <router-link to="/about">About</router-link>
-  </div>
   <router-view />
 </template>
 

+ 4 - 3
src/background.ts

@@ -1,5 +1,6 @@
 "use strict";
 
+import path from "path";
 import { app, protocol, BrowserWindow } from "electron";
 import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
 import installExtension, { VUEJS3_DEVTOOLS } from "electron-devtools-installer";
@@ -19,9 +20,9 @@ async function createWindow() {
     webPreferences: {
       // Use pluginOptions.nodeIntegration, leave this alone
       // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
-      nodeIntegration: process.env
-        .ELECTRON_NODE_INTEGRATION as unknown as boolean,
-      contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
+      nodeIntegration: false, //process.env.ELECTRON_NODE_INTEGRATION as unknown as boolean,
+      contextIsolation: true, //!process.env.ELECTRON_NODE_INTEGRATION,
+      preload: path.join(__dirname, "preload.js"),
     },
   });
 

+ 11 - 2
src/lib/api.ts

@@ -1,5 +1,5 @@
-const request = require("requestretry");
-const env = require("./env");
+import request from "requestretry";
+import env from "./env";
 import _logger from "./logger";
 const logger = _logger("api.js");
 
@@ -92,3 +92,12 @@ export function getPackages(examId, upload, withUrl) {
   }
   return execute(uri, "GET");
 }
+
+export default {
+  execute,
+  login,
+  getExams,
+  getStudents,
+  countStudents,
+  getPackages,
+};

+ 3 - 6
src/lib/config.ts

@@ -1,10 +1,9 @@
-import fs from "fs";
+import fs, { readFileSync } from "fs";
 import path from "path";
 import moment from "moment";
 import env from "./env";
 
-console.log(__dirname);
-const configJson = fs.readFileSync(path.join(__dirname, "../config.json"));
+const configJson = readFileSync(path.join(__dirname, "../config.json"));
 const store = JSON.parse(configJson.toString());
 
 export default store;
@@ -13,15 +12,13 @@ const timeLog = path.join(__dirname, "../../logs/time.log");
 let syncTime = {};
 if (fs.existsSync(path.join(__dirname, "../../logs/time.log"))) {
   try {
-    syncTime = fs.readFileSync(timeLog).toJSON();
+    syncTime = readFileSync(timeLog).toJSON();
   } catch (err) {
     syncTime = {};
   }
 }
 store["syncTime"] = syncTime;
 
-// module.exports = store;
-
 export function updateSyncTime(): void {
   if (env.server && env.exam) {
     syncTime[env.server.host + "_" + env.exam.id] = moment().format(

+ 2 - 4
src/lib/env.ts

@@ -2,11 +2,9 @@ const store = {};
 
 export default store;
 
-export function merge(obj): void {
+export function merge(obj: any): void {
   if (obj == undefined) {
     return;
   }
-  for (const field in obj) {
-    store[field] = obj[field];
-  }
+  Object.assign(store, obj);
 }

+ 11 - 0
src/preload.ts

@@ -0,0 +1,11 @@
+import { contextBridge } from "electron";
+
+import env from "./lib/env";
+import config from "./lib/config";
+import api from "./lib/api";
+
+contextBridge.exposeInMainWorld("electron", {
+  env: env,
+  config,
+  api,
+});

+ 5 - 6
src/router/index.ts

@@ -1,18 +1,17 @@
 import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
-import Home from "../views/Home.vue";
 
 const routes: Array<RouteRecordRaw> = [
   {
     path: "/",
-    name: "Home",
-    component: Home,
+    name: "Login",
+    component: () =>
+      import(
+        /* webpackChunkName: "about" */ "../views/features/Login/Login.vue"
+      ),
   },
   {
     path: "/about",
     name: "About",
-    // route level code-splitting
-    // this generates a separate chunk (about.[hash].js) for this route
-    // which is lazy-loaded when the route is visited.
     component: () =>
       import(/* webpackChunkName: "about" */ "../views/About.vue"),
   },

+ 52 - 0
src/views/features/Home/Home.vue

@@ -0,0 +1,52 @@
+<template>
+  <div class="wp">
+    <div class="hd">
+      <div class="logo"><img src="img/logo.png" /></div>
+      <span class="y">
+        欢迎您,<span id="user-name"></span> <span class="pipe">|</span
+        ><a href="login.html">退出</a>
+      </span>
+    </div>
+    <div class="cont">
+      <div class="title cl" id="exam-title">
+        <em class="id"></em><span class="name">{{ userName }}</span
+        ><span class="pipe">|</span>
+        <span class="time"></span>
+      </div>
+      <div class="list">
+        <h3>功能选择</h3>
+        <ul class="cl">
+          <li class="l1">
+            <a href="exam-list.html"><span></span>考试切换</a>
+          </li>
+          <li class="l2">
+            <a href="sync.html"><span></span>数据同步</a>
+          </li>
+          <li class="l3">
+            <a href="image.html"><span></span>图片下载</a>
+          </li>
+        </ul>
+      </div>
+    </div>
+    <div class="ft">
+      Copyright © 2011-2020 www.qmth.com.cn, All Rights Reserved
+    </div>
+  </div>
+</template>
+
+<script setup lang="ts">
+import env from "../../../lib/env";
+
+Object.assign(env, JSON.parse(window.localStorage.getItem("env") || "{}"));
+
+const {
+  user: { userName },
+  exam: { iid, name, examTime },
+} = env;
+
+// $("#user-name").html(env.user.userName);
+
+// $("#exam-title").find(".id").html(env.exam.id);
+// $("#exam-title").find(".name").html(env.exam.name);
+// $("#exam-title").find(".time").html(env.exam.examTime);
+</script>

二進制
src/views/features/Home/img/back.png


二進制
src/views/features/Home/img/bg.jpg


二進制
src/views/features/Home/img/close.png


二進制
src/views/features/Home/img/data_btn.png


二進制
src/views/features/Home/img/enter.png


二進制
src/views/features/Home/img/error.png


二進制
src/views/features/Home/img/error_small.png


二進制
src/views/features/Home/img/icon1.png


二進制
src/views/features/Home/img/icon2.png


二進制
src/views/features/Home/img/icon3.png


二進制
src/views/features/Home/img/id.png


二進制
src/views/features/Home/img/logo.png


二進制
src/views/features/Home/img/logo_blue.png


二進制
src/views/features/Home/img/pic_btn.png


二進制
src/views/features/Home/img/radio.png


二進制
src/views/features/Home/img/select.png


二進制
src/views/features/Home/img/success.png


二進制
src/views/features/Home/img/success_small.png


+ 91 - 0
src/views/features/Login/Login.vue

@@ -0,0 +1,91 @@
+<template>
+  <div class="login-flex">
+    <div class="login">
+      <div class="logo"><img src="img/logo_blue.png" /></div>
+      <form>
+        <div>
+          <select id="server-select">
+            <option value="">请选择服务地址</option>
+          </select>
+        </div>
+        <div>
+          <input id="loginName-input" type="text" placeholder="请输入账号" />
+        </div>
+        <div>
+          <input id="password-input" type="password" placeholder="请输入密码" />
+        </div>
+        <div><a href="##" id="login-button">登录</a></div>
+      </form>
+    </div>
+    <div class="ft">
+      Copyright © 2011-2021 www.qmth.com.cn, All Rights Reserved
+    </div>
+  </div>
+</template>
+
+<script setup lang="ts">
+import { onMounted } from "@vue/runtime-core";
+
+Object.assign(
+  electron.env,
+  JSON.parse(window.localStorage.getItem("env") || "{}")
+);
+
+onMounted(() => {
+  window.localStorage.clear();
+  for (let i = 0; i < electron.config.servers.length; i++) {
+    let server = electron.config.servers[i];
+    // $('<option value="' + i + '">' + server.name + "</option>").appendTo(
+    //   $("#server-select")
+    // );
+  }
+});
+
+// document.onkeydown = function (event) {
+//     var e = event || window.event;
+//     if (e && e.keyCode == 13) { //回车键的键值为13
+//         $('#login-button').click() //调用登录按钮的登录事件
+//     }
+// }
+
+// $('#login-button').click(() => {
+//     let index = $('#server-select').val()
+//     if (index != '') {
+//         env.server = config.servers[parseInt(index)]
+//     } else {
+//         env.server = undefined
+//     }
+//     env.loginName = $('#loginName-input').val()
+//     env.password = $('#password-input').val()
+//     if (env.server == undefined) {
+//         alert('请选择服务地址')
+//         return
+//     }
+//     if (env.loginName == '') {
+//         alert('请输入账号')
+//         return
+//     }
+//     if (env.password == '') {
+//         alert('请输入密码')
+//         return
+//     }
+//     api.login().then(user => {
+//         env.user = user
+//         window.localStorage.setItem('env', JSON.stringify(env))
+//         window.location.href = 'exam-list.html'
+//     }).catch(err => {
+//         alert('登陆失败,用户名或密码错误')
+//     })
+// })
+
+// const {
+//   user: { userName },
+//   exam: { iid, name, examTime },
+// } = env;
+
+// $("#user-name").html(env.user.userName);
+
+// $("#exam-title").find(".id").html(env.exam.id);
+// $("#exam-title").find(".name").html(env.exam.name);
+// $("#exam-title").find(".time").html(env.exam.examTime);
+</script>

二進制
src/views/features/Login/img/back.png


二進制
src/views/features/Login/img/bg.jpg


二進制
src/views/features/Login/img/close.png


二進制
src/views/features/Login/img/data_btn.png


二進制
src/views/features/Login/img/enter.png


二進制
src/views/features/Login/img/error.png


二進制
src/views/features/Login/img/error_small.png


二進制
src/views/features/Login/img/icon1.png


二進制
src/views/features/Login/img/icon2.png


二進制
src/views/features/Login/img/icon3.png


二進制
src/views/features/Login/img/id.png


二進制
src/views/features/Login/img/logo.png


二進制
src/views/features/Login/img/logo_blue.png


二進制
src/views/features/Login/img/pic_btn.png


二進制
src/views/features/Login/img/radio.png


二進制
src/views/features/Login/img/select.png


二進制
src/views/features/Login/img/success.png


二進制
src/views/features/Login/img/success_small.png


+ 1 - 0
vue.config.js

@@ -19,6 +19,7 @@ module.exports = {
   transpileDependencies: [/\bvue-awesome\b/],
   pluginOptions: {
     electronBuilder: {
+      preload: "src/preload.ts",
       externals: [],
       builderOptions: {
         extraFiles: ["extra/**"],

+ 5 - 0
yarn.lock

@@ -10231,6 +10231,11 @@ verror@1.10.0, verror@^1.10.0:
     core-util-is "1.0.2"
     extsprintf "^1.2.0"
 
+vertx@^0.0.1-security:
+  version "0.0.1-security"
+  resolved "https://registry.nlark.com/vertx/download/vertx-0.0.1-security.tgz#886c73319e737e3db295ed658f4ba51eadbe7bff"
+  integrity sha1-iGxzMZ5zfj2yle1lj0ulHq2+e/8=
+
 vm-browserify@^1.0.1:
   version "1.1.2"
   resolved "https://registry.npm.taobao.org/vm-browserify/download/vm-browserify-1.1.2.tgz"