|
@@ -1,10 +1,15 @@
|
|
|
// chapter-generator.page.ts
|
|
|
-import { CommonModule } from '@angular/common';
|
|
|
-import { Component } from '@angular/core';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
import { FormsModule } from '@angular/forms'; // 导入 FormsModule
|
|
|
-import { IonBackButton, IonButton, IonButtons, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonInput, IonItem, IonLabel, IonList, IonMenu, IonMenuButton, IonRouterOutlet, IonTitle, IonToolbar } from '@ionic/angular/standalone';
|
|
|
+import { IonRouterOutlet, NavController } from '@ionic/angular/standalone';
|
|
|
import { addIcons } from 'ionicons';
|
|
|
import { chevronForward } from 'ionicons/icons';
|
|
|
+import { IonicModule, ModalController } from '@ionic/angular';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { AiExpandModalComponent } from '../ai-expand-modal/ai-expand-modal.component';
|
|
|
+import { AiPolishModalComponent } from '../ai-polish-modal/ai-polish-modal.component';
|
|
|
+import { AiContinueModalComponent } from '../ai-continue-modal/ai-continue-modal.component';
|
|
|
+import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
addIcons({ chevronForward });
|
|
|
|
|
@@ -15,19 +20,62 @@ addIcons({ chevronForward });
|
|
|
standalone: true,
|
|
|
imports: [
|
|
|
FormsModule, // 添加 FormsModule
|
|
|
- IonIcon, IonRouterOutlet,
|
|
|
- IonList, IonFab, IonBackButton,
|
|
|
- IonFabButton, CommonModule,
|
|
|
- IonTitle, IonMenuButton, IonMenu,
|
|
|
- IonContent, IonItem, IonInput, IonLabel, IonButton, IonButtons, IonHeader, IonToolbar
|
|
|
+ IonRouterOutlet, CommonModule, IonicModule, AiExpandModalComponent, AiPolishModalComponent, AiContinueModalComponent
|
|
|
]
|
|
|
})
|
|
|
-export class ChapterGeneratorPage {
|
|
|
+export class ChapterGeneratorPage implements OnInit {
|
|
|
chapters = [
|
|
|
{ title: 'Chapter 1', content: '这是第一章的内容。' },
|
|
|
// 其他章节...
|
|
|
];
|
|
|
isSideShow: boolean = true;
|
|
|
+ selectedChapterIndex: number | null = null;
|
|
|
+ selectedChapterTitle: string = '';
|
|
|
+ selectedChapterContent: string = '';
|
|
|
+ novelTitle: string = ''; // 初始化作品名称
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private modalCtrl: ModalController,
|
|
|
+ private navCtrl: NavController,
|
|
|
+ private route: ActivatedRoute // 注入 ActivatedRoute 以获取查询参数
|
|
|
+ ) { }
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ // 从查询参数中获取作品名称
|
|
|
+ this.route.queryParams.subscribe(params => {
|
|
|
+ this.novelTitle = params['title'] || '';
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async openAiExpandModal() {
|
|
|
+ const modal = await this.modalCtrl.create({
|
|
|
+ component: AiExpandModalComponent,
|
|
|
+ componentProps: {
|
|
|
+ onInsertText: (text: string) => this.insertTextIntoChapterEnd(text)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return await modal.present();
|
|
|
+ }
|
|
|
+
|
|
|
+ async openAiPolishModal() {
|
|
|
+ const modal = await this.modalCtrl.create({
|
|
|
+ component: AiPolishModalComponent,
|
|
|
+ componentProps: {
|
|
|
+ onInsertText: (text: string) => this.insertTextIntoChapterEnd(text)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return await modal.present();
|
|
|
+ }
|
|
|
+
|
|
|
+ async openAiContinueModal() {
|
|
|
+ const modal = await this.modalCtrl.create({
|
|
|
+ component: AiContinueModalComponent,
|
|
|
+ componentProps: {
|
|
|
+ onInsertText: (text: string) => this.insertTextIntoChapterEnd(text)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return await modal.present();
|
|
|
+ }
|
|
|
|
|
|
toggleSide() {
|
|
|
this.isSideShow = !this.isSideShow;
|
|
@@ -48,10 +96,6 @@ export class ChapterGeneratorPage {
|
|
|
this.chapters.splice(index, 1);
|
|
|
}
|
|
|
|
|
|
- selectedChapterIndex: number | null = null;
|
|
|
- selectedChapterTitle: string = '';
|
|
|
- selectedChapterContent: string = '';
|
|
|
-
|
|
|
selectChapter(index: number) {
|
|
|
this.editChapter(index);
|
|
|
this.isSideShow = false; // 隐藏侧边栏
|
|
@@ -74,4 +118,30 @@ export class ChapterGeneratorPage {
|
|
|
this.isSideShow = true; // 显示侧边栏
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ insertTextIntoChapterEnd(text: string) {
|
|
|
+ if (this.selectedChapterIndex !== null) {
|
|
|
+ this.chapters[this.selectedChapterIndex].content += text;
|
|
|
+ this.selectedChapterContent += text; // 更新显示的内容
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ saveWork() {
|
|
|
+ const work = {
|
|
|
+ id: Date.now().toString(), // 使用当前时间戳作为唯一ID
|
|
|
+ cover: 'default-cover.jpg', // 默认封面,可以根据需要修改
|
|
|
+ title: this.novelTitle, // 使用从查询参数获取的作品名称
|
|
|
+ createTime: new Date(),
|
|
|
+ type: '长篇小说',
|
|
|
+ chapters: this.chapters,
|
|
|
+ };
|
|
|
+
|
|
|
+ // 将作品信息存储在本地存储
|
|
|
+ const existingWorks = JSON.parse(localStorage.getItem('works') || '[]');
|
|
|
+ existingWorks.push(work);
|
|
|
+ localStorage.setItem('works', JSON.stringify(existingWorks));
|
|
|
+
|
|
|
+ // 跳转到home页面
|
|
|
+ this.navCtrl.navigateRoot(['/']);
|
|
|
+ }
|
|
|
}
|