Skip to content

Commit

Permalink
发布 加入js调用go的例子
Browse files Browse the repository at this point in the history
  • Loading branch information
duolabmeng6 committed Oct 20, 2023
1 parent d83babe commit 6e644f6
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 10 deletions.
7 changes: 7 additions & 0 deletions wails-demo/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"github.com/duolabmeng6/goefun/ecore"
)

// App struct
Expand Down Expand Up @@ -31,3 +32,9 @@ func (a *App) E按钮1被点击() string {
println("E按钮1被点击")
return fmt.Sprintf("E按钮1被点击")
}

func (a *App) E获取系统时间() string {
println("E获取系统时间")
t := ecore.E取现行时间().E时间到文本("Y-m-d H:i:s")
return t
}
22 changes: 21 additions & 1 deletion wails-demo/frontend/src/窗口/窗口事件.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
export function 绑定窗口事件(c, 组件) {
import {
E获取系统时间
} from "../../wailsjs/go/main/App";

export function 绑定窗口事件(c, 组件) {
const 程序集变量 = {
time: null
}
c.按钮2被单击 = function () {
console.log("按钮2被单击")
组件.编辑框1.内容 = "祖国你好!"
}

c.按钮_获取时间被单击 = async () => {
console.log("按钮_获取时间被单击")
//js
//组件.编辑框_时间.内容 = new Date().toLocaleString()
//go
组件.编辑框_时间.内容 = await E获取系统时间()

clearInterval(程序集变量.time)
程序集变量.time = setInterval(async () => { (
组件.编辑框_时间.内容 = await E获取系统时间()
) }, 1000)

}
//事件函数位置不要删除
}
38 changes: 38 additions & 0 deletions wails-demo/frontend/src/窗口/设计文件.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,44 @@
"子容器": true,
"父容器id": "id-38334",
"子组件": [
{
"top": "116",
"left": "270",
"width": "76",
"height": "40",
"禁止放置": true,
"按钮类型": "default",
"可视": true,
"禁止": false,
"尺寸": "custom",
"层级": 0,
"id": "id-37592",
"组件名称": "按钮",
"名称": "按钮_获取时间",
"标题": "开始",
"data_id": "c9a710",
"事件被单击": "按钮_获取时间被单击"
},
{
"top": "117",
"left": "44",
"width": "211",
"height": "40",
"禁止放置": true,
"可视": true,
"禁止": false,
"层级": 0,
"尺寸": "custom",
"内容": "时间",
"输入框类型": "text",
"提示文本": "请输入..",
"最大长度": -1,
"id": "id-98518",
"组件名称": "编辑框",
"名称": "编辑框_时间",
"标题": "编辑框1",
"data_id": "dc4c51"
},
{
"top": "18",
"left": "25",
Expand Down
16 changes: 9 additions & 7 deletions wails-demo/frontend/src/窗口/辅助代码.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ function __辅助代码(list, 组件) {
组件.内容区域header1 = list[0].子组件[0].子组件[0].子组件[0].子组件[0]
组件.标签1 = list[0].子组件[0].子组件[0].子组件[0].子组件[0].子组件[0]
组件.内容区域main1 = list[0].子组件[0].子组件[0].子组件[0].子组件[1]
组件.弹性布局2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0]
组件.内容区域1 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0].子组件[0]
组件.标签2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0].子组件[0].子组件[0]
组件.内容区域2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0].子组件[1]
组件.编辑框1 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0].子组件[1].子组件[0]
组件.内容区域3 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0].子组件[2]
组件.按钮2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0].子组件[2].子组件[0]
组件.按钮_获取时间 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[0]
组件.编辑框_时间 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[1]
组件.弹性布局2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[2]
组件.内容区域1 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[2].子组件[0]
组件.标签2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[2].子组件[0].子组件[0]
组件.内容区域2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[2].子组件[1]
组件.编辑框1 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[2].子组件[1].子组件[0]
组件.内容区域3 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[2].子组件[2]
组件.按钮2 = list[0].子组件[0].子组件[0].子组件[0].子组件[1].子组件[2].子组件[2].子组件[0]
组件.内容区域footer1 = list[0].子组件[0].子组件[0].子组件[0].子组件[2]
组件.标签3 = list[0].子组件[0].子组件[0].子组件[0].子组件[2].子组件[0]
组件.内容区域aside1 = list[0].子组件[0].子组件[0].子组件[0].子组件[3]
Expand Down
2 changes: 2 additions & 0 deletions wails-demo/frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

export function E按钮1被点击():Promise<string>;

export function E获取系统时间():Promise<string>;

export function Greet(arg1:string):Promise<string>;
4 changes: 4 additions & 0 deletions wails-demo/frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export function E按钮1被点击() {
return window['go']['main']['App']['E按钮1被点击']();
}

export function E获取系统时间() {
return window['go']['main']['App']['E获取系统时间']();
}

export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1);
}
14 changes: 13 additions & 1 deletion wails-demo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ module changeme

go 1.18

require github.com/wailsapp/wails/v2 v2.6.0
require (
github.com/duolabmeng6/goefun v1.3.8
github.com/wailsapp/wails/v2 v2.6.0
)

require (
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogf/gf/v2 v2.4.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leaanthony/go-ansi-parser v1.6.0 // indirect
Expand All @@ -19,12 +28,15 @@ require (
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/tkrajina/go-reflector v0.5.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/wailsapp/go-webview2 v1.0.1 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.10.0 // indirect
Expand Down
Loading

0 comments on commit 6e644f6

Please sign in to comment.