内容库操作

获取内容库列表

ContentGroup.find(options)

参数说明

options:

参数 类型 必填 默认 说明
withCount bool false 是否返回 total_count
offset int 0 偏移量
limit int 20 最大返回条数

请求示例

  1. try {
  2. ContentList data = await ContentGroup.find(withCount: true, offset: 0, limit: 20);
  3. } catch (e) {
  4. // 操作失败
  5. }

返回示例

返回 ContentList 类型。详见数据类型章节。

获取内容库详情

ContentGroup.get(contentGroupID)

参数说明

参数 类型 必填 说明
contentGroupID int 内容库 ID

请求示例

  1. try {
  2. int contentGroupID = 1513076211190694;
  3. ContentGroup data = await ContentGroup.get(contentGroupID);
  4. print(data.id);
  5. } catch (e) {
  6. // 操作失败
  7. }

返回示例

返回 ContentGroup 类型。详见数据类型章节。

内容操作

以下操作都需指明操作的内容库,方法如下:

ContentGroup myContentGroup = new ContentGroup(contentGroupID)

参数说明

参数 类型 必填 说明
contentGroupID int 内容库 ID

获取内容详情

myContentGroup.getContent(richTextID, select: select, expand: expand)

参数说明

参数名 类型 必填 说明
richTextID int 内容 ID
select String or List 指定返回字段
expand String or List 展开字段

info 如果有自定义字段,则一并返回。

visit_count 字段,只有在已经开通了“文章统计”(“阅读数支持”)功能,且该文章的阅读数大于 0 时,才会返回。

“文章阅读数统计”是一个异步的操作,统计结果略有延迟。

请求示例

  1. try {
  2. int contentGroupID = 1513076211190694;
  3. int richTextID = 1514529306082815;
  4. ContentGroup contentGroup = new ContentGroup(contentGroupID);
  5. Content data = await contentGroup.getContent(richTextID);
  6. } catch (e) {
  7. // 操作失败
  8. }

返回示例

返回 Content 类型。详见数据类型章节。

获取符合筛选条件的内容总数

myContentGroup.count()

  1. try {
  2. int contentGroupID = 1513076211190694;
  3. ContentGroup contentGroup = new ContentGroup(contentGroupID);
  4. Query query = new Query();
  5. query.where(Where.arrayContains('categories', [1513076252710475]));
  6. int data = await contentGroup.count(query: query);
  7. } catch (e) {
  8. // 操作失败
  9. }

查询,获取内容列表

myContentGroup.query(options)

参数说明

options:

参数 类型 必填 默认 说明
query Query null 查询条件
withCount bool false 是否返回 total_count

内容查询与数据表查询方法一致。

info > myContentGroup.query() 接口返回的内容中,不包含 content 字段。

请求示例

  1. // 查找该内容库下的所有内容
  2. contentGroup.query();
  3. // 查找该内容库下在指定分类下的内容
  4. try {
  5. int contentGroupID = 1513076211190694;
  6. ContentGroup contentGroup = new ContentGroup(contentGroupID);
  7. Query query = new Query();
  8. query.where(Where.arrayContains('categories', [1513076252710475]));
  9. ContentList data = await contentGroup.query(query: query);
  10. print(data.contents);
  11. } catch (e) {
  12. // 操作失败
  13. }

筛选字段

select 使用方法可以参考数据表 - 字段过滤小节

扩展字段

expand 使用方法可以参考数据表 - 字段扩展小节

假设 _richtextcontent 表中有一个类型为 pointer 的字段,名称为 pointer_test_oder, 指向了 test_order 表

请求示例 1

  1. try {
  2. ContentGroup contentGroup = new ContentGroup(contentGroupID);
  3. Content data = await contentGroup.getContent(1513076305938456, expand: 'pointer_test_oder');
  4. print(data.content);
  5. } catch (e) {
  6. // 操作失败
  7. }

请求示例 2

  1. try {
  2. int contentGroupID = 1513076211190694;
  3. ContentGroup contentGroup = new ContentGroup(contentGroupID);
  4. Content data = await contentGroup.getContent(1513076305938456, expand: 'pointer_test_oder', select: ['title', 'pointer_test_oder']);
  5. print(data.content);
  6. } catch (e) {
  7. // 操作失败
  8. }

获取分类详情

myContentGroup.getCategory(categoryID)

OBJECT 参数说明

参数 类型 必填 说明
categoryID int 分类 ID

返回参数

参数 类型 说明
children List 子分类列表
have_children bool 是否含有子分类
id int 分类 ID
name String 分类名称

请求示例

  1. try {
  2. int contentGroupID = 1513076211190694;
  3. ContentGroup contentGroup = new ContentGroup(contentGroupID);
  4. ContentCategory data = await contentGroup.getCategory(1513076252710475);
  5. } catch (e) {
  6. // 操作失败
  7. }

返回示例

返回 ContentCategory 类型。详见数据类型章节。

获取内容库分类列表

myContentGroup.getCategoryList()

请求示例

  1. try {
  2. int contentGroupID = 1513076211190694;
  3. ContentGroup contentGroup = new ContentGroup(contentGroupID);
  4. ContentCategoryList data = await contentGroup.getCategoryList();
  5. print(data);
  6. } catch (e) {
  7. // 操作失败
  8. }

分页与排序

内容查询的分页与排序操作和数据表分页与排序方法一致。

数据类型

Content

属性 类型 说明
id int 内容 Id
title String 名称
description String 描述
cover String 封面 路径
content String 实际内容
group_id int 分组 Id
categories List 子类
visit_count int 阅读数
updated_at int 更新日期,unix 时间戳格式
created_at int 创建日期,unix 时间戳格式
created_by int 创建者 Id
name String 列表名称,仅在 find 时有值

ContentCategory

ContentCategory 表示内容所属的分类。

属性 类型 说明
id int 分类 Id
name String 分类名
haveChildren bool 是否有子类
children List 子类列表,元素类型为 ContentCategory

ContentList

ContentList 表示一次查询数据库所返回的内容列表以及元数据。

属性 类型 说明
limit int 返回内容的最大个数
offset int 返回内容的起始偏移值
total_count int 内容总数,默认为 -1,表示该字段无效
next String 下一页地址,若值为 null,表示当前为最后一页
previous String 上一页地址,若值为 null,表示当前为第一页
contents List 内容列表,每个元素为 Content 类型

info 返回结果默认不包含 total_count,如需获取该值可以在设置查询条件 Query 时,通过设置 query.withTotalCount(true) 来获取 total_count。详见获取记录总数

ContentCategoryList

ContentCategoryList 表示一次查询数据库所返回的内容分类列表以及元数据。

属性 类型 说明
limit int 返回内容分类的最大个数
offset int 返回内容分类的起始偏移值
total_count int 内容分类总数,默认为 -1,表示该字段无效
next String 下一页地址,若值为 null,表示当前为最后一页
previous String 上一页地址,若值为 null,表示当前为第一页
contents List 内容分类列表,每个元素为 ContentCategory 类型

info 返回结果默认不包含 total_count,如需获取该值可以在设置查询条件 Query 时,通过设置 query.withTotalCount(true) 来获取 total_count。详见获取记录总数