0225304 2 days ago
parent
commit
3f11f39388

+ 1 - 0
myapp/src/app/app.component.ts

@@ -8,5 +8,6 @@ import { Component } from '@angular/core';
 })
 export class AppComponent {
   constructor() {}
+  
 
 }

+ 1 - 1
myapp/src/app/tab1/edit/edit.page.html

@@ -1,4 +1,4 @@
-<ion-header>
+<ion-header> 
   <ion-toolbar>
     <ion-buttons slot="start">
       <ion-button (click)="dismiss()">取消</ion-button>

+ 1 - 3
myapp/src/app/tab1/test-message/test-message.page.ts

@@ -88,9 +88,7 @@ export class TestMessagePage implements OnInit {
       if (objectToDelete) {
         // 假设 CloudObject 有 destroy 方法而不是 delete
         await objectToDelete.destroy(); // 或者使用其他删除方法如 remove()
-        this.navCtrl.navigateBack('/tabs/tab1', {
-          //state: { refreshDiaries: true }
-      });
+        this.navCtrl.navigateBack('/tabs/tab1');
       }
     } catch (error) {
       console.error('删除日记失败:', error);

+ 127 - 0
myapp/src/lib/import-data.ts

@@ -0,0 +1,127 @@
+import { CloudUser, CloudObject } from './ncloud';
+
+// 测试数据导入函数
+export async function importTestDiaries() {
+    try {
+        // 1. 首先登录一个测试用户(或创建)
+        const user = new CloudUser();
+        let currentUser = await user.login('testuser', 'test123');
+        
+        if (!currentUser) {
+            // 如果用户不存在,先注册
+            console.log('测试用户不存在,正在创建...');
+            currentUser = await user.signUp('testuser', 'test123', {
+                nickname: '测试用户',
+                email: 'test@example.com',
+                bio: '这是一个用于测试的AI日记系统用户'
+            });
+        }
+
+        if (!currentUser) {
+            console.error('无法登录或创建测试用户');
+            return;
+        }
+
+        console.log('已登录用户:', currentUser.data['username']);
+
+        // 2. 创建测试日记数据
+        const testDiaries = [
+            {
+                title: '美好的一天',
+                content: '今天天气晴朗,我去了公园散步,看到了许多美丽的花朵。心情非常愉快!',
+                mood: 'happy',
+                tags: ['公园', '散步', '花朵'],
+                isPublic: true,
+                location: {
+                    latitude: 39.9042,
+                    longitude: 116.4074
+                },
+                weather: {
+                    condition: '晴朗',
+                    temperature: 22
+                },
+                aiAnalysis: {
+                    sentiment: 'positive',
+                    keywords: ['公园', '散步', '花朵', '愉快']
+                }
+            },
+            {
+                title: '工作压力',
+                content: '今天项目截止日期临近,感觉压力很大。需要更好的时间管理方法。',
+                mood: 'stressed',
+                tags: ['工作', '压力', '时间管理'],
+                isPublic: false,
+                aiAnalysis: {
+                    sentiment: 'negative',
+                    keywords: ['项目', '截止日期', '压力', '时间管理']
+                }
+            },
+            {
+                title: '读书笔记',
+                content: '今天读了《人类简史》,对人类文明的发展有了新的认识。特别有趣的是认知革命的部分。',
+                mood: 'thoughtful',
+                tags: ['读书', '人类简史', '学习'],
+                isPublic: true,
+                aiAnalysis: {
+                    sentiment: 'neutral',
+                    keywords: ['读书', '人类简史', '认知革命', '学习']
+                }
+            },
+            {
+                title: '家庭聚餐',
+                content: '周末和家人一起聚餐,妈妈做了我最爱吃的红烧肉。大家聊得很开心,感受到了家庭的温暖。',
+                mood: 'joyful',
+                tags: ['家庭', '聚餐', '美食'],
+                isPublic: true,
+                location: {
+                    latitude: 39.9138,
+                    longitude: 116.3637
+                },
+                weather: {
+                    condition: '多云',
+                    temperature: 18
+                },
+                aiAnalysis: {
+                    sentiment: 'positive',
+                    keywords: ['家庭', '聚餐', '红烧肉', '温暖']
+                }
+            },
+            {
+                title: '健身计划',
+                content: '开始了新的健身计划,今天完成了30分钟的有氧运动。虽然很累,但感觉很充实。',
+                mood: 'energetic',
+                tags: ['健身', '运动', '健康'],
+                isPublic: false,
+                aiAnalysis: {
+                    sentiment: 'positive',
+                    keywords: ['健身计划', '有氧运动', '充实']
+                }
+            }
+        ];
+
+        // 3. 批量创建日记
+        console.log('开始导入测试日记...');
+        for (const diaryData of testDiaries) {
+            const diary = new CloudObject('Diary');
+            
+            // 设置日记数据
+            diary.set({
+                ...diaryData,
+                author: currentUser.toPointer(),
+                createdAt: new Date(),
+                updatedAt: new Date()
+            });
+
+            // 保存日记
+            await diary.save();
+            console.log(`已创建日记: ${diaryData.title} (ID: ${diary.id})`);
+        }
+
+        console.log('测试数据导入完成!');
+    } catch (error) {
+        console.error('导入测试数据时出错:', error);
+    }
+}
+
+// 执行导入
+//importTestDiaries();