papitable

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CELL_VALUE_KEY_TYPE_FIELD_TITLE = "name" // apitable 使用 name 作为字段键
	CELL_VALUE_KEY_TYPE_FIELD_ID    = "id"   // apitable 使用 id 作为字段键
)

Variables

This section is empty.

Functions

func InitAPITable

func InitAPITable(token string, baseUrl string) (err error)

func InitAPITableByConfig

func InitAPITableByConfig() error

--------------------------------------------------

func NewCheckboxValue

func NewCheckboxValue(checked bool) bool

--------------------------------------------------

func NewEmailValue

func NewEmailValue(email string) string

--------------------------------------------------

func NewMultiSelectValue

func NewMultiSelectValue(options ...string) []string

--------------------------------------------------

func NewNumValue

func NewNumValue(value float64) float64

func NewOneWayLinkValue

func NewOneWayLinkValue(recordIds ...string) []string

--------------------------------------------------

func NewPhoneValue

func NewPhoneValue(phone string) string

--------------------------------------------------

func NewRatingValue

func NewRatingValue(rating float64) float64

--------------------------------------------------

func NewSingleSelectValue

func NewSingleSelectValue(option string) string

--------------------------------------------------

func NewTextValue

func NewTextValue(text string) string

--------------------------------------------------

func NewTimeValue

func NewTimeValue(t time.Time) float64

--------------------------------------------------

func NewTwoWayLinkValue

func NewTwoWayLinkValue(recordIds ...string) []string

-------------------------------------------------- 双向链接值

func ParseAutoNumberValue

func ParseAutoNumberValue(value any) (float64, error)

-------------------------------------------------- 解析自动编号值(只读字段)

func ParseCheckboxValue

func ParseCheckboxValue(value any) (bool, error)

func ParseEmailValue

func ParseEmailValue(value any) (string, error)

func ParseFormulaValue

func ParseFormulaValue(value any) (any, error)

解析公式值(只读字段)

func ParseMagicLookUpValue

func ParseMagicLookUpValue(value any) ([]interface{}, error)

解析引用值(只读字段)

func ParseMultiSelectValue

func ParseMultiSelectValue(value any) ([]string, error)

func ParseNumValue

func ParseNumValue(value any) (float64, error)

func ParseOneWayLinkValue

func ParseOneWayLinkValue(value any) ([]string, error)

func ParsePhoneValue

func ParsePhoneValue(value any) (string, error)

func ParseRatingValue

func ParseRatingValue(value any) (float64, error)

func ParseSingleSelectValue

func ParseSingleSelectValue(value any) (string, error)

func ParseTextValue

func ParseTextValue(value any) (string, error)

func ParseTimeValue

func ParseTimeValue(value any) (time.Time, error)

func ParseTwoWayLinkValue

func ParseTwoWayLinkValue(value any) ([]string, error)

Types

type AddField

type AddField struct {
	Type     FieldType      `json:"type"`
	Name     string         `json:"name"`
	Property map[string]any `json:"property"`
}

func NewSimpleNumCol

func NewSimpleNumCol(colName string) *AddField

--------------------------------------------------

func NewSimpleSingleSelectCol

func NewSimpleSingleSelectCol(colName string, options []*SelectFieldOption) *AddField

func NewSimpleTimeCol

func NewSimpleTimeCol(colName string) *AddField

--------------------------------------------------

func NewSimpleUserCol

func NewSimpleUserCol(colName string, isMultiple bool) *AddField

--------------------------------------------------

func NewTextCol

func NewTextCol(colName string) *AddField

type AddRecord

type AddRecord struct {
	Values map[string]any `json:"fields"`
}

-------------------------------------------------- 添加记录结构

type CellAttachmentValue

type CellAttachmentValue struct {
	MimeType string `json:"mimeType"`          // 附件的媒体类型
	Name     string `json:"name"`              // 附件的名称
	Size     int32  `json:"size"`              // 附件的大小,单位为字节
	Width    int32  `json:"width,omitempty"`   // 如果附件是图片格式,表示图片的宽度,单位为px
	Height   int32  `json:"height,omitempty"`  // 如果附件是图片格式,表示图片的高度,单位为px
	Token    string `json:"token"`             // 附件的访问路径
	Preview  string `json:"preview,omitempty"` // 如果附件是PDF格式,将会生成一个预览图,用户可以通过此网址访问
}

