2024-10-07 22:28:21 +08:00

89 lines
1.7 KiB
TypeScript

import { sequelize } from '../../../modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
type PageNodeData = {
id: string;
type: string;
data: {
label?: string; // 容器 开始 结束
root?: boolean; // 是否是根节点
// 容器上的属性
cid?: string; // 容器id
style?: { [key: string]: string };
className?: string;
showChild?: boolean;
shadowRoot?: boolean;
};
[key: string]: any;
};
export interface PageData {
edges: any[];
nodes: PageNodeData[];
viewport: any;
[key: string]: any;
}
export type Publish = {
id?: string; // resource id
description?: string;
key?: string;
version?: string;
};
/**
* 页面数据
*/
export class PageModel extends Model {
declare id: string;
declare title: string;
declare description: string;
declare type: string;
declare data: PageData;
declare publish: Publish;
declare uid: string;
}
PageModel.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
comment: 'id',
},
title: {
type: DataTypes.STRING,
defaultValue: '',
},
description: {
type: DataTypes.TEXT,
defaultValue: '',
},
type: {
type: DataTypes.STRING,
defaultValue: '',
},
data: {
type: DataTypes.JSON,
defaultValue: {},
},
publish: {
type: DataTypes.JSON,
defaultValue: {},
},
uid: {
type: DataTypes.UUID,
allowNull: true,
},
},
{
sequelize,
tableName: 'kv_page',
paranoid: true,
},
);
PageModel.sync({ alter: true, logging: false }).catch((e) => {
console.error('PageModel sync', e);
});