electron-egg electron-egg
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
❤️成为赞助商
  • 快速入门

  • 基础功能

    • 目录结构
    • 生命周期
    • 前端模块

    • 控制器
    • 服务层
      • 预加载层
      • 通信

      • 数据库

      • 任务

      • 日志
      • 额外资源目录
      • 调试
      • 脚本工具
      • DLL使用
      • 调用第三方程序
      • 远程模式
    • 生成软件

    • 升级

    • 跨语言支持

    • 从v3升级v4
    • 更新记录
    • 常见问题
    目录

    服务层

    # 介绍

    业务逻辑层,建议按示例规则导出两个对象,ExampleService 和 exampleService

    • exampleService: 实例化对象,避免资源的重复创建和浪费,提高资源的利用效率,
    • ExampleService: 原始的类, 用于继承或 new 新的对象。

    # 示例

    const { logger } = require('ee-core/log');
    
    /**
     * 示例服务
     * @class
     */
    class ExampleService {
    
      /**
       * test
       */
      async test (args, event, other) {
        const obj = {
          status:'ok',
          params: args
        }
    
        // 主动向前端发请求
        // channel 前端ipc.on(),监听的路由
        const channel = "controller/example/something"
        // controller 传入 event
        // IpcMainInvokeEvent
        event.reply(channel, {age:21})
        // IpcMainEvent
        event.sender.send(`${channel}`, {age:21})
    
        return obj;
      }
    }
    ExampleService.toString = () => '[class ExampleService]';
    
    module.exports = {
      ExampleService,
      exampleService: new ExampleService()
    };
    
    上次更新: 2025/06/06, 07:21:49
    控制器
    预加载层

    ← 控制器 预加载层→

    Theme by Vdoing | Copyright © 2023-2025 哆啦好梦 | 京ICP备15041380号-2
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式
    ×