|
|
package protocol
|
|
|
|
|
|
import "sort"
|
|
|
|
|
|
//输入框类型
|
|
|
const (
|
|
|
inputTypeCheck string = "check-box" //多选宽
|
|
|
inputTypeText string = "text" //单行文本宽
|
|
|
InputTypeRedio string = "redio" //单选框
|
|
|
)
|
|
|
|
|
|
//InputElement 自定义表单项
|
|
|
type InputElement struct {
|
|
|
Sort int `json:"sort"` //排序
|
|
|
Lable string `json:"lable"` //标题
|
|
|
InputType string `json:"input_type"` //输入类型
|
|
|
ValueList string `json:"value_list"` //输入候选值
|
|
|
Required bool `json:"required"` //是否必填
|
|
|
Placeholder string `json:"Placeholder"` //帮助用户填写输入字段的提示
|
|
|
Disable bool `json:"disable ` //"显示隐藏",
|
|
|
CurrentValue string `json:"current_value"` //"当前填写的值"
|
|
|
}
|
|
|
|
|
|
//自定义表单
|
|
|
type CustomForm []InputElement
|
|
|
|
|
|
var (
|
|
|
_ sort.Interface = new(CustomForm)
|
|
|
)
|
|
|
|
|
|
//实现排序接口
|
|
|
func (a CustomForm) Len() int { return len(a) }
|
|
|
func (a CustomForm) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
func (a CustomForm) Less(i, j int) bool {
|
|
|
return a[i].Sort < a[j].Sort
|
|
|
}
|
|
|
|
|
|
//IValidateInput 自定义输入项校验接口
|
|
|
type IValidateInput interface {
|
|
|
ValidateInput() error //校验当前输入值
|
|
|
ValidateConfig() error //校验自定义的输入项设置
|
|
|
}
|
|
|
|
|
|
type ValidateInputText struct {
|
|
|
InputElement
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
_ IValidateInput = ValidateInputText{}
|
|
|
)
|
|
|
|
|
|
func (input ValidateInputText) ValidateInput() error {
|
|
|
return nil
|
|
|
}
|
|
|
func (input ValidateInputText) ValidateConfig() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//ValidateInputRedio 单选项校验
|
|
|
type ValidateInputRedio struct {
|
|
|
InputElement
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
_ IValidateInput = ValidateInputRedio{}
|
|
|
)
|
|
|
|
|
|
func (input ValidateInputRedio) ValidateInput() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (input ValidateInputRedio) ValidateConfig() error {
|
|
|
return nil
|
|
|
} |
...
|
...
|
|