Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page添加其他组件 #2

Open
littleboss01 opened this issue Sep 5, 2024 · 4 comments
Open

page添加其他组件 #2

littleboss01 opened this issue Sep 5, 2024 · 4 comments

Comments

@littleboss01
Copy link

littleboss01 commented Sep 5, 2024

没发现怎么添加curd以外的控件,
后台只有crud会不会太单调了.
尝试写了个函数,来添加自定义json文本

plugins/amis/page.go

func (p *Page) AddBodyByJsonStr(s string) {
	var v interface{}
	err := json.Unmarshal([]byte(s), &v)
	if err != nil {
		println(err.Error())
		return
	}

	switch v := v.(type) {
	case map[string]interface{}:
		// JSON 是对象
		p.AddBody(v)
	case []interface{}:
		// JSON 是数组
		for _, item := range v {
			p.AddBody(item)
		}
	default:
		// 其他类型,可以按需处理或忽略
		println("Unexpected JSON type")
	}
}
@littleboss01
Copy link
Author

自学的编程,刚入门,不知道怎么提交

增加创建以外的按钮,要是能设置按钮样式就好了
plugins/amis/curd.go

// AddCreate 创建按钮
func (c *Crud) AddCreate(form *Form) {
	f := form.SetApi(GetUrl(c.ctx, ""), "post")
	button := NewButton("创建").SetDialogForm(f)
	button.Level = "primary"
	//c.headerToolbar = []interface{}{
	//	button,
	//	"bulkActions",
	//}
	//保证创建按钮在首位
	c.headerToolbar = append([]interface{}{button, "bulkActions"}, c.headerToolbar)
}

func (c *Crud) AddCustomButton(form *Form, btnName string) {
	f := form.SetApi(GetUrl(c.ctx, ""), "post")
	button := NewButton(btnName).SetDialogForm(f)

	button.Level = "primary"
	c.headerToolbar = append(c.headerToolbar, button)
}

@ctfang
Copy link
Member

ctfang commented Sep 5, 2024

你直接fork后修改,再往上这个仓库提交合并吧

@ctfang
Copy link
Member

ctfang commented Sep 5, 2024

自学的编程,刚入门,不知道怎么提交

增加创建以外的按钮,要是能设置按钮样式就好了 plugins/amis/curd.go

// AddCreate 创建按钮
func (c *Crud) AddCreate(form *Form) {
	f := form.SetApi(GetUrl(c.ctx, ""), "post")
	button := NewButton("创建").SetDialogForm(f)
	button.Level = "primary"
	//c.headerToolbar = []interface{}{
	//	button,
	//	"bulkActions",
	//}
	//保证创建按钮在首位
	c.headerToolbar = append([]interface{}{button, "bulkActions"}, c.headerToolbar)
}

func (c *Crud) AddCustomButton(form *Form, btnName string) {
	f := form.SetApi(GetUrl(c.ctx, ""), "post")
	button := NewButton(btnName).SetDialogForm(f)

	button.Level = "primary"
	c.headerToolbar = append(c.headerToolbar, button)
}

多写写就熟了,怎么提交看 https://blog.csdn.net/m0_72619231/article/details/131501772

@ctfang
Copy link
Member

ctfang commented Sep 5, 2024

自学的编程,刚入门,不知道怎么提交

增加创建以外的按钮,要是能设置按钮样式就好了 plugins/amis/curd.go

// AddCreate 创建按钮
func (c *Crud) AddCreate(form *Form) {
	f := form.SetApi(GetUrl(c.ctx, ""), "post")
	button := NewButton("创建").SetDialogForm(f)
	button.Level = "primary"
	//c.headerToolbar = []interface{}{
	//	button,
	//	"bulkActions",
	//}
	//保证创建按钮在首位
	c.headerToolbar = append([]interface{}{button, "bulkActions"}, c.headerToolbar)
}

func (c *Crud) AddCustomButton(form *Form, btnName string) {
	f := form.SetApi(GetUrl(c.ctx, ""), "post")
	button := NewButton(btnName).SetDialogForm(f)

	button.Level = "primary"
	c.headerToolbar = append(c.headerToolbar, button)
}

如果你有兴趣,拉你进来一起维护都行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants