gosdk/config/form.go

52 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import "encoding/json"
const (
FormTypeInput = "input" //文本输入框
FormTypeText = "text" //多行文本
FormTypeRadio = "radio" //单选框
FormTypeCheckbox = "checkbox" //单选框
FormTypeSwitch = "switch" //开关
FormTypeJson = "json" //JSON输入框
)
type FormOption struct {
Name string `json:"name"` //选项名称
Value string `json:"value"` //选项值
}
type Form struct {
Type string `json:"type"` //表单类型
Name string `json:"name"` //表单名称
Key string `json:"key"` //表单KEY
Value interface{} `json:"value"` //表单值
Disable bool `json:"disable,omitempty"` //是否禁用
Tips string `json:"tips"` //表单提示
Option []*FormOption `json:"option"` //表单选项radion和checkbox需要
}
func NewFroms(tplConfig, saveConfig string) ([]*Form, error) {
var forms []*Form
err := json.Unmarshal([]byte(tplConfig), &forms)
if err != nil {
return nil, err
}
var cfg map[string]interface{}
err = json.Unmarshal([]byte(saveConfig), &cfg)
if err != nil {
return nil, err
}
if cfg == nil {
cfg = make(map[string]interface{})
}
for _, form := range forms {
if _, ok := cfg[form.Key]; ok {
form.Value = cfg[form.Key]
}
}
return forms, err
}