mirror of
https://github.com/quarkcloudio/quark-go.git
synced 2025-10-06 16:36:56 +08:00
chore: wip
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/quarkcms/quark-go/pkg/app/handler/admin"
|
"github.com/quarkcms/quark-go/pkg/app/handler/admin"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/app/handler/miniapp"
|
||||||
"github.com/quarkcms/quark-go/pkg/app/handler/mix"
|
"github.com/quarkcms/quark-go/pkg/app/handler/mix"
|
||||||
"github.com/quarkcms/quark-go/pkg/app/handler/tool"
|
"github.com/quarkcms/quark-go/pkg/app/handler/tool"
|
||||||
"github.com/quarkcms/quark-go/pkg/app/install"
|
"github.com/quarkcms/quark-go/pkg/app/install"
|
||||||
@@ -25,6 +26,9 @@ func main() {
|
|||||||
// 加载Mix服务
|
// 加载Mix服务
|
||||||
providers = append(providers, mix.Providers...)
|
providers = append(providers, mix.Providers...)
|
||||||
|
|
||||||
|
// 加载MiniApp服务
|
||||||
|
providers = append(providers, miniapp.Providers...)
|
||||||
|
|
||||||
// 加载工具服务
|
// 加载工具服务
|
||||||
providers = append(providers, tool.Providers...)
|
providers = append(providers, tool.Providers...)
|
||||||
|
|
||||||
|
0
pkg/app/handler/miniapp/forms/.keep
Normal file
0
pkg/app/handler/miniapp/forms/.keep
Normal file
0
pkg/app/handler/miniapp/logins/.keep
Normal file
0
pkg/app/handler/miniapp/logins/.keep
Normal file
35
pkg/app/handler/miniapp/pages/index.go
Normal file
35
pkg/app/handler/miniapp/pages/index.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package pages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/quarkcms/quark-go/pkg/builder"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/builder/template/miniapppage"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/component/miniapp/navbar"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/component/miniapp/tabbar"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Index struct {
|
||||||
|
miniapppage.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
func (p *Index) Init() interface{} {
|
||||||
|
// 初始化模板
|
||||||
|
p.TemplateInit()
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 头部导航
|
||||||
|
func (p *Index) Navbar(ctx *builder.Context, navbar *navbar.Component) interface{} {
|
||||||
|
return navbar.SetTitle("首页")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件渲染
|
||||||
|
func (p *Index) Content(ctx *builder.Context) interface{} {
|
||||||
|
return "Hello World!"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 底部导航
|
||||||
|
func (p *Index) Tabbar(ctx *builder.Context, tabbar *tabbar.Component) interface{} {
|
||||||
|
return tabbar.SetBottom(true)
|
||||||
|
}
|
8
pkg/app/handler/miniapp/providers.go
Normal file
8
pkg/app/handler/miniapp/providers.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package miniapp
|
||||||
|
|
||||||
|
import "github.com/quarkcms/quark-go/pkg/app/handler/miniapp/pages"
|
||||||
|
|
||||||
|
// 注册服务
|
||||||
|
var Providers = []interface{}{
|
||||||
|
&pages.Index{},
|
||||||
|
}
|
105
pkg/builder/template/miniapppage/miniapppage.go
Normal file
105
pkg/builder/template/miniapppage/miniapppage.go
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package miniapppage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/quarkcms/quark-go/pkg/builder"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/builder/template"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/component/miniapp/navbar"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/component/miniapp/page"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/component/miniapp/tabbar"
|
||||||
|
"github.com/quarkcms/quark-go/pkg/dal/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 后台登录模板
|
||||||
|
type Template struct {
|
||||||
|
template.Template
|
||||||
|
Title string
|
||||||
|
Style string
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
func (p *Template) Init() interface{} {
|
||||||
|
p.TemplateInit()
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化模板
|
||||||
|
func (p *Template) TemplateInit() interface{} {
|
||||||
|
|
||||||
|
// 初始化数据对象
|
||||||
|
p.DB = db.Client
|
||||||
|
|
||||||
|
// 注册路由映射
|
||||||
|
p.GET("/api/miniapp/page/:resource/index", p.Render) // 渲染页面路由
|
||||||
|
|
||||||
|
// 标题
|
||||||
|
p.Title = "QuarkGo"
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 头部导航
|
||||||
|
func (p *Template) Navbar(ctx *builder.Context, navbar *navbar.Component) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内容
|
||||||
|
func (p *Template) Content(ctx *builder.Context) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 底部导航
|
||||||
|
func (p *Template) Tabbar(ctx *builder.Context, tabbar *tabbar.Component) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件渲染
|
||||||
|
func (p *Template) Render(ctx *builder.Context) error {
|
||||||
|
var (
|
||||||
|
components []interface{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 标题
|
||||||
|
title := reflect.
|
||||||
|
ValueOf(ctx.Template).
|
||||||
|
Elem().
|
||||||
|
FieldByName("Title").
|
||||||
|
String()
|
||||||
|
|
||||||
|
// 导航
|
||||||
|
navbar := ctx.Template.(interface {
|
||||||
|
Navbar(ctx *builder.Context, navbar *navbar.Component) interface{}
|
||||||
|
}).Navbar(ctx, navbar.New())
|
||||||
|
|
||||||
|
// 底部菜单
|
||||||
|
tabbar := ctx.Template.(interface {
|
||||||
|
Tabbar(ctx *builder.Context, tabbar *tabbar.Component) interface{}
|
||||||
|
}).Tabbar(ctx, tabbar.New())
|
||||||
|
|
||||||
|
// 样式
|
||||||
|
style := reflect.
|
||||||
|
ValueOf(ctx.Template).
|
||||||
|
Elem().
|
||||||
|
FieldByName("Style").
|
||||||
|
String()
|
||||||
|
|
||||||
|
// 内容
|
||||||
|
content := ctx.Template.(interface {
|
||||||
|
Content(ctx *builder.Context) interface{}
|
||||||
|
}).Content(ctx)
|
||||||
|
components = append(components, content)
|
||||||
|
|
||||||
|
// 组件
|
||||||
|
component := (&page.Component{}).
|
||||||
|
Init().
|
||||||
|
SetTitle(title).
|
||||||
|
SetNavbar(navbar).
|
||||||
|
SetTabbar(tabbar).
|
||||||
|
SetStyle(style).
|
||||||
|
SetContent(components).
|
||||||
|
JsonSerialize()
|
||||||
|
|
||||||
|
return ctx.JSON(200, component)
|
||||||
|
}
|
37
pkg/component/miniapp/component/element.go
Normal file
37
pkg/component/miniapp/component/element.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package component
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
|
||||||
|
"github.com/go-basic/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Element struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
ComponentKey string `json:"componentKey"`
|
||||||
|
Component string `json:"component"`
|
||||||
|
Style interface{} `json:"style"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_KEY = ""
|
||||||
|
const DEFAULT_CRYPT = true
|
||||||
|
|
||||||
|
// 设置Key
|
||||||
|
func (p *Element) SetKey(key string, crypt bool) *Element {
|
||||||
|
|
||||||
|
if key == "" {
|
||||||
|
key = uuid.New()
|
||||||
|
}
|
||||||
|
|
||||||
|
if crypt {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(key))
|
||||||
|
key = hex.EncodeToString(h.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Key = key
|
||||||
|
p.ComponentKey = key
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
56
pkg/component/miniapp/navbar/navbar.go
Normal file
56
pkg/component/miniapp/navbar/navbar.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package navbar
|
||||||
|
|
||||||
|
import "github.com/quarkcms/quark-go/pkg/component/miniapp/component"
|
||||||
|
|
||||||
|
type Component struct {
|
||||||
|
component.Element
|
||||||
|
Title string `json:"title"`
|
||||||
|
LeftText string `json:"leftText"`
|
||||||
|
Desc string `json:"desc"`
|
||||||
|
LeftShow bool `json:"leftShow"`
|
||||||
|
TitleIcon bool `json:"titleIcon"`
|
||||||
|
Border bool `json:"border"`
|
||||||
|
Fixed bool `json:"fixed"`
|
||||||
|
Placeholder bool `json:"placeholder"`
|
||||||
|
SafeAreaInsetTop bool `json:"safeAreaInsetTop"`
|
||||||
|
ZIndex int `json:"zIndex"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化组件
|
||||||
|
func New() *Component {
|
||||||
|
return (&Component{}).Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
func (p *Component) Init() *Component {
|
||||||
|
p.Component = "navbar"
|
||||||
|
p.SetKey("navbar", component.DEFAULT_CRYPT)
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set style.
|
||||||
|
func (p *Component) SetStyle(style interface{}) *Component {
|
||||||
|
p.Style = style
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标题
|
||||||
|
func (p *Component) SetTitle(title string) *Component {
|
||||||
|
p.Title = title
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 左侧文案
|
||||||
|
func (p *Component) SetLeftText(leftText string) *Component {
|
||||||
|
p.LeftText = leftText
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件json序列化
|
||||||
|
func (p *Component) JsonSerialize() *Component {
|
||||||
|
p.Component = "navbar"
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
62
pkg/component/miniapp/page/page.go
Normal file
62
pkg/component/miniapp/page/page.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package page
|
||||||
|
|
||||||
|
import "github.com/quarkcms/quark-go/pkg/component/miniapp/component"
|
||||||
|
|
||||||
|
type Component struct {
|
||||||
|
component.Element
|
||||||
|
Title string `json:"title"`
|
||||||
|
Navbar interface{} `json:"navbar"`
|
||||||
|
Content interface{} `json:"content"`
|
||||||
|
Tabbar interface{} `json:"tabbar"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化组件
|
||||||
|
func New() *Component {
|
||||||
|
return (&Component{}).Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
func (p *Component) Init() *Component {
|
||||||
|
p.Component = "page"
|
||||||
|
p.SetKey("page", component.DEFAULT_CRYPT)
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set style.
|
||||||
|
func (p *Component) SetStyle(style interface{}) *Component {
|
||||||
|
p.Style = style
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标题
|
||||||
|
func (p *Component) SetTitle(title string) *Component {
|
||||||
|
p.Title = title
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 头部导航
|
||||||
|
func (p *Component) SetNavbar(navbar interface{}) *Component {
|
||||||
|
p.Navbar = navbar
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内容
|
||||||
|
func (p *Component) SetContent(content interface{}) *Component {
|
||||||
|
p.Content = content
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 底部导航
|
||||||
|
func (p *Component) SetTabbar(tabbar interface{}) *Component {
|
||||||
|
p.Tabbar = tabbar
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件json序列化
|
||||||
|
func (p *Component) JsonSerialize() *Component {
|
||||||
|
p.Component = "page"
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
47
pkg/component/miniapp/tabbar/tabbar.go
Normal file
47
pkg/component/miniapp/tabbar/tabbar.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package tabbar
|
||||||
|
|
||||||
|
import "github.com/quarkcms/quark-go/pkg/component/miniapp/component"
|
||||||
|
|
||||||
|
type Component struct {
|
||||||
|
component.Element
|
||||||
|
Bottom bool `json:"bottom"`
|
||||||
|
UnactiveColor string `json:"unactiveColor"`
|
||||||
|
ActiveColor string `json:"activeColor"`
|
||||||
|
SafeAreaInsetBottom bool `json:"safeAreaInsetBottom"`
|
||||||
|
Placeholder bool `json:"placeholder"`
|
||||||
|
Items interface{} `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化组件
|
||||||
|
func New() *Component {
|
||||||
|
return (&Component{}).Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
func (p *Component) Init() *Component {
|
||||||
|
p.Component = "tabbar"
|
||||||
|
p.SetKey("tabbar", component.DEFAULT_CRYPT)
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set style.
|
||||||
|
func (p *Component) SetStyle(style interface{}) *Component {
|
||||||
|
p.Style = style
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否固定在页面底部
|
||||||
|
func (p *Component) SetBottom(bottom bool) *Component {
|
||||||
|
p.Bottom = bottom
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件json序列化
|
||||||
|
func (p *Component) JsonSerialize() *Component {
|
||||||
|
p.Component = "tabbar"
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
Reference in New Issue
Block a user