0
点赞
收藏
分享

微信扫一扫

SprinBoot+Vue家政公司服务平台的设计与实现

Raow1 2024-08-30 阅读 5

目录(本项目基于vue2)

1、打包成功后的样子​

 2、开发环境

3、开发流程(serve + build + 基础设置 + 系统托盘)

4、插件下载地址 

5、打包后的配置文件:

6、镜像


1、打包成功后的样子

 2、开发环境

3、开发流程(serve + build + 基础设置 + 系统托盘)

1、添加electron-builder

解决办法

vue/cli卸载重装 再运行vue add electron-builder

2、运行:npm run electron:serve

如下图:

3、打 包:npm run electron:build

打包报错

报错原因:

 其他插件存放位置

 

4、插件下载地址 

网络因素导致无法下载到的插件可以在下面地址进行手动下载

tips: 插件下载icon-default.png?t=N7T8https://mirrors.huaweicloud.com/electron-builder-binaries/

接下来就打包成功啦!!

如果打包出现以下跨域情况请细看下面的配置文件

5、打包后的配置文件:

background.js

"use strict";

import { app, protocol, Menu, BrowserWindow, ipcMain } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
const isDevelopment = process.env.NODE_ENV !== "production";

// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
  {
    scheme: "app",
    privileges: {
      secure: true,
      standard: true,
    },
  },
]);

async function createWindow() {
  // 获取可执行文件位置
  const ex = process.execPath;
  // 创建浏览器窗口
  Menu.setApplicationMenu(null); //隐藏菜单栏
  const win = new BrowserWindow({
    width: 1900, //最大宽高 不设置则自适应
    height: 1600,
    fullscreen: false, // 非全屏
    show: false, // 初始化不显示窗口
    webPreferences: {
      nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION, // 是否集成Node.js
      contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,  // 是否隔离渲染进程
      webSecurity: false, // 关闭web安全策略 配置跨域
      allowRunningInsecureContent: false, // 不允许加载不安全的内容 
    },
  });
  // win.maximize(); //窗口最大化
  win.show(); // 显示窗口
  // 打开控制台
  // win.webContents.openDevTools()
  // 根据环境变量加载URL
  if (process.env.WEBPACK_DEV_SERVER_URL) {
    await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
    if (!process.env.IS_TEST) win.webContents.openDevTools(); //调试工具
  } else {
    createProtocol("app"); // 使用自定义协议加载文件
    win.loadURL("app://./index.html"); 
    // win.loadURL('http://192.168.0.84:8086/index.html');
    // 窗口准备好之后,再显示
    win.once("ready-to-show", function() {
      win.show(); // 初始化后再显示
    });
  }
  // 开启开机自启动
  ipcMain.on("openAutoStart", () => {
    app.setLoginItemSettings({
      openAtLogin: true,
      path: ex,
      args: [],
    });
  });
  //检查更新
  // handleUpdate(win, "http://192.168.2.9:9700/")
}
// 监听Electron事件
app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

app.on("activate", () => {
  if (BrowserWindow.getAllWindows().length === 0) createWindow();
});

app.on("ready", async () => {
  if (isDevelopment && !process.env.IS_TEST) {
    try {
      await installExtension(VUEJS_DEVTOOLS);
    } catch (e) {
      console.error("Vue Devtools failed to install:", e.toString());
    }
  }
  createWindow();
});

if (isDevelopment) {
  if (process.platform === "win32") {
    process.on("message", (data) => {
      if (data === "graceful-exit") {
        app.quit();
      }
    });
  } else {
    process.on("SIGTERM", () => {
      app.quit();
    });
  }
}

vue.config.js

module.exports = {
    pluginOptions: {
        electronBuilder: {
            externals: [  // 外部依赖的模块列表
                'ws',
                "clipboard",
                "core-js",
                "electron-log" ,
                "qrcode",
                "soap",
                "view-design",
                "vue",
                "vue-router",
                "vuex",
                "x2js"
            ],
            nodeIntegration: true, // 允许在渲染进程中使用 Node.js 功能
            builderOptions: {
                nsis: {
                    allowToChangeInstallationDirectory: true, //允许选择安装目录
                    oneClick: false, // 非一键安装,需手动点击下一步
                },
                win: {
                    icon: './public/icon.png', // 设置应用图标
                    extraResources: "./static/*.html", // 额外资源
                    publish: [{
                        provider: 'generic', // 通用
                        url: 'http://192.168.0.84:8086/' // 跨域地址
                    }]
                },
                productName: 'xxx系统'  // 应用名称
            }
        },
    },
}

6、镜像

举报

相关推荐

0 条评论