rest/types/attribute.go

49 lines
2.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package types
import (
"database/sql/driver"
"encoding/json"
)
type (
Attribute struct {
Match string `json:"match"` //匹配模式
Tag string `json:"tag,omitempty"` //字段标签
PrimaryKey bool `json:"primary_key"` //是否为主键
DefaultValue string `json:"default_value"` //默认值
Readonly []string `json:"readonly"` //只读场景
Disable []string `json:"disable"` //禁用场景
Visible []VisibleCondition `json:"visible"` //可见条
Invisible bool `json:"invisible"` //不可见的字段表示在UI界面看不到这个字段但是这个字段需要
EndOfNow bool `json:"end_of_now"` //最大时间为当前时间
Values []EnumValue `json:"values"` //值
Live LiveValue `json:"live"` //延时加载配置
UploadUrl string `json:"upload_url,omitempty"` //上传地址
Icon string `json:"icon,omitempty"` //显示图标
Sort bool `json:"sort"` //是否允许排序
Suffix string `json:"suffix,omitempty"` //追加内容
Tooltip string `json:"tooltip,omitempty"` //字段提示信息
Description string `json:"description,omitempty"` //字段说明信息
DropdownOption *DropdownOption `json:"dropdown,omitempty"` //下拉选项
}
)
// Scan implements the Scanner interface.
func (n *Attribute) Scan(value interface{}) error {
if value == nil {
return nil
}
switch s := value.(type) {
case string:
return json.Unmarshal([]byte(s), n)
case []byte:
return json.Unmarshal(s, n)
}
return ErrDbTypeUnsupported
}
// Value implements the driver Valuer interface.
func (n Attribute) Value() (driver.Value, error) {
return json.Marshal(n)
}