-------------------------------------------------- 附件类型单元格值

func NewAttachmentValue

func NewAttachmentValue(attachments ...CellAttachmentValue) []CellAttachmentValue

func ParseAttachmentValue

func ParseAttachmentValue(value any) ([]CellAttachmentValue, error)

type CellOption

type CellOption string

--------------------------------------------------

func NewOptionValue

func NewOptionValue(option *SelectFieldOption) *CellOption

func ParseSingleOptionValue

func ParseSingleOptionValue(value any) (*CellOption, error)

func (*CellOption) GetKey

func (opt *CellOption) GetKey() string

type CellUrlValue

type CellUrlValue struct {
	Title   string `json:"title"`   // 网页标题
	Text    string `json:"text"`    // 网页地址
	Favicon string `json:"favicon"` // 网页 ICON
}

-------------------------------------------------- 链接类型单元格值

func NewUrlValue

func NewUrlValue(title, text, favicon string) CellUrlValue

func ParseUrlValue

func ParseUrlValue(value any) (*CellUrlValue, error)

type CellUserValue

type CellUserValue struct {
	// Id     string `json:"id"`               // 组织单元的ID
	UserId string `json:"id"`               // 组织单元的ID
	Type   int32  `json:"type"`             // 组织单元的类型,1是小组,3是成员
	Name   string `json:"name"`             // 小组或成员的名称
	Avatar string `json:"avatar,omitempty"` // 头像URL,只读,不可写入
}

-------------------------------------------------- 成员类型单元格值

func NewUserValue

func NewUserValue(userIds ...string) []CellUserValue

func ParseUserValue

func ParseUserValue(value any) ([]CellUserValue, error)

type CellWorkDocValue

type CellWorkDocValue struct {
	DocumentId string `json:"documentId"`
	Title      string `json:"title"`
}

-------------------------------------------------- 工作文档类型单元格值

func NewWorkDocValue

func NewWorkDocValue(workDocs ...CellWorkDocValue) []CellWorkDocValue

func ParseWorkDocValue

func ParseWorkDocValue(value any) ([]CellWorkDocValue, error)

type CommonRecord

type CommonRecord struct {
	RecordId  string         `json:"recordId"`
	Fields    map[string]any `json:"fields"`
	CreatedAt int64          `json:"createdAt"`
	UpdatedAt int64          `json:"updatedAt"`
}

--------------------------------------------------

type Field

type Field struct {
	Id       string         `json:"id"`
	Name     string         `json:"name"`
	Type     FieldType      `json:"type"`
	Desc     string         `json:"desc,omitempty"`
	Property map[string]any `json:"property"`
}

type FieldType

type FieldType string

-------------------------------------------------- 字段类型 -------------------------------------------------- 字段类型常量

const (
	// FIELD_TYPE_SINGLE_TEXT FieldType = "SingleText" //单行文本
	// FIELD_TYPE_TEXT               FieldType = "Text"             //多行文本
	FIELD_TYPE_TEXT FieldType = "SingleText" // 用一个就好了,文档有两个类型

	FIELD_TYPE_SINGLE_SELECT      FieldType = "SingleSelect"     //单选
	FIELD_TYPE_MULTI_SELECT       FieldType = "MultiSelect"      //多选
	FIELD_TYPE_NUMBER             FieldType = "Number"           //数字
	FIELD_TYPE_CURRENCY           FieldType = "Currency"         //货币
	FIELD_TYPE_PERCENT            FieldType = "Percent"          //百分比
	FIELD_TYPE_DATE_TIME          FieldType = "DateTime"         //日期
	FIELD_TYPE_ATTACHMENT         FieldType = "Attachment"       //附件
	FIELD_TYPE_MEMBER             FieldType = "Member"           //成员
	FIELD_TYPE_CHECKBOX           FieldType = "Checkbox"         //勾选
	FIELD_TYPE_RATING             FieldType = "Rating"           //评分
	FIELD_TYPE_URL                FieldType = "URL"              //网址
	FIELD_TYPE_PHONE              FieldType = "Phone"            //电话
	FIELD_TYPE_EMAIL              FieldType = "Email"            //邮箱
	FIELD_TYPE_WORK_DOC           FieldType = "WorkDoc"          //轻文档
	FIELD_TYPE_ONE_WAY_LINK       FieldType = "OneWayLink"       //单向关联
	FIELD_TYPE_TWO_WAY_LINK       FieldType = "TwoWayLink"       //双向关联
	FIELD_TYPE_MAGIC_LOOKUP       FieldType = "MagicLookUp"      //神奇引用
	FIELD_TYPE_FORMULA            FieldType = "Formula"          //智能公式
	FIELD_TYPE_AUTO_NUMBER        FieldType = "AutoNumber"       //自增数字
	FIELD_TYPE_CREATED_TIME       FieldType = "CreatedTime"      //创建时间
	FIELD_TYPE_LAST_MODIFIED_TIME FieldType = "LastModifiedTime" //修改时间
	FIELD_TYPE_CREATED_BY         FieldType = "CreatedBy"        //创建人
	FIELD_TYPE_LAST_MODIFIED_BY   FieldType = "LastModifiedBy"   //更新人
	FIELD_TYPE_BUTTON             FieldType = "Button"           //按钮
)

