diff --git a/agents/noco/common/base-table.ts b/agents/noco/common/base-table.ts index c0b94ea..7006721 100644 --- a/agents/noco/common/base-table.ts +++ b/agents/noco/common/base-table.ts @@ -1,13 +1,11 @@ import { CreateColumnData } from "@kevisual/noco" export const columns: CreateColumnData[] = [ - { - title: 'Id', - // @ts-ignore + title: 'Id2', + // uidt: "ID", uidt: "ID", pk: true, - dt: "int4", - dtx: "integer" + pv: true, }, { diff --git a/scripts/create.ts b/scripts/create.ts new file mode 100644 index 0000000..0c329c6 --- /dev/null +++ b/scripts/create.ts @@ -0,0 +1,31 @@ +import { Life, NocoApi } from '../mod.ts'; +import { generateMultipleRandomItems } from './random-data'; + +// const token = 'your' +// const baseId = 'your_base_id'; + +const token = 'CPrDfoajtCjayEYK17wOljE7R2E7DoTIw_7oUnjb' +const baseId = 'p1pderowf0zhugt' +let tableId = 'mierezd5z73kj26' +const nocoApi = new NocoApi({ + baseURL: 'http://localhost:8080', + token +}); + +const life = new Life({ nocoApi, baseId }); + +// const tableRes = await life.createTable({ +// title: '测试表格2', +// }); +// tableId = tableRes.data?.id || ''; +// console.log('tableId', tableId); + +life.nocoApi.record.table = tableId; +const datas = generateMultipleRandomItems(1); + +for (const data of datas) { + console.log('data', data); + const createRes = await life.nocoApi.record.create(data); + console.log('createRes', createRes); +} + diff --git a/scripts/random-data.ts b/scripts/random-data.ts new file mode 100644 index 0000000..7485619 --- /dev/null +++ b/scripts/random-data.ts @@ -0,0 +1,60 @@ +type Item = { + Id?: number; + '标题': string; + '描述': string; + '总结': string; + '标签': string[]; +} +export function generateRandomItem(): Item { + const titles = [ + '探索未知的宇宙', + '人工智能的未来', + '可持续发展的重要性', + '历史上的伟大人物', + '科技改变生活' + ]; + + const descriptions = [ + '这是一段关于宇宙探索的描述,涵盖了最新的发现和理论。', + '本文探讨了人工智能的发展趋势及其对社会的影响。', + '讨论了可持续发展的概念及其在现代社会中的应用。', + '介绍了历史上几位对世界产生重大影响的人物。', + '分析了科技进步如何改变了我们的日常生活。' + ]; + + const summaries = [ + '本文总结了宇宙探索的现状和未来方向。', + '总结了人工智能技术的发展及其潜在挑战。', + '概述了可持续发展的关键要素和实践方法。', + '回顾了历史伟人对社会的贡献和影响。', + '总结了科技进步对生活方式的改变。' + ]; + + const tagsList = [ + ['宇宙', '探索', '科学'], + ['人工智能', '技术', '未来'], + ['可持续发展', '环境', '社会'], + ['历史', '人物', '影响'], + ['科技', '生活', '进步'] + ]; + + const randomIndex = Math.floor(Math.random() * titles.length); + + return { + '标题': titles[randomIndex], + '描述': descriptions[randomIndex], + '总结': summaries[randomIndex], + // '标签': tagsList[randomIndex], + '标签': ['b'], + }; +} + +export function generateMultipleRandomItems(count: number): Item[] { + const items: Item[] = []; + for (let i = 0; i < count; i++) { + const item = generateRandomItem(); + item.Id = i + 1; + items.push(item); + } + return items; +} \ No newline at end of file