wangjunbo4 há 3 anos atrás
pai
commit
cc6af1fe0c
9 ficheiros alterados com 867 adições e 363 exclusões
  1. BIN
      .DS_Store
  2. 10 14
      .vscode/launch.json
  3. 0 54
      index.html
  4. 7 1
      js/js.js
  5. 157 41
      main.js
  6. 682 238
      package-lock.json
  7. 11 3
      package.json
  8. 0 12
      preload.js
  9. BIN
      result.xlsx

BIN
.DS_Store


+ 10 - 14
.vscode/launch.json

@@ -1,18 +1,14 @@
 {
-    "version": "0.2.0",
     "configurations": [
-        {
-            "name": "Debug Main Process",
-            "type": "node",
-            "request": "launch",
-            "cwd": "${workspaceFolder}",
-            "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
-            "windows": {
-                "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
-            },
-            "args": [
-                "."
-            ]
-        }
+    {
+        "name": "Electron Main",
+        "program": "${workspaceFolder}/main.js",
+        "request": "launch",
+        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
+        "skipFiles": [
+            "<node_internals>/**"
+        ],
+        "type": "node"
+    }
     ]
 }

+ 0 - 54
index.html

@@ -1,54 +0,0 @@
-<!DOCTYPE html>
-<html>
-
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-    <title>全排列软件</title>
-    <script type="text/javascript" src="js/js.js"></script>
-    <style>
-        .div-1 {
-            float: left;
-            width: 49%;
-        }
-
-        .div-2 {
-            float: right;
-            width: 49%;
-        }
-        .div-1-1 {
-            height: 425px;
-            border: 1px solid;
-        }
-
-        .text-0 {
-            overflow-x: scroll;
-            overflow-y: scroll;
-        }
-    </style>
-</head>
-
-<body>
-    <div class="div-1">
-        <div>
-           <p>输入</p>
-        
-        </div>
-        <div id="thingsBox" class="div-1-1">
-            
-        </div>
-        <br>
-        <div>
-            <input id="in">
-            <button onclick="add()">添加</button>
-            <button onclick="delall()">清空</button>
-            <button onclick="start()">开始</button>
-        </div>
-        
-    </div>
-    <div class="div-2">
-        <p>全排列</p>
-        <textarea class="text-0" id="texts" rows="30" cols="40"></textarea>
-    </div>
-</body>
-
-</html>

+ 7 - 1
js/js.js

@@ -2,7 +2,7 @@
  * @Author: Gtylcara.
  * @Date: 2021-03-27 00:07:00
  * @LastEditors: Gtylcara.
- * @LastEditTime: 2021-03-29 17:27:02
+ * @LastEditTime: 2022-07-06 00:07:04
  */
 
 
@@ -69,6 +69,12 @@ function del(id)
     text.innerHTML = "";
 }
 
+// send message to main process with electron api
+function sendMessage() {
+    const { ipcRenderer } = require('electron')
+    ipcRenderer.send('asynchronous-message', 'ping')
+}
+
 function start()
 {
     full(things, 0, things.length)

+ 157 - 41
main.js

@@ -1,47 +1,163 @@
-/*
- * @Author: Gtylcara.
- * @Date: 2021-03-26 23:23:14
- * @LastEditors: Gtylcara.
- * @LastEditTime: 2021-03-27 00:01:04
+/* eslint global-require: off, no-console: off, promise/always-return: off */
+
+/**
+ * This module executes inside of electron's main process. You can start
+ * electron renderer process from here and communicate with the other processes
+ * through IPC.
+ *
+ * When running `npm run build` or `npm run build:main`, this file is compiled to
+ * `./src/main.js` using webpack. This gives us some performance wins.
  */
-// Modules to control application life and create native browser window
-const {app, BrowserWindow} = require('electron')
-const path = require('path')
-
-function createWindow () {
-  // Create the browser window.
-  const mainWindow = new BrowserWindow({
-    width: 800,
-    height: 600,
-    webPreferences: {
-      preload: path.join(__dirname, 'preload.js')
+
+const path = require ('path');
+const { app, BrowserWindow, shell, ipcMain } = require('electron');
+const { autoUpdater } = require('electron-updater');
+const log = require('electron-log');
+const puppeteer = require('puppeteer');
+
+class AppUpdater {
+    constructor() {
+        log.transports.file.level = 'info';
+        autoUpdater.logger = log;
+        autoUpdater.checkForUpdatesAndNotify();
     }
-  })
+}
+
+let mainWindow = null;
+
+ipcMain.on('ipc-example', async (event, arg) => {
+    const msgTemplate = (pingPong) => `IPC test: ${pingPong}`;
+    console.log(msgTemplate(arg));
+    event.reply('ipc-example', msgTemplate('pong'));
+});
+
+if (process.env.NODE_ENV === 'production') {
+    const sourceMapSupport = require('source-map-support');
+    sourceMapSupport.install();
+}
 
-  // and load the index.html of the app.
-  mainWindow.loadFile('index.html')
+const isDebug =
+    process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
 
+if (isDebug) {
+    require('electron-debug')();
 }
 
-// This method will be called when Electron has finished
-// initialization and is ready to create browser windows.
-// Some APIs can only be used after this event occurs.
-app.whenReady().then(() => {
-  createWindow()
-  
-  app.on('activate', function () {
-    // On macOS it's common to re-create a window in the app when the
-    // dock icon is clicked and there are no other windows open.
-    if (BrowserWindow.getAllWindows().length === 0) createWindow()
-  })
-})
-
-// 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.
-app.on('window-all-closed', function () {
-  if (process.platform !== 'darwin') app.quit()
-})
-
-// In this file you can include the rest of your app's specific main process
-// code. You can also put them in separate files and require them here.
+const installExtensions = async () => {
+    const installer = require('electron-devtools-installer');
+    const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
+    const extensions = ['REACT_DEVELOPER_TOOLS'];
+
+    return installer
+        .default(
+            extensions.map((name) => installer[name]),
+            forceDownload
+        )
+        .catch(console.log);
+};
+
+const createWindow = async () => {
+    if (isDebug) {
+        await installExtensions();
+    }
+
+    const RESOURCES_PATH = app.isPackaged
+        ? path.join(process.resourcesPath, 'assets')
+        : path.join(__dirname, '../../assets');
+
+    const getAssetPath = (...paths) => {
+        return path.join(RESOURCES_PATH, ...paths);
+    };
+
+    mainWindow = new BrowserWindow({
+        show: false,
+        width: 1024,
+        height: 728,
+        icon: getAssetPath('icon.png'),
+        webPreferences: {
+            preload: app.isPackaged
+                ? path.join(__dirname, 'preload.js')
+                : path.join(__dirname, '../../.erb/dll/preload.js'),
+        },
+    });
+
+    // mainWindow.loadURL('');
+
+    
+
+    async function func() {
+        const browser = await puppeteer.launch({
+            headless: false,
+            defaultViewport: false
+        })
+
+        const page = await browser.newPage();
+        await page.goto('http://yct.sh.gov.cn/portal_yct/')
+
+        await page.waitForSelector('#scroll_list')
+
+        const data = await page.$$eval('#scroll_list', data => {
+            return data.map(a => {
+                return {
+                    'title': a.children[0].title
+                }
+            });
+        });
+
+        console.log(data)
+        // await browser.close();
+    }
+    puppeteer.launch().then(
+        func()
+    );
+
+    mainWindow.on('ready-to-show', () => {
+        if (!mainWindow) {
+            throw new Error('"mainWindow" is not defined');
+        }
+        if (process.env.START_MINIMIZED) {
+            mainWindow.minimize();
+        } else {
+            mainWindow.show();
+        }
+    });
+
+    mainWindow.on('closed', () => {
+        mainWindow = null;
+    });
+
+
+    // Open urls in the user's browser
+    mainWindow.webContents.setWindowOpenHandler((edata) => {
+        shell.openExternal(edata.url);
+        return { action: 'deny' };
+    });
+
+    // Remove this if your app does not use auto updates
+    // eslint-disable-next-line
+    new AppUpdater();
+};
+
+/**
+ * Add event listeners...
+ */
+
+app.on('window-all-closed', () => {
+    // Respect the OSX convention of having the application in memory even
+    // after all windows have been closed
+    if (process.platform !== 'darwin') {
+        app.quit();
+    }
+});
+
+app
+    .whenReady()
+    .then(() => {
+        createWindow();
+        app.on('activate', () => {
+            // On macOS it's common to re-create a window in the app when the
+            // dock icon is clicked and there are no other windows open.
+            if (mainWindow === null) createWindow();
+        });
+    })
+    .catch(console.log);

Diff do ficheiro suprimidas por serem muito extensas
+ 682 - 238
package-lock.json


+ 11 - 3
package.json

@@ -8,11 +8,19 @@
     "build": "node --max_old_space_size=8192 .electron-vue/build.js && electron-builder"
   },
   "repository": "",
-  "keywords": [
-  ],
+  "keywords": [],
   "author": "Gtylcara",
   "license": "CC0-1.0",
   "devDependencies": {
-    "electron": "^12.0.2"
+    "electron": "^12.0.2",
+    "jquery": "^3.6.0"
+  },
+  "dependencies": {
+    "electron-log": "^4.4.8",
+    "electron-updater": "^5.3.0",
+    "fs": "^0.0.1-security",
+    "jq": "^1.7.2",
+    "node-xlsx": "^0.21.0",
+    "puppeteer": "^19.2.0"
   }
 }

+ 0 - 12
preload.js

@@ -1,12 +0,0 @@
-// All of the Node.js APIs are available in the preload process.
-// It has the same sandbox as a Chrome extension.
-window.addEventListener('DOMContentLoaded', () => {
-  const replaceText = (selector, text) => {
-    const element = document.getElementById(selector)
-    if (element) element.innerText = text
-  }
-
-  for (const type of ['chrome', 'node', 'electron']) {
-    replaceText(`${type}-version`, process.versions[type])
-  }
-})

BIN
result.xlsx


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff