118 lines
3.0 KiB
TypeScript
118 lines
3.0 KiB
TypeScript
import { String, Text, Boolean } from 'oak-domain/lib/types/DataType';
|
|
import { ActionDef, EntityDesc, EntityShape } from 'oak-domain/lib/types';
|
|
import { Schema as User } from 'oak-general-business/lib/entities/User';
|
|
import { Schema as ExtraFile } from 'oak-general-business/lib/entities/ExtraFile';
|
|
import { Schema as Log } from 'oak-domain/lib/entities/Log';
|
|
import { Schema as Category } from './Category';
|
|
|
|
export type MetaData = Record<string, any>;
|
|
|
|
// Essay.ts
|
|
export interface Schema extends EntityShape {
|
|
title: String<32>;
|
|
summary: String<128>;
|
|
content: Text;
|
|
creator: User;
|
|
meta: MetaData;
|
|
images: ExtraFile[];
|
|
logs: Log[];
|
|
category?: Category;
|
|
isTop: Boolean;
|
|
}
|
|
|
|
export type IState = 'unpublished' | 'published' | 'withdrawn';
|
|
|
|
export type IAction = 'publish' | 'withdraw';
|
|
|
|
export const IActionDef: ActionDef<IAction, IState> = {
|
|
stm: {
|
|
publish: [['unpublished', 'withdrawn'], 'published'],
|
|
withdraw: ['published', 'withdrawn'],
|
|
},
|
|
is: 'unpublished',
|
|
};
|
|
|
|
// 用户行为操作
|
|
export type CommonAction = 'setTop' | 'cancelTop';
|
|
|
|
type Action = IAction | CommonAction;
|
|
|
|
export const entityDesc: EntityDesc<
|
|
Schema,
|
|
Action,
|
|
'',
|
|
{
|
|
iState: IState;
|
|
}
|
|
> = {
|
|
locales: {
|
|
zh_CN: {
|
|
name: '文章',
|
|
attr: {
|
|
title: '标题',
|
|
summary: '摘要',
|
|
content: '内容(Markdown 格式)',
|
|
creator: '创建者',
|
|
meta: '元数据',
|
|
images: '图片',
|
|
logs: '修改记录',
|
|
category: '分类',
|
|
iState: '状态',
|
|
isTop: '是否置顶',
|
|
},
|
|
action: {
|
|
publish: '发布',
|
|
withdraw: '撤回',
|
|
setTop: '置顶',
|
|
cancelTop: '取消置顶',
|
|
},
|
|
v: {
|
|
iState: {
|
|
unpublished: '未发布',
|
|
published: '已发布',
|
|
withdrawn: '已撤回',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
style: {
|
|
icon: {},
|
|
color: {
|
|
iState: {
|
|
unpublished: '#f50',
|
|
published: '#87d068',
|
|
withdrawn: '#2db7f5',
|
|
},
|
|
},
|
|
},
|
|
indexes: [
|
|
{
|
|
name: 'title_unique',
|
|
attributes: [
|
|
{
|
|
name: 'title',
|
|
size: 32,
|
|
},
|
|
],
|
|
config: {
|
|
unique: true,
|
|
// 标题使用btree索引进行前缀搜索
|
|
type: 'btree',
|
|
},
|
|
},
|
|
// 根据文章内容搜索的全文检索索引
|
|
{
|
|
name: 'content_fulltext',
|
|
attributes: [
|
|
{
|
|
name: 'content',
|
|
},
|
|
],
|
|
config: {
|
|
type: 'fulltext',
|
|
parser: 'ngram',
|
|
},
|
|
}
|
|
],
|
|
};
|