82 lines
3.1 KiB
Go
82 lines
3.1 KiB
Go
|
package types
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
LiveValue struct {
|
||
|
Enable bool `json:"enable"`
|
||
|
Type string `json:"type"`
|
||
|
Url string `json:"url"`
|
||
|
Method string `json:"method"`
|
||
|
Body string `json:"body"`
|
||
|
ContentType string `json:"content_type"`
|
||
|
Columns []string `json:"columns"`
|
||
|
}
|
||
|
|
||
|
EnumValue struct {
|
||
|
Label string `json:"label"`
|
||
|
Value string `json:"value"`
|
||
|
Color string `json:"color"`
|
||
|
}
|
||
|
|
||
|
VisibleCondition struct {
|
||
|
Column string `json:"column"`
|
||
|
Values []interface{} `json:"values"`
|
||
|
}
|
||
|
|
||
|
DropdownOption struct {
|
||
|
Created bool `json:"created,omitempty"`
|
||
|
Filterable bool `json:"filterable,omitempty"`
|
||
|
Autocomplete bool `json:"autocomplete,omitempty"`
|
||
|
DefaultFirst bool `json:"default_first,omitempty"`
|
||
|
}
|
||
|
|
||
|
Scenarios []string
|
||
|
|
||
|
Schema struct {
|
||
|
Id uint64 `json:"id" gorm:"primary_key"`
|
||
|
CreatedAt int64 `json:"created_at" gorm:"autoCreateTime"` //创建时间
|
||
|
UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime"` //更新时间
|
||
|
Domain string `json:"domain" gorm:"column:domain;type:char(60);index"` //域
|
||
|
ModuleName string `json:"module_name" gorm:"column:module_name;type:varchar(60);index"` //模块名称
|
||
|
TableName string `json:"table_name" gorm:"column:table_name;type:varchar(120);index"` //表名称
|
||
|
Enable uint8 `json:"enable" gorm:"column:enable;type:int(1)"` //是否启用
|
||
|
Column string `json:"column" gorm:"type:varchar(120)"` //字段名称
|
||
|
Label string `json:"label" gorm:"type:varchar(120)"` //显示名称
|
||
|
Type string `json:"type" gorm:"type:varchar(120)"` //字段类型
|
||
|
Format string `json:"format" gorm:"type:varchar(120)"` //字段格式
|
||
|
Native uint8 `json:"native" gorm:"type:int(1)"` //是否为原生字段
|
||
|
IsPrimaryKey uint8 `json:"is_primary_key" gorm:"type:int(1)"` //是否为主键
|
||
|
Expression string `json:"expression" gorm:"type:varchar(526)"` //计算规则
|
||
|
Scenarios Scenarios `json:"scenarios" gorm:"type:varchar(120)"` //场景
|
||
|
Rule Rule `json:"rule" gorm:"type:varchar(2048)"` //字段规则
|
||
|
Attribute Attribute `json:"attribute" gorm:"type:varchar(4096)"` //字段属性
|
||
|
Position int `json:"position"` //字段排序位置
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func (n Scenarios) Has(str string) bool {
|
||
|
for _, v := range n {
|
||
|
if v == str {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// Scan implements the Scanner interface.
|
||
|
func (n *Scenarios) 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
|
||
|
}
|