type GetRecordRequest

type GetRecordRequest struct {
	PageSize       int        `json:"pageSize,omitempty"`
	MaxRecords     int        `json:"maxRecords,omitempty"`
	PageNum        int        `json:"pageNum,omitempty"`
	Sort           []SortRule `json:"sort,omitempty"`
	RecordIds      []string   `json:"recordIds,omitempty"`
	ViewId         string     `json:"viewId,omitempty"`
	Fields         []string   `json:"fields,omitempty"`
	FilterByFrmula string     `json:"filterByFrmula,omitempty"`
	CellFormat     string     `json:"cellFormat,omitempty"`
	FieldKey       string     `json:"fieldKey,omitempty"`
}

查询记录请求结构

type GetTeamListResponse

type GetTeamListResponse struct {
	Success bool   `json:"success"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    struct {
		PageNum  int     `json:"pageNum"`
		PageSize int     `json:"pageSize"`
		Total    int     `json:"total"`
		Teams    []*Team `json:"teams"`
	} `json:"data"`
}

GetTeamListResponse 获取小组列表响应

type GetTeamMembersResponse

type GetTeamMembersResponse struct {
	Success bool   `json:"success"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    struct {
		PageNum  int     `json:"pageNum"`
		PageSize int     `json:"pageSize"`
		Total    int     `json:"total"`
		Members  []*User `json:"members"`
	} `json:"data"`
}

GetTeamMembersResponse 获取小组成员响应

type GetUserResponse

type GetUserResponse struct {
	Success bool   `json:"success"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    User   `json:"data"`
}

GetUserResponse 获取单个用户响应

type MultiTableDoc

type MultiTableDoc struct {
	SpaceId     string `json:"spaceId"`     // 空间ID
	DatasheetId string `json:"datasheetId"` // 数据表ID
}

func CreateMultiTable

func CreateMultiTable(spaceId, tblName string, keyCol *AddField) (doc *MultiTableDoc, err error)

APITable 首列不能隐藏/删除/拖拽等等操作,所以需要指定业务的主键列名

func NewMultiTableDoc

func NewMultiTableDoc(spaceId, datasheetId string) *MultiTableDoc

func (*MultiTableDoc) AddCol

func (doc *MultiTableDoc) AddCol(fields []*AddField) (ret []*Field, err error)

-------------------------------------------------- 添加指定类型的字段

func (*MultiTableDoc) AddRow

func (doc *MultiTableDoc) AddRow(rows []*AddRecord) (records []*CommonRecord, err error)

-------------------------------------------------- 增加记录

func (*MultiTableDoc) DelAllRows

func (doc *MultiTableDoc) DelAllRows() error

-------------------------------------------------- 清空记录

func (*MultiTableDoc) DelCol

func (doc *MultiTableDoc) DelCol(fieldIds []string) error

删除字段

func (*MultiTableDoc) DelRow

func (doc *MultiTableDoc) DelRow(recordIds []string) error

-------------------------------------------------- 删除记录

func (*MultiTableDoc) EditRow

func (doc *MultiTableDoc) EditRow(rows []*UpdateRecord) error

--------------------------------------------------

func (*MultiTableDoc) GetCols

func (doc *MultiTableDoc) GetCols() ([]*Field, error)

-------------------------------------------------- 内部方法:查询字段

func (*MultiTableDoc) GetRow

func (doc *MultiTableDoc) GetRow(req *GetRecordRequest) (*getRecordResponse, error)

-------------------------------------------------- 创建记录

func (*MultiTableDoc) SetColList

func (doc *MultiTableDoc) SetColList(myColList []*AddField, deleteExcept bool) (isEdited bool, err error)

设置多维表格文档的列列表: 如果该列已存在,则不修改。如需修改列,为了确保程序不会误删数据,应该手动删除列,再通过该方法重建。 如果该列不存在,则添加列。 如果deleteExcept为true,则删除除myColList之外的所有列。

type SelectFieldOption

type SelectFieldOption struct {
	Id string `json:"id,omitempty"`
	// Name  string                  `json:"name"`
	Text string `json:"name"`
	// Color *SelectFieldOptionColor `json:"color,omitempty"` // 文档有问题,这里只需要string
	Style SelectFieldOptionColor `json:"color,omitempty"`
}

--------------------------------------------------

type SelectFieldOptionColor

type SelectFieldOptionColor string
var (
	ColorRed    SelectFieldOptionColor = "red_4"
	ColorOrange SelectFieldOptionColor = "tangerine_4"
	ColorYellow SelectFieldOptionColor = "yellow_4"
	ColorBlue   SelectFieldOptionColor = "blue_4"
	ColorGreen  SelectFieldOptionColor = "green_4"
	ColorPurple SelectFieldOptionColor = "deepPurple_4"
	ColorGray   SelectFieldOptionColor = "blue_0"
	ColorPink   SelectFieldOptionColor = "pink_4"
)

预定义的颜色选项

type SortRule

type SortRule struct {
	Field string `json:"field"`
	Order string `json:"order"` // "asc" 或 "desc"
}

-------------------------------------------------- 排序规则

func NewSortRule

func NewSortRule(fieldName string, desc bool) SortRule

type Team

type Team struct {
	UnitId       string `json:"unitId"`
	Name         string `json:"name"`
	Sequence     int    `json:"sequence"`
	ParentUnitId string `json:"parentUnitId"`
	Roles        []struct {
		UnitId   string `json:"unitId"`
		Name     string `json:"name"`
		Sequence int    `json:"sequence"`
	} `json:"roles"`
}

Team 表示小组信息

type UpdateRecord

type UpdateRecord struct {
	RecordId string         `json:"recordId"`
	Fields   map[string]any `json:"fields"`
}

-------------------------------------------------- api req/resp结构 --------------------------------------------------

type UpdateRecordRequest

type UpdateRecordRequest struct {
	Records  []*UpdateRecord `json:"records"`
	FieldKey string          `json:"fieldKey,omitempty"` // "name" or "id", default "name"
}

type UpdateRecordResponse

type UpdateRecordResponse struct {
	Success bool   `json:"success"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    struct {
		Records []CommonRecord `json:"records"`
	} `json:"data"`
}

type User

type User struct {
	UnitId string `json:"unitId"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Mobile struct {
		Number   string `json:"number"`
		AreaCode string `json:"areaCode"`
	} `json:"mobile"`
	Avatar string `json:"avatar"`
	Status int    `json:"status"` // 0:未加入空间站, 1:已加入空间站
	Type   string `json:"type"`   // PrimaryAdmin, SubAdmin, Member
	Teams  []struct {
		UnitId       string `json:"unitId"`
		Name         string `json:"name"`
		Sequence     int    `json:"sequence"`
		ParentUnitId string `json:"parentUnitId"`
	} `json:"teams"`
	Roles []struct {
		UnitId   string `json:"unitId"`
		Name     string `json:"name"`
		Sequence int    `json:"sequence"`
	} `json:"roles"`
}

User 表示成员信息

func GetUser

func GetUser(spaceId, unitId string) (*User, error)

GetUser 根据unitId获取单个用户信息

func GetUserList

func GetUserList(spaceId string) ([]*User, error)

GetUserList 递归获取所有成员

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL