2 Star 0 Fork 0

远航 / goGUI基本绑定

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
  1. 程序基于go-astilectron感兴趣的大佬可以直接看 go-astilectron
  2. 基于个人渣渣程序员编码习惯做简单封装,不喜勿喷
  3. go-astilectron简单功能介绍:建立了js和go之间的通讯
  4. go的框架是 gframe
  5. 项目 码云地址

目录结构

go_gui_basic_binding     项目根目录
├─app                    你写代码的目录
  ├─bindHandle          go方法声明javaScript方法名目录
    ├─bind.go          go方法声明javaScript方法名文件
  
  ├─function            绑定到javaScript的方法目录
     ├─func.go          绑定到javaScript的方法文件

├─config                 配置文件命令
  ├─config.toml         配置文件,参考goFrame文档

├─database               数据文件目录
  ├─db                  我使用sqlite数据库,存放数据库文件

├─frame                  做了简单的封装,符合自己的使用习惯

├─output                 打包后的可执行文件目录

├─resources              静态文件目录
  ├─app                 模板文件目录,界面文件
    ├─static
       ├─js
         ├─app.js      基础通讯函数
         ├─func.js     提供给go的方法
    
  ├─icon.*              win,mac,linux端的图标

├─main.go                南天门

创建主页面:./resources/app/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="static/lib/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="static/lib/layui/css/layui.css">
</head>
<body>
<div id="test">

</div>
<script src="static/lib/layui/layui.all.js"></script>
<script src="static/js/func.js"></script>
<script src="static/js/app.js"></script>
<script type="module">
    // 引入func.js和app.js
    // 其他的按个人需要,可以引入VUE,jq,layui等 非常银杏

    // 按个人需求初始化对应类库,我这里需要jq就声明了个$方便在func.js里使用
    layui.use(['jquery'], function(){
        $ = layui.jquery;
    });
    // 初始化app
    app.init(function (data) {
        console.log(data)
    },function () {
        // 初始化完成
        app.goFunc("test","测试调用go方法")
    });
    // 初始化完成可以在任何地方调用
    // 比如
    app.goFunc("go绑定的方法名", '传递给go的参数')
</script>
</body>
</html>

绑定主页

// 是否开启浏览器控制台
app.Debug = true
initData := app.BaseStruct{
    Asset:         Asset,
    AssetDir:      AssetDir,
    RestoreAssets: RestoreAssets,
}
// 在main.go内绑定入口界面文件
ws := &astilectron.WindowOptions{
    BackgroundColor: astikit.StrPtr("#fff"),
    Center:          astikit.BoolPtr(true),
    // 窗口名称
    Title: astikit.StrPtr("主窗口"),
    // 启动窗口宽度
    Width: astikit.IntPtr(700),
    // 启动窗口高度
    Height: astikit.IntPtr(700),
}
// 入口界面 我们刚刚创建index.html就填index
app.Run("index", ws, initData)

启动程序

  1. 想换图标的自己转icns 图片转icns
  2. 转换格式不对图标不会生效,不行的换个工具转
  3. 下载编译工具 搞不定的自己恶补go mod
go get -u github.com/asticode/go-astilectron-bundler/...

go install github.com/asticode/go-astilectron-bundler/astilectron-bundler
  1. Mac端使命令生效,win自己配置环境变量
export PATH=$PATH:$GOPATH/bin
  1. 调试
  • 执行编译命令,这个时候会下载浏览器
  • 不能科学上网就复制地址去浏览器下载或者去 阿里镜像 下载
  • 直接ctrl+f搜索名字,你肉眼找不到的
  • 下载地址和下载后的文件名和目录在控制台都能看到
  • 下载好改名字放到对应目录重新执行编译命令
  • 如果还在下载那就是你目录或者文件名没对
  • 这个问题和作者大大反映了,看作者心情修复
  • 哪个正经程序员不会科学上网啊 ::(狗头)
// 编译
astilectron-bundler bd
// 启动,win的cmd不支持*通配符,正经人谁用cmd,换一个吧
go run *.go
  1. 基础命令,提示命令不存在就重新执行上面的步骤
astilectron-bundler    // 打包当前系统软件
astilectron-bundler -l // 打包Linux系统软件
astilectron-bundler -d // 打包MacOs系统软件
astilectron-bundler -w // 打包windows系统软件
astilectron-bundler -h // 查看命令

基础用法:编写提供给js的go方法

// ./app/function/finc.go 文件内编写
func Message(key string)  {
	fmt.Println("js调用了go的Message")
}
// 绑定到js ./app/bindHandle/bind.go 文件内编写
func Init()  {
    // 绑定刚刚写的Message方法
    // bind.Bind("js使用的key",方法)
	bind.Bind("Message",function.Message)
}
// js端调用
<script type="module">
    // 初始化app
    app.init(function (data) {
        console.log(data)
    },function () {
        // 初始化完成 调用go方法
        app.goFunc("Message","传递给go的参数")
    });
    // 初始化完成可以在任何地方调用
    // 比如
    app.goFunc("Message", '传递给go的参数')
</script>
// 注意事项 go在接收int参数的时候,js传递'1'是无法接收到的,注意类型
// 建议string

基础用法:编写提供给go的js方法

// ./resources/app/static/js/finc.js 文件内编写
function test(aaa) {
    console.log("调用js 方法成功")
    console.log(aaa)
}
// go端调用
// bind.JsFunc("方法名", "参数","窗口名称,默认主页")
bind.JsFunc("test", "测试调用js方法")

基础用法:创建新窗口 - go端

windows.Create("模板名称,不用.html", "窗口名称", 窗口参数, 是否打开浏览器控制台)
_, _ = windows.Create("bb", "tips", &astilectron.WindowOptions{
    Height: astikit.IntPtr(300),
    Width:  astikit.IntPtr(300),
    Title:  astikit.StrPtr("子窗口"),
}, true)

基础用法:日志输出 - go端

// 输出日志到浏览器控制台
log.Log("调用go方法成功")
log.Error()

没了没了

MIT License Copyright (c) 2017 Quentin Renard Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

在election 的基础上进行简单封装,方便自己使用 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/voyager-hang/go_gui_basic_binding.git
git@gitee.com:voyager-hang/go_gui_basic_binding.git
voyager-hang
go_gui_basic_binding
goGUI基本绑定
master

搜索帮助