Commit 5a77febf authored by chunsen's avatar chunsen

feat: 在表单组件中添加英美音标、英文定义和例句翻译字段,并优化课程ID获取逻辑

parent d5e53c2b
...@@ -70,6 +70,23 @@ ...@@ -70,6 +70,23 @@
<input type="text" nz-input [(ngModel)]="word.wordTranslation" (blur)="save()" style="width: 250px;"> <input type="text" nz-input [(ngModel)]="word.wordTranslation" (blur)="save()" style="width: 250px;">
</div> </div>
<!-- 英式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英式音标:</span>
<input type="text" nz-input [(ngModel)]="word.britishPhonetic" (blur)="save()" style="width: 250px;">
</div>
<!-- 美式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">美式音标:</span>
<input type="text" nz-input [(ngModel)]="word.americanPhonetic" (blur)="save()" style="width: 250px;">
</div>
<!-- 英文定义 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英文定义:</span>
<input type="text" nz-input [(ngModel)]="word.englishDefinition" (blur)="save()" style="width: 250px;">
</div>
<div style="margin-top: 20px; border-top: 1px dashed #eee; padding-top: 15px;"> <div style="margin-top: 20px; border-top: 1px dashed #eee; padding-top: 15px;">
<div style="margin-bottom: 10px; display: flex; align-items: center;"> <div style="margin-bottom: 10px; display: flex; align-items: center;">
...@@ -96,6 +113,12 @@ ...@@ -96,6 +113,12 @@
<input type="text" nz-input [(ngModel)]="word.exampleSentence" (blur)="save()" style="width: 250px;"> <input type="text" nz-input [(ngModel)]="word.exampleSentence" (blur)="save()" style="width: 250px;">
</div> </div>
<!-- 例句翻译 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">例句翻译:</span>
<input type="text" nz-input [(ngModel)]="word.exampleSentenceTranslation" (blur)="save()" style="width: 250px;">
</div>
<!-- 例句音频 --> <!-- 例句音频 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;"> <div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">例句音频:</span> <span style="width: 120px; text-align: right;">例句音频:</span>
...@@ -119,33 +142,6 @@ ...@@ -119,33 +142,6 @@
x x
</button> </button>
</div> </div>
<!-- 其他可选字段 -->
<div style="margin-top: 20px; border-top: 1px dashed #eee; padding-top: 15px;">
<!-- 英式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英式音标:</span>
<input type="text" nz-input [(ngModel)]="word.britishPhonetic" (blur)="save()" style="width: 250px;">
</div>
<!-- 美式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">美式音标:</span>
<input type="text" nz-input [(ngModel)]="word.americanPhonetic" (blur)="save()" style="width: 250px;">
</div>
<!-- 英文定义 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英文定义:</span>
<input type="text" nz-input [(ngModel)]="word.englishDefinition" (blur)="save()" style="width: 250px;">
</div>
<!-- 例句翻译 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">例句翻译:</span>
<input type="text" nz-input [(ngModel)]="word.exampleSentenceTranslation" (blur)="save()" style="width: 250px;">
</div>
</div>
</div> </div>
</div> </div>
......
...@@ -37,7 +37,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -37,7 +37,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
'ordinal number', 'ordinal number',
]; ];
// 存储courseId
courseId: string = '';
constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef, constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef,
private message: NzMessageService) { private message: NzMessageService) {
...@@ -62,17 +63,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -62,17 +63,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() { ngOnInit() {
this.item = {}; this.item = {};
// 获取父窗口URL中的courseId参数作为pictureBookId // 获取课程ID
const courseIdStr = this.getParentUrlParam('courseId'); this.getCourseIdFromParent();
let courseId = 0;
if (courseIdStr) {
courseId = parseInt(courseIdStr, 10);
if (isNaN(courseId)) {
courseId = 0;
}
console.log('从父窗口URL获取到courseId:', courseId);
}
// 获取存储的数据 // 获取存储的数据
(<any>window).courseware.getData((data) => { (<any>window).courseware.getData((data) => {
...@@ -87,15 +79,12 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -87,15 +79,12 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.initItem(); this.initItem();
// 确保pictureBookId存在并且是整数 // 如果有courseId,设置为pictureBookId
if (courseId > 0) { if (this.courseId) {
this.item.pictureBookId = courseId; const courseIdNum = parseInt(this.courseId, 10);
} else if (this.item.pictureBookId) { if (!isNaN(courseIdNum)) {
// 确保现有的pictureBookId是整数 this.item.pictureBookId = courseIdNum;
const pictureBookId = parseInt(this.item.pictureBookId, 10); }
this.item.pictureBookId = isNaN(pictureBookId) ? 0 : pictureBookId;
} else {
this.item.pictureBookId = 0;
} }
// 确保每个单词都有正确的ID(pictureBookId + 索引) // 确保每个单词都有正确的ID(pictureBookId + 索引)
...@@ -201,7 +190,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -201,7 +190,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
id: 0, // 临时ID,将在ensureWordIds中设置正确的值 id: 0, // 临时ID,将在ensureWordIds中设置正确的值
pictureBookId: pictureBookId, pictureBookId: pictureBookId,
word: '', word: '',
displayType: '3', // 默认为"核心单词" displayType: 1, // 默认为"词卡单词"
partOfSpeech: '', partOfSpeech: '',
exampleSentence: '', exampleSentence: '',
wordAudioUrl: '', wordAudioUrl: '',
...@@ -318,7 +307,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -318,7 +307,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
id: 0, // 临时ID,将在ensureWordIds中设置正确的值 id: 0, // 临时ID,将在ensureWordIds中设置正确的值
pictureBookId: pictureBookId, pictureBookId: pictureBookId,
word: '', word: '',
displayType: '3', // 默认为"核心单词" displayType: 1, // 默认为"词卡单词"
partOfSpeech: '', partOfSpeech: '',
exampleSentence: '', exampleSentence: '',
wordAudioUrl: '', wordAudioUrl: '',
...@@ -566,6 +555,27 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -566,6 +555,27 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.message.info(`准备为题目生成音频`); this.message.info(`准备为题目生成音频`);
} }
// 获取课程ID
getCourseIdFromParent() {
const call_back = (res) => {
console.log("courseId res: ", res);
this.courseId = res;
}
const checkAndCall = () => {
if (typeof commonPostMessageWithCallback === "function") {
commonPostMessageWithCallback(
{
action: "getCourseId",
},
call_back
);
} else {
this.message.create("error", "通信方法不可用");
}
};
checkAndCall();
}
// 生成选项音频 // 生成选项音频
generateOptionAudio(option, word) { generateOptionAudio(option, word) {
if (!option.answer || option.answer.trim() === '') { if (!option.answer || option.answer.trim() === '') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment