Model Fields
This document introduces the related concepts and usage instructions of the content model.
Common Field Properties
Display Name
The display name is the text shown for database fields during table editing, such as "Product Name".
Database Field Name
Description
The description of the field is typically used for explanation and prompting purposes, and is displayed during content editing.
i.e., the actual storage name of the field in the database, such as name.
Default Value
Provides a default value for content fields. During editing, users can leave the field blank and the default value will be used.
Required
By default, when creating content, all field values are optional. Enabling this option makes the field mandatory during content creation; content cannot be created without filling this field.
Hidden
Hides this field in the content collection table view, but keeps it visible during content editing.
Set as Sort Field
By default, the CMS system sorts content in chronological order of creation, with earlier entries appearing first. You can specify other sorting criteria by setting sort fields.
String
CloudBase CMS provides two string types: single-line strings and multi-line strings. Single-line strings are suitable for shorter content, such as product names and article titles, using a single-line input box during editing. Multi-line strings are suitable for longer content, such as article introductions.
When using a string, you can specify the maximum and minimum length to constrain the input string length.
Numeric
CloudBase CMS does not distinguish between numeric types or precision, and by default supports both integers and floating-point numbers.
When using a number, you can specify the maximum and minimum values to constrain the input.
Boolean
Boolean only allows input of false
and true
. During content editing, it appears as a Switch control, defaulting to false
.
Enum
An enum field represents selecting a value from a finite set for the current field. For example, a product's status might be 'listed' or 'unlisted', which can be represented as an enum. During content editing, only values from the predefined enum set can be chosen.
When setting an enum field, you need to add optional enum elements. Each enum element has two required attributes:
Display alias for enum elements: Used solely for display purposes to distinguish between enum values
Enum element value: The actual value stored in the database
Date and Time
CloudBase CMS provides two time types: Date and Date and Time. Date includes only year, month, and day, e.g., 2021-01-01. Date and Time includes year, month, day, hour, minute, and second, e.g., 2021-01-01 12:01:01.
Date and Time support multiple customizable storage formats, allowing you to define the storage format for time fields in the database:
Unix Timestamp ms: The number of milliseconds elapsed since January 1, 1970, midnight (UTC/GMT), in integer format
Unix Timestamp s: The number of seconds elapsed since January 1, 1970, midnight (UTC/GMT), in integer format
Date object: the Date object in JavaScript
Time string: Stores time directly as a string, e.g., 2021-01-01
By default, the storage format for Date and Time is Unix Timestamp in milliseconds.
File
The file field supports uploading files directly to cloud storage during content editing, along with operations such as downloading files and copying access links. It also allows customization of the resource link format, i.e., the field format stored in the database:
- FileId: CloudBase private protocol, such as
cloud://envId.random-1002/file.psd
, can be displayed directly in mini-programs and supports read-write permission settings.
- HTTPS: Fixed HTTPS access link, such as
https://asdf47.tcb.qcloud.la/asdf.png
, which does not support access permission settings. Cloud storage must be configured for public access.
Additionally, the file field can enable multiple content support, storing file access links as an array.
{
// Single file
file: 'https://tcb.cloud.tencent.com/',
// Multiple files
files: [
'https://tcb.cloud.tencent.com/'
]
}
Image
Similar to the file field, the image field supports uploading images directly to cloud storage during content editing, along with operations such as previewing, downloading, and copying access links. It also allows customization of the resource link format and storing multiple contents.
Multimedia
Multimedia can be used to display music and videos, allowing direct playback of audio or video content during presentation.
Email Address
Used to display and edit email addresses. During editing, the CMS system automatically validates the input values.
Phone Number
Used to display and edit phone numbers. During editing, the CMS system automatically validates the input values and stores them in integer format.
URL
Used to display and edit URLs. During editing, the CMS system automatically validates the input values.
Rich Text
CMS supports basic rich text editing, allowing the use of a built-in rich text editor to edit and display rich text content, as well as upload and insert images. The CMS system utilizes the open-source braft-editor rich text editor.
Markdown
CMS supports Markdown editors, allowing you to edit text content with real-time preview and image upload/insertion capabilities.
Association
In some cases, a field in one content item may reference the field value of another content item. For example, consider a blog post content model containing an author field that stores an author's name, while an author content collection exists to manage all authors.
In this case, we can add an author field to the blog content model, set it as an association type, select author content as the associated content, and configure the display field to show the author's name.
When creating a new article, you can directly select from all available author content, which is very convenient.
When storing associated fields, to ensure associated values update in real time as the linked content changes, CloudBase CMS stores the _id
of the associated object content in the database.
Additionally, the association supports setting multiple associations, meaning it can link to multiple content items simultaneously, and the database stores an array of _id
.
The association field actually links to the _id of the associated table, while the display field primarily enhances readability.
Array
It is used to display and edit string array content.
JSON Object
In some cases, when you need to display or edit complex data structures that cannot be represented by the above types, you may use the JSON object type. The JSON object type can display valid JSON objects and allow editing.
Edit
JSON object supports two editing modes: JSON string input and manual editing
JSON String Input
Click the JSON string button to directly enter a valid JSON string, which will be formatted and stored as an object.
Manual Editing
Click the JSON object to edit it directly.
View
In the content table, you can click the view button to view the content of the JSON object.