2024-10-01 00:47:14 +08:00

78 lines
1.4 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 class PageModel extends Model {
declare id: string;
declare title: string;
declare description: string;
declare type: string;
declare data: PageData;
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: {},
},
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);
});